Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp627074rwb; Wed, 9 Nov 2022 06:56:29 -0800 (PST) X-Google-Smtp-Source: AMsMyM5SkO2XOxgCiPIVX3hox7ttQbeJ1Fi0VBp6eRtnZJvWE0zFBUOeyNbhzlvGcxlMZ8dO6QAe X-Received: by 2002:a17:906:f88:b0:7ad:9f03:fd44 with SMTP id q8-20020a1709060f8800b007ad9f03fd44mr1150047ejj.73.1668005789402; Wed, 09 Nov 2022 06:56:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668005789; cv=none; d=google.com; s=arc-20160816; b=ay10EAxXmEs/8AOLXr3L44FkXdIyk7PFCzdSf5smOIZsCxmov2UzN1KIaPWrFTPUZF P0YQ084TwCYmYMdTWTXbRkY0QF3fGHuO4DPF3M0I5ktJYeeN8aIRpGpSaO/d9Q+s95nZ MIWn+SLUxqY8qbOeOJDH0WpPthQC0JmN9Hs9d+H2AexNLrkWhaykANdvThqX9Q0lUoba bV+S7voX9oGq3N1lnOUgmnVWbR7A1sK+GoEWrKHacd3GaMEA8/EuoVHO0rDK6kaQf6K+ 9lO2C6n/q4BoTmwEJbpsn6AtVdAsPo27BvR50jVPRg0tCVHGkYjgKzzSvwfy8P5AWm1E x8SQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=3+abILhBguRFqQMHrTQ07b4hnOkJ4lTon8AP6i+bA6o=; b=gmvw69wqgQ/14X6ppuWwh6uSlbg0odNF8C+kAZ6xa1YfNu+TleoINWv8sIS+mGYDf/ qqjJeHJsu9jnbMxW4vFIiaMlSxc3V/we24HSNu57kzTgTw2lYVvrdoKGZPQjKpuhhkdT 4x19/QbqTkyu/i17F4GyVUsLBe1/p7iFSiPLPTgOqRbn3C6sBWwYp4ycheXjobmtB4ze QQ14/A2iK2Nh6rbmSy95APoL0SVyzSaS6/iyqc16sbqT6sfb75+ouCOzAgJpv5q2a2rN J2fNAk99vz3Qai/2hsh68+igo8s10YZH/4Q/gdtzt91N0FP6igvNPEJI/gSyvITPZ49s DogQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p11-20020a056402500b00b00457f9c97f13si14508862eda.581.2022.11.09.06.56.04; Wed, 09 Nov 2022 06:56:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231613AbiKIOgk (ORCPT + 92 others); Wed, 9 Nov 2022 09:36:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231213AbiKIOgi (ORCPT ); Wed, 9 Nov 2022 09:36:38 -0500 Received: from fudo.makrotopia.org (fudo.makrotopia.org [IPv6:2a07:2ec0:3002::71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC0C310A1; Wed, 9 Nov 2022 06:36:37 -0800 (PST) Received: from local by fudo.makrotopia.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.94.2) (envelope-from ) id 1osmBa-0008KM-BE; Wed, 09 Nov 2022 15:36:14 +0100 Date: Wed, 9 Nov 2022 14:36:11 +0000 From: Daniel Golle To: Matthew Wilcox Cc: Jens Axboe , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Davidlohr Bueso , "Martin K. Petersen" , Chaitanya Kulkarni , Ming Lei , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org, linux-efi@vger.kernel.org Subject: Re: [PATCH v4 2/5] block: add partition parser for U-Boot uImage.FIT Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=0.1 required=5.0 tests=BAYES_00,PDS_OTHER_BAD_TLD, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Nov 09, 2022 at 01:58:29PM +0000, Matthew Wilcox wrote: > On Tue, Nov 08, 2022 at 11:03:16PM +0000, Daniel Golle wrote: > > + /* map first page */ > > + page = read_mapping_page( > > + mapping, fit_start_sector >> (PAGE_SHIFT - SECTOR_SHIFT), NULL); > > + > > + if (IS_ERR(page)) > > + return -EFAULT; > > + > > + if (PageError(page)) > > + return -EFAULT; > > Why are you checking for PageError? You won't ever get a page with an > error back from read_mapping_page(). And you have the real error in > 'page', so why return -EFAUlT, which would indicate a problem copying > from the user. Also, this is a great place to use the new folio APIs > instead of the old page APIs. So: > > folio = read_mapping_folio(mapping, > fit_start_sector >> PAGE_SECTORS_SHIFT, NULL); > if (IS_ERR(folio)) > return PTR_ERR(folio); > > > + init_fit = page_address(page); > > init_fit = folio_address(folio) + > offset_in_folio(folio, fit_start_sector * SECTOR_SIZE); > > > + if (!init_fit) { > > + put_page(page); > > + return -EFAULT; > > + } > > page_address() or folio_address() can't ever return NULL, you should > just drop this nonsense check. Thank you for the pointers, I will implement your suggestions and post v5 after the upcoming weekend. > > ... actually, why can't you call read_part_sector() and avoid all of > this? I've tried that before and the problem is that read_part_sector() returns a pointer to one sector (typically 512 bytes) of data. And this pointer should not be accesses beyond sector boundaries, right? You'd have to call read_part_sector() again for the next sector. The FIT structure, however, usually exceeds the size of one sector, and having a continous memory area covering the structure as a whole is crucial for libfdt to do its job. I could, of course, use read_part_sector() to copy all sectors covering the FIT structure into a buffer, but that seemed strange given that read_part_sector() actually used read_mapping_page() (and now uses read_mapping_folio()) internally and then returns a pointer to the offset within the page/folio. So why not read it in one piece in first place instead of having it first split up to sectors by read_part_sector() just to then having to reassemble it into a continous buffer again.