Re: [PATCH v4 15/15] dmaengine: dw-edma: Add pcim_iomap_table return checker

From: Krzysztof Wilczyński
Date: Tue Feb 09 2021 - 17:16:05 EST


Hi Gustavo,

[...]
> > That's true, there are a lot of drivers that don't verify that pointer.
> > What do you suggest?
> > 1) To remove the verification so that is aligned with the other drivers
> > 2) Leave it as is. Or even to add this verification to the other drivers?
> >
> > Either way, I will add the pcim_iomap_table(pdev) before this
> > instruction.
> [...]
>
> A lot of the drivers consume the value from pcim_iomap_table() at
> a given BAR index directly as-is, some check if the pointer they got
> back is not NULL, a very few also check if the address at a given index
> is not NULL.
>
> Given that the memory allocation for the table can fail, we ought to
> check for a NULL pointer. It's a bit worrying that people decided to
> consume the value it returns directly without any verification.
>
> I only found two drivers that perform this additional verification of
> checking whether the address at a given index is valid, as per:
>
> https://lore.kernel.org/linux-pci/YCLFTjZQ2bCfGC+J@rocinante/
>
> Personally, I would opt for (2), and then like you suggested send
> a separate series to update other drivers so that they also include the
> this NULL pointer check.
>
> But let's wait for Bjorn's take on this, though.

As per Bjorn's reply:

https://lore.kernel.org/linux-pci/20210209185246.GA494880@bjorn-Precision-5520/

These extra checks I proposed would be definitely too much, especially
since almost everyone who uses pcim_iomap_table() also calls either
pcim_iomap_regions() or pcim_iomap_regions_request_all() before
accessing the table.

There probably is also an opportunity to simplify some of the other
drivers in the future, especially if do some API changes as per what
Bjorn suggested.

Sorry for taking your time, and thank you again!

Krzysztof