This focuses on abused cases in macros Per filesystems/sysfs.rst, show() should only use sysfs_emit() or sysfs_emit_at() when formatting the value to be returned to user space. coccinelle complains that there are still a couple of functions that use snprintf(). Convert them to sysfs_emit(). sprintf() and scnprintf() will be converted as well if they have. Generally, this patch is generated by make coccicheck M=<path/to/file> MODE=patch \ COCCI=scripts/coccinelle/api/device_attr_show.cocci No functional change intended CC: "James E.J. Bottomley" <jejb@xxxxxxxxxxxxx> CC: "Martin K. Petersen" <martin.petersen@xxxxxxxxxx> CC: linux-scsi@xxxxxxxxxxxxxxx Signed-off-by: Li Zhijian <lizhijian@xxxxxxxxxxx> --- This is a part of the work "Fix coccicheck device_attr_show warnings"[1] Split them per subsystem so that the maintainer can review it easily [1] https://lore.kernel.org/lkml/20240116041129.3937800-1-lizhijian@xxxxxxxxxxx/ --- drivers/scsi/fcoe/fcoe_sysfs.c | 82 +++++++++++++++++----------------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c index 46a2f7f0669f..2baa1d6456fc 100644 --- a/drivers/scsi/fcoe/fcoe_sysfs.c +++ b/drivers/scsi/fcoe/fcoe_sysfs.c @@ -134,7 +134,7 @@ static int fcoe_fcf_set_dev_loss_tmo(struct fcoe_fcf_device *fcf, struct device_attribute device_attr_fcoe_##_prefix##_##_name = \ __ATTR(_name, _mode, _show, _store) -#define fcoe_ctlr_show_function(field, format_string, sz, cast) \ +#define fcoe_ctlr_show_function(field, format_string, cast) \ static ssize_t show_fcoe_ctlr_device_##field(struct device *dev, \ struct device_attribute *attr, \ char *buf) \ @@ -142,11 +142,11 @@ static ssize_t show_fcoe_ctlr_device_##field(struct device *dev, \ struct fcoe_ctlr_device *ctlr = dev_to_ctlr(dev); \ if (ctlr->f->get_fcoe_ctlr_##field) \ ctlr->f->get_fcoe_ctlr_##field(ctlr); \ - return snprintf(buf, sz, format_string, \ - cast fcoe_ctlr_##field(ctlr)); \ + return sysfs_emit(buf, format_string, \ + cast fcoe_ctlr_##field(ctlr)); \ } -#define fcoe_fcf_show_function(field, format_string, sz, cast) \ +#define fcoe_fcf_show_function(field, format_string, cast) \ static ssize_t show_fcoe_fcf_device_##field(struct device *dev, \ struct device_attribute *attr, \ char *buf) \ @@ -155,55 +155,55 @@ static ssize_t show_fcoe_fcf_device_##field(struct device *dev, \ struct fcoe_ctlr_device *ctlr = fcoe_fcf_dev_to_ctlr_dev(fcf); \ if (ctlr->f->get_fcoe_fcf_##field) \ ctlr->f->get_fcoe_fcf_##field(fcf); \ - return snprintf(buf, sz, format_string, \ - cast fcoe_fcf_##field(fcf)); \ + return sysfs_emit(buf, format_string, \ + cast fcoe_fcf_##field(fcf)); \ } -#define fcoe_ctlr_private_show_function(field, format_string, sz, cast) \ +#define fcoe_ctlr_private_show_function(field, format_string, cast) \ static ssize_t show_fcoe_ctlr_device_##field(struct device *dev, \ struct device_attribute *attr, \ char *buf) \ { \ struct fcoe_ctlr_device *ctlr = dev_to_ctlr(dev); \ - return snprintf(buf, sz, format_string, cast fcoe_ctlr_##field(ctlr)); \ + return sysfs_emit(buf, format_string, cast fcoe_ctlr_##field(ctlr)); \ } -#define fcoe_fcf_private_show_function(field, format_string, sz, cast) \ +#define fcoe_fcf_private_show_function(field, format_string, cast) \ static ssize_t show_fcoe_fcf_device_##field(struct device *dev, \ struct device_attribute *attr, \ char *buf) \ { \ struct fcoe_fcf_device *fcf = dev_to_fcf(dev); \ - return snprintf(buf, sz, format_string, cast fcoe_fcf_##field(fcf)); \ + return sysfs_emit(buf, format_string, cast fcoe_fcf_##field(fcf)); \ } -#define fcoe_ctlr_private_rd_attr(field, format_string, sz) \ - fcoe_ctlr_private_show_function(field, format_string, sz, ) \ +#define fcoe_ctlr_private_rd_attr(field, format_string) \ + fcoe_ctlr_private_show_function(field, format_string, ) \ static FCOE_DEVICE_ATTR(ctlr, field, S_IRUGO, \ show_fcoe_ctlr_device_##field, NULL) -#define fcoe_ctlr_rd_attr(field, format_string, sz) \ - fcoe_ctlr_show_function(field, format_string, sz, ) \ +#define fcoe_ctlr_rd_attr(field, format_string) \ + fcoe_ctlr_show_function(field, format_string, ) \ static FCOE_DEVICE_ATTR(ctlr, field, S_IRUGO, \ show_fcoe_ctlr_device_##field, NULL) -#define fcoe_fcf_rd_attr(field, format_string, sz) \ - fcoe_fcf_show_function(field, format_string, sz, ) \ +#define fcoe_fcf_rd_attr(field, format_string) \ + fcoe_fcf_show_function(field, format_string, ) \ static FCOE_DEVICE_ATTR(fcf, field, S_IRUGO, \ show_fcoe_fcf_device_##field, NULL) -#define fcoe_fcf_private_rd_attr(field, format_string, sz) \ - fcoe_fcf_private_show_function(field, format_string, sz, ) \ +#define fcoe_fcf_private_rd_attr(field, format_string) \ + fcoe_fcf_private_show_function(field, format_string, ) \ static FCOE_DEVICE_ATTR(fcf, field, S_IRUGO, \ show_fcoe_fcf_device_##field, NULL) -#define fcoe_ctlr_private_rd_attr_cast(field, format_string, sz, cast) \ - fcoe_ctlr_private_show_function(field, format_string, sz, (cast)) \ +#define fcoe_ctlr_private_rd_attr_cast(field, format_string, cast) \ + fcoe_ctlr_private_show_function(field, format_string, (cast)) \ static FCOE_DEVICE_ATTR(ctlr, field, S_IRUGO, \ show_fcoe_ctlr_device_##field, NULL) -#define fcoe_fcf_private_rd_attr_cast(field, format_string, sz, cast) \ - fcoe_fcf_private_show_function(field, format_string, sz, (cast)) \ +#define fcoe_fcf_private_rd_attr_cast(field, format_string, cast) \ + fcoe_fcf_private_show_function(field, format_string, (cast)) \ static FCOE_DEVICE_ATTR(fcf, field, S_IRUGO, \ show_fcoe_fcf_device_##field, NULL) @@ -489,30 +489,30 @@ store_private_fcoe_ctlr_fcf_dev_loss_tmo(struct device *dev, mutex_unlock(&ctlr->lock); return count; } -fcoe_ctlr_private_show_function(fcf_dev_loss_tmo, "%d\n", 20, ); +fcoe_ctlr_private_show_function(fcf_dev_loss_tmo, "%d\n", ); static FCOE_DEVICE_ATTR(ctlr, fcf_dev_loss_tmo, S_IRUGO | S_IWUSR, show_fcoe_ctlr_device_fcf_dev_loss_tmo, store_private_fcoe_ctlr_fcf_dev_loss_tmo); /* Link Error Status Block (LESB) */ -fcoe_ctlr_rd_attr(link_fail, "%u\n", 20); -fcoe_ctlr_rd_attr(vlink_fail, "%u\n", 20); -fcoe_ctlr_rd_attr(miss_fka, "%u\n", 20); -fcoe_ctlr_rd_attr(symb_err, "%u\n", 20); -fcoe_ctlr_rd_attr(err_block, "%u\n", 20); -fcoe_ctlr_rd_attr(fcs_error, "%u\n", 20); - -fcoe_fcf_private_rd_attr_cast(fabric_name, "0x%llx\n", 20, unsigned long long); -fcoe_fcf_private_rd_attr_cast(switch_name, "0x%llx\n", 20, unsigned long long); -fcoe_fcf_private_rd_attr(priority, "%u\n", 20); -fcoe_fcf_private_rd_attr(fc_map, "0x%x\n", 20); -fcoe_fcf_private_rd_attr(vfid, "%u\n", 20); -fcoe_fcf_private_rd_attr(mac, "%pM\n", 20); -fcoe_fcf_private_rd_attr(fka_period, "%u\n", 20); -fcoe_fcf_rd_attr(selected, "%u\n", 20); -fcoe_fcf_rd_attr(vlan_id, "%u\n", 20); - -fcoe_fcf_private_show_function(dev_loss_tmo, "%d\n", 20, ) +fcoe_ctlr_rd_attr(link_fail, "%u\n"); +fcoe_ctlr_rd_attr(vlink_fail, "%u\n"); +fcoe_ctlr_rd_attr(miss_fka, "%u\n"); +fcoe_ctlr_rd_attr(symb_err, "%u\n"); +fcoe_ctlr_rd_attr(err_block, "%u\n"); +fcoe_ctlr_rd_attr(fcs_error, "%u\n"); + +fcoe_fcf_private_rd_attr_cast(fabric_name, "0x%llx\n", unsigned long long); +fcoe_fcf_private_rd_attr_cast(switch_name, "0x%llx\n", unsigned long long); +fcoe_fcf_private_rd_attr(priority, "%u\n"); +fcoe_fcf_private_rd_attr(fc_map, "0x%x\n"); +fcoe_fcf_private_rd_attr(vfid, "%u\n"); +fcoe_fcf_private_rd_attr(mac, "%pM\n"); +fcoe_fcf_private_rd_attr(fka_period, "%u\n"); +fcoe_fcf_rd_attr(selected, "%u\n"); +fcoe_fcf_rd_attr(vlan_id, "%u\n"); + +fcoe_fcf_private_show_function(dev_loss_tmo, "%d\n", ) static ssize_t store_fcoe_fcf_dev_loss_tmo(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) -- 2.29.2