From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by ash.osuosl.org (Postfix) with ESMTP id 75FC31BF282 for ; Tue, 21 May 2019 11:23:32 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 6E20C844A1 for ; Tue, 21 May 2019 11:23:32 +0000 (UTC) Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id QuJisEqx34lX for ; Tue, 21 May 2019 11:23:31 +0000 (UTC) Received: from userp2120.oracle.com (userp2120.oracle.com [156.151.31.85]) by fraxinus.osuosl.org (Postfix) with ESMTPS id D31128449F for ; Tue, 21 May 2019 11:23:31 +0000 (UTC) Date: Tue, 21 May 2019 14:23:13 +0300 From: Dan Carpenter Subject: Re: [PATCH v3 3/6] staging: kpc2000: simplified kp2000_device retrieval in device attributes call-backs. Message-ID: <20190521112312.GI31203@kadam> References: <20190517073057.GA2631@kroah.com> <20190517110315.10646-1-jeremy@azazel.net> <20190517110315.10646-4-jeremy@azazel.net> <20190517115451.GA1279@kroah.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20190517115451.GA1279@kroah.com> List-Id: Linux Driver Project Developer List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: driverdev-devel-bounces@linuxdriverproject.org Sender: "devel" To: Greg KH Cc: Linux Driver Project Developer List 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 _______________________________________________ devel mailing list devel@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel