Re: [V2 2/6] driver core: auxiliary bus: Add driver data helpers

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

 



[+cc Rafael, since I used generic PM as an example]

On Wed, Dec 08, 2021 at 09:47:56AM +0100, Greg KH wrote:
> On Wed, Dec 08, 2021 at 08:43:53AM +0000, Lee Jones wrote:
> > On Wed, 08 Dec 2021, Greg KH wrote:
> > > On Wed, Dec 08, 2021 at 09:03:16AM +0200, Leon Romanovsky wrote:
> > > > On Tue, Dec 07, 2021 at 09:14:44AM -0800, David E. Box wrote:
> > > > > Adds get/set driver data helpers for auxiliary devices.
> > > > > 
> > > > > Signed-off-by: David E. Box <david.e.box@xxxxxxxxxxxxxxx>
> > > > > Reviewed-by: Mark Gross <markgross@xxxxxxxxxx>
> > > > > ---
> > > > > V2
> > > > >   - No changes
> > > > > 
> > > > >  include/linux/auxiliary_bus.h | 10 ++++++++++
> > > > >  1 file changed, 10 insertions(+)
> > > > 
> > > > I would really like to see an explanation why such obfuscation is really
> > > > needed. dev_*_drvdata() is a standard way to access driver data.
> > 
> > I wouldn't call it obfuscation, but it does looks like abstraction for
> > the sake of abstraction, which I usually push back on.  What are the
> > technical benefits over using the dev_*() variant?
> 
> See my response at:
> 	https://lore.kernel.org/r/YbBwOb6JvWkT3JWI@xxxxxxxxx
> for why it is a good thing to do.
> 
> In short, driver authors should not have to worry about mixing
> bus-specific and low-level driver core functions.

In the very common situation of PCI drivers that use generic power
management, authors *do* have to use both (example from [1]):

  ioh_gpio_probe(struct pci_dev *pdev)   # pci_driver.probe()
    pci_set_drvdata(pdev, chip);

  ioh_gpio_remove(struct pci_dev *pdev)  # pci_driver.remove()
    struct ioh_gpio *chip = pci_get_drvdata(pdev);

  ioh_gpio_suspend(struct device *dev)   # pci_driver.driver.pm.suspend()
    struct ioh_gpio *chip = dev_get_drvdata(dev);   <--

The pci_driver methods receive a struct pci_dev and use the
pci_get_drvdata() wrapper.

The generic power management methods receive a struct device and use
the underlying dev_get_drvdata().

It's kind of ugly that readers have to know that pci_get_drvdata()
gives you the same thing as dev_get_drvdata().

I guess the generic PM methods could do something like:

  pci_get_drvdata(to_pci_dev(dev));

but that seems a little bit circuitous.  It's slightly wordier, but I
might prefer to just use this everywhere and skip the pci_* wrappers:

  dev_get_drvdata(&pdev->dev);

Bjorn

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/gpio/gpio-ml-ioh.c?id=v5.15#n505



[Index of Archives]     [DMA Engine]     [Linux Coverity]     [Linux USB]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Greybus]

  Powered by Linux