All the call-backs used the same formula to retrieve the pcard from dev: struct pci_dev *pdev = to_pci_dev(dev); struct kp2000_device *pcard; if (!pdev) return NULL; pcard = pci_get_drvdata(pdev); Since to_pci_dev is a wrapper for container_of, it will not return NULL, and since pci_get_drvdata just calls dev_get_drvdata on the dev member of pdev, this is equivalent to: struct kp2000_device *pcard = dev_get_drvdata(&(container_of(dev, struct pci_dev, dev)->dev)); and we can simplify it to: struct kp2000_device *pcard = dev_get_drvdata(dev); Signed-off-by: Jeremy Sowden <jeremy@xxxxxxxxxx> --- drivers/staging/kpc2000/kpc2000/core.c | 28 +++++++++----------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/drivers/staging/kpc2000/kpc2000/core.c b/drivers/staging/kpc2000/kpc2000/core.c index 35e54e494fa3..f5ad90b17959 100644 --- a/drivers/staging/kpc2000/kpc2000/core.c +++ b/drivers/staging/kpc2000/kpc2000/core.c @@ -25,20 +25,10 @@ static DEFINE_IDA(card_num_ida); * SysFS Attributes ******************************************************/ -static struct kp2000_device *get_pcard(struct device *dev) -{ - struct pci_dev *pdev = to_pci_dev(dev); - - if (!pdev) - return NULL; - - return pci_get_drvdata(pdev); -} - static ssize_t ssid_show(struct device *dev, struct device_attribute *attr, char *buf) { - struct kp2000_device *pcard = get_pcard(dev); + struct kp2000_device *pcard = dev_get_drvdata(dev); if (!pcard) return -ENXIO; @@ -50,7 +40,7 @@ static DEVICE_ATTR_RO(ssid); static ssize_t ddna_show(struct device *dev, struct device_attribute *attr, char *buf) { - struct kp2000_device *pcard = get_pcard(dev); + struct kp2000_device *pcard = dev_get_drvdata(dev); if (!pcard) return -ENXIO; @@ -62,7 +52,7 @@ static DEVICE_ATTR_RO(ddna); static ssize_t card_id_show(struct device *dev, struct device_attribute *attr, char *buf) { - struct kp2000_device *pcard = get_pcard(dev); + struct kp2000_device *pcard = dev_get_drvdata(dev); if (!pcard) return -ENXIO; @@ -74,7 +64,7 @@ static DEVICE_ATTR_RO(card_id); static ssize_t hw_rev_show(struct device *dev, struct device_attribute *attr, char *buf) { - struct kp2000_device *pcard = get_pcard(dev); + struct kp2000_device *pcard = dev_get_drvdata(dev); if (!pcard) return -ENXIO; @@ -86,7 +76,7 @@ static DEVICE_ATTR_RO(hw_rev); static ssize_t build_show(struct device *dev, struct device_attribute *attr, char *buf) { - struct kp2000_device *pcard = get_pcard(dev); + struct kp2000_device *pcard = dev_get_drvdata(dev); if (!pcard) return -ENXIO; @@ -98,7 +88,7 @@ static DEVICE_ATTR_RO(build); static ssize_t build_date_show(struct device *dev, struct device_attribute *attr, char *buf) { - struct kp2000_device *pcard = get_pcard(dev); + struct kp2000_device *pcard = dev_get_drvdata(dev); if (!pcard) return -ENXIO; @@ -110,7 +100,7 @@ static DEVICE_ATTR_RO(build_date); static ssize_t build_time_show(struct device *dev, struct device_attribute *attr, char *buf) { - struct kp2000_device *pcard = get_pcard(dev); + struct kp2000_device *pcard = dev_get_drvdata(dev); if (!pcard) return -ENXIO; @@ -122,7 +112,7 @@ static DEVICE_ATTR_RO(build_time); static ssize_t cpld_reg_show(struct device *dev, struct device_attribute *attr, char *buf) { - struct kp2000_device *pcard = get_pcard(dev); + struct kp2000_device *pcard = dev_get_drvdata(dev); u64 val; if (!pcard) @@ -137,7 +127,7 @@ static ssize_t cpld_reconfigure(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - struct kp2000_device *pcard = get_pcard(dev); + struct kp2000_device *pcard = dev_get_drvdata(dev); long wr_val; int rv; -- 2.20.1 _______________________________________________ devel mailing list devel@xxxxxxxxxxxxxxxxxxxxxx http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel