Re: [PATCH v4] PCI: Check rom header and data structure addr before accessing

From: Andy Shevchenko

Date: Wed Nov 26 2025 - 12:42:14 EST


On Wed, Nov 26, 2025 at 07:39:18PM +0200, Andy Shevchenko wrote:
> On Wed, Nov 26, 2025 at 08:57:27PM +0800, Guixin Liu wrote:

...

> > image = rom;
> > do {
> > void __iomem *pds;
> > +
> > + if (!pci_rom_header_valid(pdev, image, rom, size, true))
> > break;
> > +
> > /* get the PCI data structure and check its "PCIR" signature */
> > pds = image + readw(image + 24);
> > + if (!pci_rom_data_struct_valid(pdev, pds, rom, size))
> > break;
> > +
> > + last_image = !!(readb(pds + 21) & 0x80);
>
> !!() is not needed.
>
> last_image = readb(pds + 21) & 0x80;

And while at it, isn't this a bit field and

last_image = readb(pds + 21) & BIT(7);

is even more descriptive? Please, check with specification and if it's
a (single) bit, also change this.

> > length = readw(pds + 16);
> > image += length * 512;
> > +
> > + if (!pci_rom_header_valid(pdev, image, rom, size, last_image))
> > break;
> > } while (length && !last_image);

--
With Best Regards,
Andy Shevchenko