Define separate simple show functions for each attribute instead of having a one big one containing a chain of conditionals. Replaced calls to scnprintf with sprintf since all the outputs are single integers. All the readable device attributes are read-only, so use DEVICE_ATTR_RO to define them. The definitions are only used to populate the kp_attr_list attribute array, so declare them as static. Fixes the following sparse warnings: drivers/staging/kpc2000/kpc2000/core.c:152:1: warning: symbol 'dev_attr_ssid' was not declared. Should it be static? drivers/staging/kpc2000/kpc2000/core.c:153:1: warning: symbol 'dev_attr_ddna' was not declared. Should it be static? drivers/staging/kpc2000/kpc2000/core.c:154:1: warning: symbol 'dev_attr_card_id' was not declared. Should it be static? drivers/staging/kpc2000/kpc2000/core.c:155:1: warning: symbol 'dev_attr_hw_rev' was not declared. Should it be static? drivers/staging/kpc2000/kpc2000/core.c:156:1: warning: symbol 'dev_attr_build' was not declared. Should it be static? drivers/staging/kpc2000/kpc2000/core.c:157:1: warning: symbol 'dev_attr_build_date' was not declared. Should it be static? drivers/staging/kpc2000/kpc2000/core.c:158:1: warning: symbol 'dev_attr_build_time' was not declared. Should it be static? drivers/staging/kpc2000/kpc2000/core.c:159:1: warning: symbol 'dev_attr_cpld_reg' was not declared. Should it be static? drivers/staging/kpc2000/kpc2000/core.c:161:1: warning: symbol 'dev_attr_cpld_reconfigure' was not declared. Should it be static? Signed-off-by: Jeremy Sowden <jeremy@xxxxxxxxxx> --- drivers/staging/kpc2000/kpc2000/core.c | 89 +++++++++++++++++++------- 1 file changed, 66 insertions(+), 23 deletions(-) diff --git a/drivers/staging/kpc2000/kpc2000/core.c b/drivers/staging/kpc2000/kpc2000/core.c index cbd634caeade..80141514f7d1 100644 --- a/drivers/staging/kpc2000/kpc2000/core.c +++ b/drivers/staging/kpc2000/kpc2000/core.c @@ -22,28 +22,80 @@ /******************************************************* * 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); + + return sprintf(buf, "%016llx\n", pcard->ssid); +} +static DEVICE_ATTR_RO(ssid); + +static ssize_t ddna_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct kp2000_device *pcard = dev_get_drvdata(dev); + + return sprintf(buf, "%016llx\n", pcard->ddna); +} +static DEVICE_ATTR_RO(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 sprintf(buf, "%08x\n", pcard->card_id); +} +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 = dev_get_drvdata(dev); + + return sprintf(buf, "%08x\n", pcard->hardware_revision); +} +static DEVICE_ATTR_RO(hw_rev); + +static ssize_t build_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; } + struct kp2000_device *pcard = dev_get_drvdata(dev); + + return sprintf(buf, "%08x\n", pcard->build_version); } +static DEVICE_ATTR_RO(build); -static ssize_t show_cpld_config_reg(struct device *dev, struct device_attribute *attr, char *buf) +static ssize_t build_date_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct kp2000_device *pcard = dev_get_drvdata(dev); + + return sprintf(buf, "%08x\n", pcard->build_datestamp); +} +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 = dev_get_drvdata(dev); + + return sprintf(buf, "%08x\n", pcard->build_timestamp); +} +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 = dev_get_drvdata(dev); u64 val; val = readq(pcard->sysinfo_regs_base + REG_CPLD_CONFIG); - return scnprintf(buf, PAGE_SIZE, "%016llx\n", val); + return sprintf(buf, "%016llx\n", val); } +static DEVICE_ATTR_RO(cpld_reg); static ssize_t cpld_reconfigure(struct device *dev, struct device_attribute *attr, @@ -64,16 +116,7 @@ static ssize_t cpld_reconfigure(struct device *dev, writeq(wr_val, pcard->sysinfo_regs_base + REG_CPLD_CONFIG); 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 DEVICE_ATTR(cpld_reconfigure, 0220, NULL, cpld_reconfigure); static const struct attribute *kp_attr_list[] = { &dev_attr_ssid.attr, -- 2.20.1 _______________________________________________ devel mailing list devel@xxxxxxxxxxxxxxxxxxxxxx http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel