OSDN Git Service

staging: kpc2000: simplified kp2000_device retrieval in device attribute call-backs.
authorJeremy Sowden <jeremy@azazel.net>
Tue, 21 May 2019 10:35:23 +0000 (11:35 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 22 May 2019 12:44:22 +0000 (14:44 +0200)
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@azazel.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/kpc2000/kpc2000/core.c

index 7d6b99f..2af4170 100644 (file)
@@ -32,20 +32,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;
@@ -57,7 +47,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;
@@ -69,7 +59,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;
@@ -81,7 +71,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;
@@ -93,7 +83,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;
@@ -105,7 +95,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;
@@ -117,7 +107,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;
@@ -129,7 +119,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)
@@ -144,7 +134,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;