Re: [PATCH v4 2/5] block: add partition parser for U-Boot uImage.FIT

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.



[Index of Archives]     [Linux RAID]     [Linux SCSI]     [Linux ATA RAID]     [IDE]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Device Mapper]

  Powered by Linux