Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

intel_th: Convert sprintf/snprintf to sysfs_emit

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>

authored by

Li Zhijian and committed by
Greg Kroah-Hartman
212886f5 8dc0b2d3

+4 -4
+4 -4
drivers/hwtracing/intel_th/gth.c
··· 154 154 spin_unlock(&gth->gth_lock); 155 155 156 156 if (port >= 0) 157 - count = snprintf(buf, PAGE_SIZE, "%x\n", port); 157 + count = sysfs_emit(buf, "%x\n", port); 158 158 else 159 - count = snprintf(buf, PAGE_SIZE, "disabled\n"); 159 + count = sysfs_emit(buf, "disabled\n"); 160 160 161 161 return count; 162 162 } ··· 332 332 pm_runtime_get_sync(dev); 333 333 334 334 spin_lock(&gth->gth_lock); 335 - count = snprintf(buf, PAGE_SIZE, "%x\n", 336 - gth_output_parm_get(gth, oa->port, oa->parm)); 335 + count = sysfs_emit(buf, "%x\n", 336 + gth_output_parm_get(gth, oa->port, oa->parm)); 337 337 spin_unlock(&gth->gth_lock); 338 338 339 339 pm_runtime_put(dev);