From patchwork Tue Nov 4 13:56:22 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Protsenko X-Patchwork-Id: 40158 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f70.google.com (mail-la0-f70.google.com [209.85.215.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 760B121894 for ; Tue, 4 Nov 2014 13:56:39 +0000 (UTC) Received: by mail-la0-f70.google.com with SMTP id ge10sf670159lab.5 for ; Tue, 04 Nov 2014 05:56:38 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:mime-version:in-reply-to:references :date:message-id:subject:from:to:cc:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe:content-type; bh=8PQj/YGvw4rawuM5iteCZ/CXpBNort2jqAAV1JRBSu4=; b=ftFX+ILzZTMFvYzBpqOsAy8obx4MmOQ2HNGtNeRANn7G4s4cCuuTQ7pNH9Kw2Ys1aN w7c06eMFKbTyvMYMyJbwsZplpN2jVXa9r0uNuflT9weOsCrRiXvGoD3Kl0RJJ/AsjUrl Sdt0o7zMjSFBY9xhEarqGYuhFqoO991+IuV16EIwGOd3b0UGnpmeSF2xDTg41+VOMcO8 3rSlLvmtFD4qB4iOfJ1JYaxW3vuIQdYPeGY1QocYDepgBTwPbV5S2BEERUyteaq8sY/z YgDPT9BAjwawf3X0Qmi6F/qlOj05WA7yT+W/5IflLLdG9w3RSATJoFQiHUBGAACDgmSJ kzIA== X-Gm-Message-State: ALoCoQnKh0gQbEFQargUfajQoSBm8V8+e5UThjjqMVCs/e65j3CXQT2NgRxu44Fw3c3XcOmLNx89 X-Received: by 10.180.218.100 with SMTP id pf4mr2395525wic.4.1415109398381; Tue, 04 Nov 2014 05:56:38 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.21.135 with SMTP id v7ls905624lae.40.gmail; Tue, 04 Nov 2014 05:56:38 -0800 (PST) X-Received: by 10.112.87.162 with SMTP id az2mr58844564lbb.15.1415109398189; Tue, 04 Nov 2014 05:56:38 -0800 (PST) Received: from mail-la0-f51.google.com (mail-la0-f51.google.com. [209.85.215.51]) by mx.google.com with ESMTPS id k1si962409lbv.25.2014.11.04.05.56.38 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 04 Nov 2014 05:56:38 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.51 as permitted sender) client-ip=209.85.215.51; Received: by mail-la0-f51.google.com with SMTP id q1so897429lam.24 for ; Tue, 04 Nov 2014 05:56:38 -0800 (PST) X-Received: by 10.152.29.8 with SMTP id f8mr59598152lah.56.1415109398055; Tue, 04 Nov 2014 05:56:38 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.184.201 with SMTP id ew9csp118094lbc; Tue, 4 Nov 2014 05:56:37 -0800 (PST) X-Received: by 10.70.19.206 with SMTP id h14mr8222016pde.49.1415109395988; Tue, 04 Nov 2014 05:56:35 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id sd1si340884pbb.115.2014.11.04.05.56.32 for ; Tue, 04 Nov 2014 05:56:35 -0800 (PST) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753586AbaKDN4b (ORCPT + 25 others); Tue, 4 Nov 2014 08:56:31 -0500 Received: from mail-lb0-f182.google.com ([209.85.217.182]:46740 "EHLO mail-lb0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753381AbaKDN4Z (ORCPT ); Tue, 4 Nov 2014 08:56:25 -0500 Received: by mail-lb0-f182.google.com with SMTP id f15so12494350lbj.13 for ; Tue, 04 Nov 2014 05:56:23 -0800 (PST) MIME-Version: 1.0 X-Received: by 10.152.7.175 with SMTP id k15mr59026668laa.58.1415109383006; Tue, 04 Nov 2014 05:56:23 -0800 (PST) Received: by 10.25.136.2 with HTTP; Tue, 4 Nov 2014 05:56:22 -0800 (PST) In-Reply-To: <20141016161507.GJ14343@console-pimps.org> References: <20141013095310.GZ14343@console-pimps.org> <20141016161507.GJ14343@console-pimps.org> Date: Tue, 4 Nov 2014 15:56:22 +0200 Message-ID: Subject: Re: [PATCH 2/2] efi: Capsule update support From: Sam Protsenko To: Matt Fleming Cc: Matt Fleming , Leif Lindholm , hock.leong.kweh@intel.com, "linux-efi@vger.kernel.org" , linux-kernel@vger.kernel.org Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: semen.protsenko@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.51 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Matt, I've tested your patch with zero image size (no image passed, only headers) and it crashes because there is no check for image size there. This case (zero image size) seems to be legit according to specification and also can be useful in real life. So I developed a little fix for your patch: <<<<<<<<<<<<<<<<<<<<<<< cut here >>>>>>>>>>>>>>>>>>>>> @@ -215,7 +219,10 @@ static int efi_update_capsule(efi_capsule_header_t *capsule, kunmap(block_pgs[i]); } - status = efi.update_capsule(&capsule, 1, page_to_phys(block_pgs[0])); + sg_list = page_to_phys(block_pgs[0]); + +update_caps: + status = efi.update_capsule(&capsule, 1, sg_list); if (status != EFI_SUCCESS) { pr_err("update_capsule fail: 0x%lx\n", status); err = efi_status_to_err(status); diff --git a/drivers/firmware/efi/capsule.c b/drivers/firmware/efi/capsule.c index ca29bad..597b363 100644 --- a/drivers/firmware/efi/capsule.c +++ b/drivers/firmware/efi/capsule.c @@ -169,13 +169,17 @@ static int efi_update_capsule(efi_capsule_header_t *capsule, struct page **pages, size_t size, int reset) { efi_capsule_block_desc_t *block = NULL; - struct page **block_pgs; + struct page **block_pgs = NULL; efi_status_t status; - unsigned int nr_data_pgs, nr_block_pgs; + unsigned int nr_data_pgs = 0, nr_block_pgs = 0; + unsigned long sg_list = 0; int i, j, err = -ENOMEM; lockdep_assert_held(&capsule_mutex); + if (size == 0) + goto update_caps; + nr_data_pgs = DIV_ROUND_UP(size, PAGE_SIZE); nr_block_pgs = num_block_pages(nr_data_pgs);