[PATCH v3 3/6] staging: kpc2000: simplified kp2000_device retrieval in device attributes call-backs.
Dan Carpenter
dan.carpenter at oracle.com
Tue May 21 11:23:13 UTC 2019
On Fri, May 17, 2019 at 01:54:51PM +0200, Greg KH wrote:
> On Fri, May 17, 2019 at 12:03:12PM +0100, Jeremy Sowden wrote:
> > static ssize_t show_attr(struct device *dev, struct device_attribute *attr, char *buf)
> > {
> > - struct pci_dev *pdev = to_pci_dev(dev);
> > - struct kp2000_device *pcard;
> > -
> > - if (!pdev) return -ENXIO;
> > - pcard = pci_get_drvdata(pdev);
> > - if (!pcard) return -ENXIO;
> > + struct kp2000_device *pcard = dev_get_drvdata(dev);
>
> Wait, dev_get_drvdata() is not returning you the same pointer that
> pci_get_drvdata() does. So I think this is now broken :(
>
It looks sort of weird but it's fine.
> What this should look like is this:
> struct pci_dev *pdev = to_pci_dev(dev);
> struct kp200_device *pcard = pci_get_drvdata(pdev);
>
> if (!pcard)
> return -ENODEV;
>
> that is IF the driver really is setting the pci dev data to NULL when
> the device is removed from the driver. Is it?
Yes. The pci_get_drvdata() is only set to NULL after we remove the
sysfs files so pci_get_drvdata() always returns a valid pointer.
regards,
dan carpenter
More information about the devel
mailing list