Linux Input/HID development
 help / color / mirror / Atom feed
* [PATCH v4 1/4] HID: hid-picolcd*: Convert sprintf() family to sysfs_emit() family
@ 2024-03-19  5:45 Li Zhijian
  2024-03-19  5:45 ` [PATCH v4 2/4] HID: hid-sensor-custom: " Li Zhijian
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Li Zhijian @ 2024-03-19  5:45 UTC (permalink / raw)
  To: linux-kernel
  Cc: Li Zhijian, Christophe JAILLET, Bruno Prémont, Jiri Kosina,
	Benjamin Tissoires, linux-input

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: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
CC: "Bruno Prémont" <bonbons@linux-vserver.org>
CC: Jiri Kosina <jikos@kernel.org>
CC: Benjamin Tissoires <benjamin.tissoires@redhat.com>
CC: linux-input@vger.kernel.org
Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
---
V4:
   Kill 'if (ret >= PAGE_SIZE)' which is always false in this context and sysfs_emit_at() is able to handle this case. # CJ
V3:
   Convert more file(drivers/hid/hid-picolcd_fb.c) as suggested by Bruno

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@fujitsu.com/
---
 drivers/hid/hid-picolcd_core.c | 6 +++---
 drivers/hid/hid-picolcd_fb.c   | 8 +++-----
 2 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/drivers/hid/hid-picolcd_core.c b/drivers/hid/hid-picolcd_core.c
index bbda231a7ce3..fa46fb6eab3f 100644
--- a/drivers/hid/hid-picolcd_core.c
+++ b/drivers/hid/hid-picolcd_core.c
@@ -256,9 +256,9 @@ static ssize_t picolcd_operation_mode_show(struct device *dev,
 	struct picolcd_data *data = dev_get_drvdata(dev);
 
 	if (data->status & PICOLCD_BOOTLOADER)
-		return snprintf(buf, PAGE_SIZE, "[bootloader] lcd\n");
+		return sysfs_emit(buf, "[bootloader] lcd\n");
 	else
-		return snprintf(buf, PAGE_SIZE, "bootloader [lcd]\n");
+		return sysfs_emit(buf, "bootloader [lcd]\n");
 }
 
 static ssize_t picolcd_operation_mode_store(struct device *dev,
@@ -301,7 +301,7 @@ static ssize_t picolcd_operation_mode_delay_show(struct device *dev,
 {
 	struct picolcd_data *data = dev_get_drvdata(dev);
 
-	return snprintf(buf, PAGE_SIZE, "%hu\n", data->opmode_delay);
+	return sysfs_emit(buf, "%hu\n", data->opmode_delay);
 }
 
 static ssize_t picolcd_operation_mode_delay_store(struct device *dev,
diff --git a/drivers/hid/hid-picolcd_fb.c b/drivers/hid/hid-picolcd_fb.c
index d7dddd99d325..063f9c01d2f7 100644
--- a/drivers/hid/hid-picolcd_fb.c
+++ b/drivers/hid/hid-picolcd_fb.c
@@ -421,12 +421,10 @@ static ssize_t picolcd_fb_update_rate_show(struct device *dev,
 	size_t ret = 0;
 
 	for (i = 1; i <= PICOLCDFB_UPDATE_RATE_LIMIT; i++)
-		if (ret >= PAGE_SIZE)
-			break;
-		else if (i == fb_update_rate)
-			ret += scnprintf(buf+ret, PAGE_SIZE-ret, "[%u] ", i);
+		if (i == fb_update_rate)
+			ret += sysfs_emit_at(buf, ret, "[%u] ", i);
 		else
-			ret += scnprintf(buf+ret, PAGE_SIZE-ret, "%u ", i);
+			ret += sysfs_emit_at(buf, ret, "%u ", i);
 	if (ret > 0)
 		buf[min(ret, (size_t)PAGE_SIZE)-1] = '\n';
 	return ret;
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-04-03 11:43 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-19  5:45 [PATCH v4 1/4] HID: hid-picolcd*: Convert sprintf() family to sysfs_emit() family Li Zhijian
2024-03-19  5:45 ` [PATCH v4 2/4] HID: hid-sensor-custom: " Li Zhijian
2024-03-24 12:16   ` Jonathan Cameron
2024-03-25  9:50     ` Zhijian Li (Fujitsu)
2024-03-19  5:45 ` [PATCH v4 3/4] HID: roccat: " Li Zhijian
2024-03-19  5:45 ` [PATCH v4 4/4] HID: corsair,lenovo: " Li Zhijian
2024-04-03 11:43 ` [PATCH v4 1/4] HID: hid-picolcd*: " Jiri Kosina

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox