intel_th: Convert sprintf/snprintf to sysfs_emit
authorLi Zhijian <lizhijian@fujitsu.com>
Mon, 29 Apr 2024 13:01:11 +0000 (16:01 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 4 May 2024 16:57:22 +0000 (18:57 +0200)
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() will be converted as weel 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

Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/r/20240429130119.1518073-8-alexander.shishkin@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/hwtracing/intel_th/gth.c

index b3308934a687dfbf8b24af75c620bfa72d5ea028..3883f99fd5d5d5b9d7cd69be715e6d03a82bff27 100644 (file)
@@ -154,9 +154,9 @@ static ssize_t master_attr_show(struct device *dev,
        spin_unlock(&gth->gth_lock);
 
        if (port >= 0)
-               count = snprintf(buf, PAGE_SIZE, "%x\n", port);
+               count = sysfs_emit(buf, "%x\n", port);
        else
-               count = snprintf(buf, PAGE_SIZE, "disabled\n");
+               count = sysfs_emit(buf, "disabled\n");
 
        return count;
 }
@@ -332,8 +332,8 @@ static ssize_t output_attr_show(struct device *dev,
        pm_runtime_get_sync(dev);
 
        spin_lock(&gth->gth_lock);
-       count = snprintf(buf, PAGE_SIZE, "%x\n",
-                        gth_output_parm_get(gth, oa->port, oa->parm));
+       count = sysfs_emit(buf, "%x\n",
+                          gth_output_parm_get(gth, oa->port, oa->parm));
        spin_unlock(&gth->gth_lock);
 
        pm_runtime_put(dev);