[PATCH 08/11] staging: kpc2000: add separate show functions for readable kp device attributes.

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

 



Define separate simple show functions for each attribute instead of
having a one big one containing a chain of conditionals.

Signed-off-by: Jeremy Sowden <jeremy@xxxxxxxxxx>
---
 drivers/staging/kpc2000/kpc2000/core.c | 91 +++++++++++++++++++-------
 1 file changed, 67 insertions(+), 24 deletions(-)

diff --git a/drivers/staging/kpc2000/kpc2000/core.c b/drivers/staging/kpc2000/kpc2000/core.c
index c05864cf33ce..e7e0d188ff73 100644
--- a/drivers/staging/kpc2000/kpc2000/core.c
+++ b/drivers/staging/kpc2000/kpc2000/core.c
@@ -19,27 +19,70 @@
 #include <linux/jiffies.h>
 #include "pcie.h"
 
-
 static atomic_t next_card_num = ATOMIC_INIT(1);
 
 /*******************************************************
   * SysFS Attributes
   ******************************************************/
-static ssize_t  show_attr(struct device *dev, struct device_attribute *attr, char *buf)
+
+static ssize_t ssid_show(struct device *dev, struct device_attribute *attr,
+			 char *buf)
 {
-    struct kp2000_device *pcard = dev_get_drvdata(dev);
+	struct kp2000_device *pcard = dev_get_drvdata(dev);
+
+	return scnprintf(buf, PAGE_SIZE, "%016llx\n", pcard->ssid);
+}
+
+static ssize_t ddna_show(struct device *dev, struct device_attribute *attr,
+			 char *buf)
+{
+	struct kp2000_device *pcard = dev_get_drvdata(dev);
+
+	return scnprintf(buf, PAGE_SIZE, "%016llx\n", pcard->ddna);
+}
+
+static ssize_t card_id_show(struct device *dev, struct device_attribute *attr,
+			    char *buf)
+{
+	struct kp2000_device *pcard = dev_get_drvdata(dev);
+
+	return scnprintf(buf, PAGE_SIZE, "%08x\n", pcard->card_id);
+}
+
+static ssize_t hw_rev_show(struct device *dev, struct device_attribute *attr,
+			   char *buf)
+{
+	struct kp2000_device *pcard = dev_get_drvdata(dev);
 
-    if (strcmp("ssid", attr->attr.name) == 0){         return scnprintf(buf, PAGE_SIZE, "%016llx\n", pcard->ssid);  } else
-    if (strcmp("ddna", attr->attr.name) == 0){         return scnprintf(buf, PAGE_SIZE, "%016llx\n", pcard->ddna);  } else
-    if (strcmp("card_id", attr->attr.name) == 0){      return scnprintf(buf, PAGE_SIZE, "%08x\n", pcard->card_id);  } else
-    if (strcmp("hw_rev", attr->attr.name) == 0){       return scnprintf(buf, PAGE_SIZE, "%08x\n", pcard->hardware_revision);  } else
-    if (strcmp("build", attr->attr.name) == 0){        return scnprintf(buf, PAGE_SIZE, "%08x\n", pcard->build_version);  } else
-    if (strcmp("build_date", attr->attr.name) == 0){   return scnprintf(buf, PAGE_SIZE, "%08x\n", pcard->build_datestamp);  } else
-    if (strcmp("build_time", attr->attr.name) == 0){   return scnprintf(buf, PAGE_SIZE, "%08x\n", pcard->build_timestamp);  } else
-    { return -ENXIO; }
+	return scnprintf(buf, PAGE_SIZE, "%08x\n", pcard->hardware_revision);
 }
 
-static ssize_t  show_cpld_config_reg(struct device *dev, struct device_attribute *attr, char *buf)
+static ssize_t build_show(struct device *dev, struct device_attribute *attr,
+			  char *buf)
+{
+	struct kp2000_device *pcard = dev_get_drvdata(dev);
+
+	return scnprintf(buf, PAGE_SIZE, "%08x\n", pcard->build_version);
+}
+
+static ssize_t build_date_show(struct device *dev,
+			       struct device_attribute *attr, char *buf)
+{
+	struct kp2000_device *pcard = dev_get_drvdata(dev);
+
+	return scnprintf(buf, PAGE_SIZE, "%08x\n", pcard->build_datestamp);
+}
+
+static ssize_t build_time_show(struct device *dev,
+			       struct device_attribute *attr, char *buf)
+{
+	struct kp2000_device *pcard = dev_get_drvdata(dev);
+
+	return scnprintf(buf, PAGE_SIZE, "%08x\n", pcard->build_timestamp);
+}
+
+static ssize_t cpld_reg_show(struct device *dev, struct device_attribute *attr,
+			     char *buf)
 {
 	struct kp2000_device *pcard = dev_get_drvdata(dev);
 	u64 val;
@@ -47,6 +90,7 @@ static ssize_t  show_cpld_config_reg(struct device *dev, struct device_attribute
 	val = readq(pcard->sysinfo_regs_base + REG_CPLD_CONFIG);
 	return scnprintf(buf, PAGE_SIZE, "%016llx\n", val);
 }
+
 static ssize_t cpld_reconfigure(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
 {
     struct kp2000_device *pcard = dev_get_drvdata(dev);
@@ -63,18 +107,17 @@ static ssize_t cpld_reconfigure(struct device *dev, struct device_attribute *att
     return count;
 }
 
-
-DEVICE_ATTR(ssid,       0444, show_attr, NULL);
-DEVICE_ATTR(ddna,       0444, show_attr, NULL);
-DEVICE_ATTR(card_id,    0444, show_attr, NULL);
-DEVICE_ATTR(hw_rev,     0444, show_attr, NULL);
-DEVICE_ATTR(build,      0444, show_attr, NULL);
-DEVICE_ATTR(build_date, 0444, show_attr, NULL);
-DEVICE_ATTR(build_time, 0444, show_attr, NULL);
-DEVICE_ATTR(cpld_reg,   0444, show_cpld_config_reg, NULL);
-DEVICE_ATTR(cpld_reconfigure,   0220, NULL, cpld_reconfigure);
-
-static const struct attribute *  kp_attr_list[] = {
+DEVICE_ATTR(ssid,             0444, ssid_show,       NULL);
+DEVICE_ATTR(ddna,             0444, ddna_show,       NULL);
+DEVICE_ATTR(card_id,          0444, card_id_show,    NULL);
+DEVICE_ATTR(hw_rev,           0444, hw_rev_show,     NULL);
+DEVICE_ATTR(build,            0444, build_show,      NULL);
+DEVICE_ATTR(build_date,       0444, build_date_show, NULL);
+DEVICE_ATTR(build_time,       0444, build_time_show, NULL);
+DEVICE_ATTR(cpld_reg,         0444, cpld_reg_show,   NULL);
+DEVICE_ATTR(cpld_reconfigure, 0220, NULL,            cpld_reconfigure);
+
+static const struct attribute *kp_attr_list[] = {
     &dev_attr_ssid.attr,
     &dev_attr_ddna.attr,
     &dev_attr_card_id.attr,
-- 
2.20.1

_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel



[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux