linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V2 0/5] hid: replace snprintf in show functions with sysfs_emit
@ 2021-10-15 11:07 Qing Wang
  2021-10-15 11:07 ` [PATCH V2 1/5] hid-lenovo: " Qing Wang
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Qing Wang @ 2021-10-15 11:07 UTC (permalink / raw)
  To: Jiri Kosina, Benjamin Tissoires, Bruno Prémont,
	Stefan Achatz, Jonathan Cameron, Srinivas Pandruvada,
	linux-input, linux-kernel, linux-iio
  Cc: Qing Wang

According to Documentation/filesystems/sysfs.txt:
show() methods of device attributes should return the number
of bytes printed into the buffer. This is the return value of 
scnprintf(). snprintf() returns the length the resulting string.

So, show() should not use snprintf() when formatting 
the value to be returned to user space. 
Also, use sysfs_emit directly makes more sense.

Qing Wang (5):
  hid-lenovo: replace snprintf in show functions with sysfs_emit
  hid-picolcd: replace snprintf in show functions with sysfs_emit
  hid-roccat: replace snprintf in show functions with sysfs_emit
  hid-sensor: replace snprintf in show functions with sysfs_emit
  hid-sony: replace snprintf in show functions with sysfs_emit

 drivers/hid/hid-lenovo.c          | 16 ++++++++--------
 drivers/hid/hid-picolcd_core.c    |  6 +++---
 drivers/hid/hid-roccat-isku.c     |  2 +-
 drivers/hid/hid-roccat-kone.c     | 12 ++++++------
 drivers/hid/hid-roccat-koneplus.c |  4 ++--
 drivers/hid/hid-roccat-kovaplus.c | 10 +++++-----
 drivers/hid/hid-roccat-pyra.c     |  6 +++---
 drivers/hid/hid-sensor-custom.c   |  2 +-
 drivers/hid/hid-sony.c            |  6 +++---
 9 files changed, 32 insertions(+), 32 deletions(-)

-- 
2.7.4


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

* [PATCH V2 1/5] hid-lenovo: replace snprintf in show functions with sysfs_emit
  2021-10-15 11:07 [PATCH V2 0/5] hid: replace snprintf in show functions with sysfs_emit Qing Wang
@ 2021-10-15 11:07 ` Qing Wang
  2021-10-15 13:51   ` Jonathan Cameron
  2021-10-15 11:07 ` [PATCH V2 2/5] hid-picolcd: " Qing Wang
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 8+ messages in thread
From: Qing Wang @ 2021-10-15 11:07 UTC (permalink / raw)
  To: Jiri Kosina, Benjamin Tissoires, Bruno Prémont,
	Stefan Achatz, Jonathan Cameron, Srinivas Pandruvada,
	linux-input, linux-kernel, linux-iio
  Cc: Qing Wang

show() should not use snprintf() when formatting the value to be returned 
to user space, snprintf() returns the length the resulting string and 
scnprintf() returns the number of bytes printed into the buffer.

Fix the coccicheck warnings:
WARNING: use scnprintf or sprintf.

Use sysfs_emit() instead of scnprintf() makes more sense.

Signed-off-by: Qing Wang <wangqing@vivo.com>
---
 drivers/hid/hid-lenovo.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/hid/hid-lenovo.c b/drivers/hid/hid-lenovo.c
index 93b1f93..086a7ae 100644
--- a/drivers/hid/hid-lenovo.c
+++ b/drivers/hid/hid-lenovo.c
@@ -400,7 +400,7 @@ static ssize_t attr_fn_lock_show(struct device *dev,
 	struct hid_device *hdev = to_hid_device(dev);
 	struct lenovo_drvdata *data = hid_get_drvdata(hdev);
 
-	return snprintf(buf, PAGE_SIZE, "%u\n", data->fn_lock);
+	return sysfs_emit(buf, "%u\n", data->fn_lock);
 }
 
 static ssize_t attr_fn_lock_store(struct device *dev,
@@ -442,7 +442,7 @@ static ssize_t attr_sensitivity_show_cptkbd(struct device *dev,
 	struct hid_device *hdev = to_hid_device(dev);
 	struct lenovo_drvdata *cptkbd_data = hid_get_drvdata(hdev);
 
-	return snprintf(buf, PAGE_SIZE, "%u\n",
+	return sysfs_emit(buf, "%u\n",
 		cptkbd_data->sensitivity);
 }
 
@@ -603,7 +603,7 @@ static ssize_t attr_press_to_select_show_tpkbd(struct device *dev,
 	struct hid_device *hdev = to_hid_device(dev);
 	struct lenovo_drvdata *data_pointer = hid_get_drvdata(hdev);
 
-	return snprintf(buf, PAGE_SIZE, "%u\n", data_pointer->press_to_select);
+	return sysfs_emit(buf, "%u\n", data_pointer->press_to_select);
 }
 
 static ssize_t attr_press_to_select_store_tpkbd(struct device *dev,
@@ -633,7 +633,7 @@ static ssize_t attr_dragging_show_tpkbd(struct device *dev,
 	struct hid_device *hdev = to_hid_device(dev);
 	struct lenovo_drvdata *data_pointer = hid_get_drvdata(hdev);
 
-	return snprintf(buf, PAGE_SIZE, "%u\n", data_pointer->dragging);
+	return sysfs_emit(buf, "%u\n", data_pointer->dragging);
 }
 
 static ssize_t attr_dragging_store_tpkbd(struct device *dev,
@@ -663,7 +663,7 @@ static ssize_t attr_release_to_select_show_tpkbd(struct device *dev,
 	struct hid_device *hdev = to_hid_device(dev);
 	struct lenovo_drvdata *data_pointer = hid_get_drvdata(hdev);
 
-	return snprintf(buf, PAGE_SIZE, "%u\n", data_pointer->release_to_select);
+	return sysfs_emit(buf, "%u\n", data_pointer->release_to_select);
 }
 
 static ssize_t attr_release_to_select_store_tpkbd(struct device *dev,
@@ -693,7 +693,7 @@ static ssize_t attr_select_right_show_tpkbd(struct device *dev,
 	struct hid_device *hdev = to_hid_device(dev);
 	struct lenovo_drvdata *data_pointer = hid_get_drvdata(hdev);
 
-	return snprintf(buf, PAGE_SIZE, "%u\n", data_pointer->select_right);
+	return sysfs_emit(buf, "%u\n", data_pointer->select_right);
 }
 
 static ssize_t attr_select_right_store_tpkbd(struct device *dev,
@@ -723,7 +723,7 @@ static ssize_t attr_sensitivity_show_tpkbd(struct device *dev,
 	struct hid_device *hdev = to_hid_device(dev);
 	struct lenovo_drvdata *data_pointer = hid_get_drvdata(hdev);
 
-	return snprintf(buf, PAGE_SIZE, "%u\n",
+	return sysfs_emit(buf, "%u\n",
 		data_pointer->sensitivity);
 }
 
@@ -752,7 +752,7 @@ static ssize_t attr_press_speed_show_tpkbd(struct device *dev,
 	struct hid_device *hdev = to_hid_device(dev);
 	struct lenovo_drvdata *data_pointer = hid_get_drvdata(hdev);
 
-	return snprintf(buf, PAGE_SIZE, "%u\n",
+	return sysfs_emit(buf, "%u\n",
 		data_pointer->press_speed);
 }
 
-- 
2.7.4


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

* [PATCH V2 2/5] hid-picolcd: replace snprintf in show functions with sysfs_emit
  2021-10-15 11:07 [PATCH V2 0/5] hid: replace snprintf in show functions with sysfs_emit Qing Wang
  2021-10-15 11:07 ` [PATCH V2 1/5] hid-lenovo: " Qing Wang
@ 2021-10-15 11:07 ` Qing Wang
  2021-10-15 11:07 ` [PATCH V2 3/5] hid-roccat: " Qing Wang
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Qing Wang @ 2021-10-15 11:07 UTC (permalink / raw)
  To: Jiri Kosina, Benjamin Tissoires, Bruno Prémont,
	Stefan Achatz, Jonathan Cameron, Srinivas Pandruvada,
	linux-input, linux-kernel, linux-iio
  Cc: Qing Wang

show() should not use snprintf() when formatting the value to be returned 
to user space, snprintf() returns the length the resulting string and 
scnprintf() returns the number of bytes printed into the buffer.

Fix the coccicheck warnings:
WARNING: use scnprintf or sprintf.

Use sysfs_emit() instead of scnprintf() makes more sense.

Signed-off-by: Qing Wang <wangqing@vivo.com>
Acked-by: Bruno Prémont <bonbons@linux-vserver.org>
---
 drivers/hid/hid-picolcd_core.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/hid/hid-picolcd_core.c b/drivers/hid/hid-picolcd_core.c
index bbda231..fa46fb6 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,
-- 
2.7.4


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

* [PATCH V2 3/5] hid-roccat: replace snprintf in show functions with sysfs_emit
  2021-10-15 11:07 [PATCH V2 0/5] hid: replace snprintf in show functions with sysfs_emit Qing Wang
  2021-10-15 11:07 ` [PATCH V2 1/5] hid-lenovo: " Qing Wang
  2021-10-15 11:07 ` [PATCH V2 2/5] hid-picolcd: " Qing Wang
@ 2021-10-15 11:07 ` Qing Wang
  2021-10-15 11:07 ` [PATCH V2 4/5] hid-sensor: " Qing Wang
  2021-10-15 11:07 ` [PATCH V2 5/5] hid-sony: " Qing Wang
  4 siblings, 0 replies; 8+ messages in thread
From: Qing Wang @ 2021-10-15 11:07 UTC (permalink / raw)
  To: Jiri Kosina, Benjamin Tissoires, Bruno Prémont,
	Stefan Achatz, Jonathan Cameron, Srinivas Pandruvada,
	linux-input, linux-kernel, linux-iio
  Cc: Qing Wang

show() should not use snprintf() when formatting the value to be returned 
to user space, snprintf() returns the length the resulting string and 
scnprintf() returns the number of bytes printed into the buffer.

Fix the coccicheck warnings:
WARNING: use scnprintf or sprintf.

Use sysfs_emit() instead of scnprintf() makes more sense.

Signed-off-by: Qing Wang <wangqing@vivo.com>
---
 drivers/hid/hid-roccat-isku.c     |  2 +-
 drivers/hid/hid-roccat-kone.c     | 12 ++++++------
 drivers/hid/hid-roccat-koneplus.c |  4 ++--
 drivers/hid/hid-roccat-kovaplus.c | 10 +++++-----
 drivers/hid/hid-roccat-pyra.c     |  6 +++---
 5 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/drivers/hid/hid-roccat-isku.c b/drivers/hid/hid-roccat-isku.c
index ce5f225..58eb4b0 100644
--- a/drivers/hid/hid-roccat-isku.c
+++ b/drivers/hid/hid-roccat-isku.c
@@ -63,7 +63,7 @@ static ssize_t isku_sysfs_show_actual_profile(struct device *dev,
 {
 	struct isku_device *isku =
 			hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
-	return snprintf(buf, PAGE_SIZE, "%d\n", isku->actual_profile);
+	return sysfs_emit(buf, "%d\n", isku->actual_profile);
 }
 
 static ssize_t isku_sysfs_set_actual_profile(struct device *dev,
diff --git a/drivers/hid/hid-roccat-kone.c b/drivers/hid/hid-roccat-kone.c
index ea17abc..e53d005 100644
--- a/drivers/hid/hid-roccat-kone.c
+++ b/drivers/hid/hid-roccat-kone.c
@@ -403,7 +403,7 @@ static ssize_t kone_sysfs_show_actual_profile(struct device *dev,
 {
 	struct kone_device *kone =
 			hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
-	return snprintf(buf, PAGE_SIZE, "%d\n", kone->actual_profile);
+	return sysfs_emit(buf, "%d\n", kone->actual_profile);
 }
 static DEVICE_ATTR(actual_profile, 0440, kone_sysfs_show_actual_profile, NULL);
 
@@ -412,7 +412,7 @@ static ssize_t kone_sysfs_show_actual_dpi(struct device *dev,
 {
 	struct kone_device *kone =
 			hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
-	return snprintf(buf, PAGE_SIZE, "%d\n", kone->actual_dpi);
+	return sysfs_emit(buf, "%d\n", kone->actual_dpi);
 }
 static DEVICE_ATTR(actual_dpi, 0440, kone_sysfs_show_actual_dpi, NULL);
 
@@ -435,7 +435,7 @@ static ssize_t kone_sysfs_show_weight(struct device *dev,
 
 	if (retval)
 		return retval;
-	return snprintf(buf, PAGE_SIZE, "%d\n", weight);
+	return sysfs_emit(buf, "%d\n", weight);
 }
 static DEVICE_ATTR(weight, 0440, kone_sysfs_show_weight, NULL);
 
@@ -444,7 +444,7 @@ static ssize_t kone_sysfs_show_firmware_version(struct device *dev,
 {
 	struct kone_device *kone =
 			hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
-	return snprintf(buf, PAGE_SIZE, "%d\n", kone->firmware_version);
+	return sysfs_emit(buf, "%d\n", kone->firmware_version);
 }
 static DEVICE_ATTR(firmware_version, 0440, kone_sysfs_show_firmware_version,
 		   NULL);
@@ -454,7 +454,7 @@ static ssize_t kone_sysfs_show_tcu(struct device *dev,
 {
 	struct kone_device *kone =
 			hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
-	return snprintf(buf, PAGE_SIZE, "%d\n", kone->settings.tcu);
+	return sysfs_emit(buf, "%d\n", kone->settings.tcu);
 }
 
 static int kone_tcu_command(struct usb_device *usb_dev, int number)
@@ -556,7 +556,7 @@ static ssize_t kone_sysfs_show_startup_profile(struct device *dev,
 {
 	struct kone_device *kone =
 			hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
-	return snprintf(buf, PAGE_SIZE, "%d\n", kone->settings.startup_profile);
+	return sysfs_emit(buf, "%d\n", kone->settings.startup_profile);
 }
 
 static ssize_t kone_sysfs_set_startup_profile(struct device *dev,
diff --git a/drivers/hid/hid-roccat-koneplus.c b/drivers/hid/hid-roccat-koneplus.c
index 0316edf..9c39b17 100644
--- a/drivers/hid/hid-roccat-koneplus.c
+++ b/drivers/hid/hid-roccat-koneplus.c
@@ -244,7 +244,7 @@ static ssize_t koneplus_sysfs_show_actual_profile(struct device *dev,
 {
 	struct koneplus_device *koneplus =
 			hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
-	return snprintf(buf, PAGE_SIZE, "%d\n", koneplus->actual_profile);
+	return sysfs_emit(buf, "%d\n", koneplus->actual_profile);
 }
 
 static ssize_t koneplus_sysfs_set_actual_profile(struct device *dev,
@@ -311,7 +311,7 @@ static ssize_t koneplus_sysfs_show_firmware_version(struct device *dev,
 			&info, KONEPLUS_SIZE_INFO);
 	mutex_unlock(&koneplus->koneplus_lock);
 
-	return snprintf(buf, PAGE_SIZE, "%d\n", info.firmware_version);
+	return sysfs_emit(buf, "%d\n", info.firmware_version);
 }
 static DEVICE_ATTR(firmware_version, 0440,
 		   koneplus_sysfs_show_firmware_version, NULL);
diff --git a/drivers/hid/hid-roccat-kovaplus.c b/drivers/hid/hid-roccat-kovaplus.c
index 9600128..17581c4 100644
--- a/drivers/hid/hid-roccat-kovaplus.c
+++ b/drivers/hid/hid-roccat-kovaplus.c
@@ -274,7 +274,7 @@ static ssize_t kovaplus_sysfs_show_actual_profile(struct device *dev,
 {
 	struct kovaplus_device *kovaplus =
 			hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
-	return snprintf(buf, PAGE_SIZE, "%d\n", kovaplus->actual_profile);
+	return sysfs_emit(buf, "%d\n", kovaplus->actual_profile);
 }
 
 static ssize_t kovaplus_sysfs_set_actual_profile(struct device *dev,
@@ -327,7 +327,7 @@ static ssize_t kovaplus_sysfs_show_actual_cpi(struct device *dev,
 {
 	struct kovaplus_device *kovaplus =
 			hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
-	return snprintf(buf, PAGE_SIZE, "%d\n", kovaplus->actual_cpi);
+	return sysfs_emit(buf, "%d\n", kovaplus->actual_cpi);
 }
 static DEVICE_ATTR(actual_cpi, 0440, kovaplus_sysfs_show_actual_cpi, NULL);
 
@@ -336,7 +336,7 @@ static ssize_t kovaplus_sysfs_show_actual_sensitivity_x(struct device *dev,
 {
 	struct kovaplus_device *kovaplus =
 			hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
-	return snprintf(buf, PAGE_SIZE, "%d\n", kovaplus->actual_x_sensitivity);
+	return sysfs_emit(buf, "%d\n", kovaplus->actual_x_sensitivity);
 }
 static DEVICE_ATTR(actual_sensitivity_x, 0440,
 		   kovaplus_sysfs_show_actual_sensitivity_x, NULL);
@@ -346,7 +346,7 @@ static ssize_t kovaplus_sysfs_show_actual_sensitivity_y(struct device *dev,
 {
 	struct kovaplus_device *kovaplus =
 			hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
-	return snprintf(buf, PAGE_SIZE, "%d\n", kovaplus->actual_y_sensitivity);
+	return sysfs_emit(buf, "%d\n", kovaplus->actual_y_sensitivity);
 }
 static DEVICE_ATTR(actual_sensitivity_y, 0440,
 		   kovaplus_sysfs_show_actual_sensitivity_y, NULL);
@@ -367,7 +367,7 @@ static ssize_t kovaplus_sysfs_show_firmware_version(struct device *dev,
 			&info, KOVAPLUS_SIZE_INFO);
 	mutex_unlock(&kovaplus->kovaplus_lock);
 
-	return snprintf(buf, PAGE_SIZE, "%d\n", info.firmware_version);
+	return sysfs_emit(buf, "%d\n", info.firmware_version);
 }
 static DEVICE_ATTR(firmware_version, 0440,
 		   kovaplus_sysfs_show_firmware_version, NULL);
diff --git a/drivers/hid/hid-roccat-pyra.c b/drivers/hid/hid-roccat-pyra.c
index 989927d..9cfa003 100644
--- a/drivers/hid/hid-roccat-pyra.c
+++ b/drivers/hid/hid-roccat-pyra.c
@@ -286,7 +286,7 @@ static ssize_t pyra_sysfs_show_actual_cpi(struct device *dev,
 {
 	struct pyra_device *pyra =
 			hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
-	return snprintf(buf, PAGE_SIZE, "%d\n", pyra->actual_cpi);
+	return sysfs_emit(buf, "%d\n", pyra->actual_cpi);
 }
 static DEVICE_ATTR(actual_cpi, 0440, pyra_sysfs_show_actual_cpi, NULL);
 
@@ -303,7 +303,7 @@ static ssize_t pyra_sysfs_show_actual_profile(struct device *dev,
 			&settings, PYRA_SIZE_SETTINGS);
 	mutex_unlock(&pyra->pyra_lock);
 
-	return snprintf(buf, PAGE_SIZE, "%d\n", settings.startup_profile);
+	return sysfs_emit(buf, "%d\n", settings.startup_profile);
 }
 static DEVICE_ATTR(actual_profile, 0440, pyra_sysfs_show_actual_profile, NULL);
 static DEVICE_ATTR(startup_profile, 0440, pyra_sysfs_show_actual_profile, NULL);
@@ -324,7 +324,7 @@ static ssize_t pyra_sysfs_show_firmware_version(struct device *dev,
 			&info, PYRA_SIZE_INFO);
 	mutex_unlock(&pyra->pyra_lock);
 
-	return snprintf(buf, PAGE_SIZE, "%d\n", info.firmware_version);
+	return sysfs_emit(buf, "%d\n", info.firmware_version);
 }
 static DEVICE_ATTR(firmware_version, 0440, pyra_sysfs_show_firmware_version,
 		   NULL);
-- 
2.7.4


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

* [PATCH V2 4/5] hid-sensor: replace snprintf in show functions with sysfs_emit
  2021-10-15 11:07 [PATCH V2 0/5] hid: replace snprintf in show functions with sysfs_emit Qing Wang
                   ` (2 preceding siblings ...)
  2021-10-15 11:07 ` [PATCH V2 3/5] hid-roccat: " Qing Wang
@ 2021-10-15 11:07 ` Qing Wang
  2021-10-15 13:48   ` Jonathan Cameron
  2021-10-15 11:07 ` [PATCH V2 5/5] hid-sony: " Qing Wang
  4 siblings, 1 reply; 8+ messages in thread
From: Qing Wang @ 2021-10-15 11:07 UTC (permalink / raw)
  To: Jiri Kosina, Benjamin Tissoires, Bruno Prémont,
	Stefan Achatz, Jonathan Cameron, Srinivas Pandruvada,
	linux-input, linux-kernel, linux-iio
  Cc: Qing Wang

show() should not use snprintf() when formatting the value to be returned 
to user space, snprintf() returns the length the resulting string and 
scnprintf() returns the number of bytes printed into the buffer.

Fix the coccicheck warnings:
WARNING: use scnprintf or sprintf.

Use sysfs_emit() instead of scnprintf() makes more sense.

Signed-off-by: Qing Wang <wangqing@vivo.com>
---
 drivers/hid/hid-sensor-custom.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/hid/hid-sensor-custom.c b/drivers/hid/hid-sensor-custom.c
index 32c2306..a46481d6 100644
--- a/drivers/hid/hid-sensor-custom.c
+++ b/drivers/hid/hid-sensor-custom.c
@@ -371,7 +371,7 @@ static ssize_t show_value(struct device *dev, struct device_attribute *attr,
 				     sizeof(struct hid_custom_usage_desc),
 				     usage_id_cmp);
 		if (usage_desc)
-			return snprintf(buf, PAGE_SIZE, "%s\n",
+			return sysfs_emit(buf, "%s\n",
 					usage_desc->desc);
 		else
 			return sprintf(buf, "not-specified\n");
-- 
2.7.4


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

* [PATCH V2 5/5] hid-sony: replace snprintf in show functions with sysfs_emit
  2021-10-15 11:07 [PATCH V2 0/5] hid: replace snprintf in show functions with sysfs_emit Qing Wang
                   ` (3 preceding siblings ...)
  2021-10-15 11:07 ` [PATCH V2 4/5] hid-sensor: " Qing Wang
@ 2021-10-15 11:07 ` Qing Wang
  4 siblings, 0 replies; 8+ messages in thread
From: Qing Wang @ 2021-10-15 11:07 UTC (permalink / raw)
  To: Jiri Kosina, Benjamin Tissoires, Bruno Prémont,
	Stefan Achatz, Jonathan Cameron, Srinivas Pandruvada,
	linux-input, linux-kernel, linux-iio
  Cc: Qing Wang

show() should not use snprintf() when formatting the value to be returned 
to user space, snprintf() returns the length the resulting string and 
scnprintf() returns the number of bytes printed into the buffer.

Fix the coccicheck warnings:
WARNING: use scnprintf or sprintf.

Use sysfs_emit() instead of scnprintf() makes more sense.

Signed-off-by: Qing Wang <wangqing@vivo.com>
---
 drivers/hid/hid-sony.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c
index d1b107d..55423db 100644
--- a/drivers/hid/hid-sony.c
+++ b/drivers/hid/hid-sony.c
@@ -707,7 +707,7 @@ static ssize_t ds4_show_poll_interval(struct device *dev,
 	struct hid_device *hdev = to_hid_device(dev);
 	struct sony_sc *sc = hid_get_drvdata(hdev);
 
-	return snprintf(buf, PAGE_SIZE, "%i\n", sc->ds4_bt_poll_interval);
+	return sysfs_emit(buf, "%i\n", sc->ds4_bt_poll_interval);
 }
 
 static ssize_t ds4_store_poll_interval(struct device *dev,
@@ -744,7 +744,7 @@ static ssize_t sony_show_firmware_version(struct device *dev,
 	struct hid_device *hdev = to_hid_device(dev);
 	struct sony_sc *sc = hid_get_drvdata(hdev);
 
-	return snprintf(buf, PAGE_SIZE, "0x%04x\n", sc->fw_version);
+	return sysfs_emit(buf, "0x%04x\n", sc->fw_version);
 }
 
 static DEVICE_ATTR(firmware_version, 0444, sony_show_firmware_version, NULL);
@@ -756,7 +756,7 @@ static ssize_t sony_show_hardware_version(struct device *dev,
 	struct hid_device *hdev = to_hid_device(dev);
 	struct sony_sc *sc = hid_get_drvdata(hdev);
 
-	return snprintf(buf, PAGE_SIZE, "0x%04x\n", sc->hw_version);
+	return sysfs_emit(buf, "0x%04x\n", sc->hw_version);
 }
 
 static DEVICE_ATTR(hardware_version, 0444, sony_show_hardware_version, NULL);
-- 
2.7.4


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

* Re: [PATCH V2 4/5] hid-sensor: replace snprintf in show functions with sysfs_emit
  2021-10-15 11:07 ` [PATCH V2 4/5] hid-sensor: " Qing Wang
@ 2021-10-15 13:48   ` Jonathan Cameron
  0 siblings, 0 replies; 8+ messages in thread
From: Jonathan Cameron @ 2021-10-15 13:48 UTC (permalink / raw)
  To: Qing Wang
  Cc: Jiri Kosina, Benjamin Tissoires, Bruno Prémont,
	Stefan Achatz, Jonathan Cameron, Srinivas Pandruvada,
	linux-input, linux-kernel, linux-iio

On Fri, 15 Oct 2021 04:07:31 -0700
Qing Wang <wangqing@vivo.com> wrote:

> show() should not use snprintf() when formatting the value to be returned 
> to user space, snprintf() returns the length the resulting string and 
> scnprintf() returns the number of bytes printed into the buffer.
> 
> Fix the coccicheck warnings:
> WARNING: use scnprintf or sprintf.
> 
> Use sysfs_emit() instead of scnprintf() makes more sense.
> 
> Signed-off-by: Qing Wang <wangqing@vivo.com>
> ---
>  drivers/hid/hid-sensor-custom.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/hid/hid-sensor-custom.c b/drivers/hid/hid-sensor-custom.c
> index 32c2306..a46481d6 100644
> --- a/drivers/hid/hid-sensor-custom.c
> +++ b/drivers/hid/hid-sensor-custom.c
> @@ -371,7 +371,7 @@ static ssize_t show_value(struct device *dev, struct device_attribute *attr,
>  				     sizeof(struct hid_custom_usage_desc),
>  				     usage_id_cmp);
>  		if (usage_desc)
> -			return snprintf(buf, PAGE_SIZE, "%s\n",
> +			return sysfs_emit(buf, "%s\n",
>  					usage_desc->desc);

Now easily short enough that this can go on one line.

>  		else
>  			return sprintf(buf, "not-specified\n");
Whilst of course not necessary, it might be nicer to use sysfs_emit here as well for
consistency.

Otherwise looks good to me.

Jonathan


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

* Re: [PATCH V2 1/5] hid-lenovo: replace snprintf in show functions with sysfs_emit
  2021-10-15 11:07 ` [PATCH V2 1/5] hid-lenovo: " Qing Wang
@ 2021-10-15 13:51   ` Jonathan Cameron
  0 siblings, 0 replies; 8+ messages in thread
From: Jonathan Cameron @ 2021-10-15 13:51 UTC (permalink / raw)
  To: Qing Wang
  Cc: Jiri Kosina, Benjamin Tissoires, Bruno Prémont,
	Stefan Achatz, Jonathan Cameron, Srinivas Pandruvada,
	linux-input, linux-kernel, linux-iio

On Fri, 15 Oct 2021 04:07:28 -0700
Qing Wang <wangqing@vivo.com> wrote:

> show() should not use snprintf() when formatting the value to be returned 
> to user space, snprintf() returns the length the resulting string and 
> scnprintf() returns the number of bytes printed into the buffer.
> 
> Fix the coccicheck warnings:
> WARNING: use scnprintf or sprintf.
> 
> Use sysfs_emit() instead of scnprintf() makes more sense.
> 
> Signed-off-by: Qing Wang <wangqing@vivo.com>

Hi,

A few places where it makes sense to tidy up the line breaks.

The benefit of the change in general is fairly minor given none
of the cases here can cause problems, but I guess it is worthwhile
as warning suppression and general tidiness improvement.

Jonathan

> ---
>  drivers/hid/hid-lenovo.c | 16 ++++++++--------
>  1 file changed, 8 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/hid/hid-lenovo.c b/drivers/hid/hid-lenovo.c
> index 93b1f93..086a7ae 100644
> --- a/drivers/hid/hid-lenovo.c
> +++ b/drivers/hid/hid-lenovo.c
> @@ -400,7 +400,7 @@ static ssize_t attr_fn_lock_show(struct device *dev,
>  	struct hid_device *hdev = to_hid_device(dev);
>  	struct lenovo_drvdata *data = hid_get_drvdata(hdev);
>  
> -	return snprintf(buf, PAGE_SIZE, "%u\n", data->fn_lock);
> +	return sysfs_emit(buf, "%u\n", data->fn_lock);
>  }
>  
>  static ssize_t attr_fn_lock_store(struct device *dev,
> @@ -442,7 +442,7 @@ static ssize_t attr_sensitivity_show_cptkbd(struct device *dev,
>  	struct hid_device *hdev = to_hid_device(dev);
>  	struct lenovo_drvdata *cptkbd_data = hid_get_drvdata(hdev);
>  
> -	return snprintf(buf, PAGE_SIZE, "%u\n",
> +	return sysfs_emit(buf, "%u\n",
>  		cptkbd_data->sensitivity);

As below, whilst here tidy this up to be one line.

>  }
>  
> @@ -603,7 +603,7 @@ static ssize_t attr_press_to_select_show_tpkbd(struct device *dev,
>  	struct hid_device *hdev = to_hid_device(dev);
>  	struct lenovo_drvdata *data_pointer = hid_get_drvdata(hdev);
>  
> -	return snprintf(buf, PAGE_SIZE, "%u\n", data_pointer->press_to_select);
> +	return sysfs_emit(buf, "%u\n", data_pointer->press_to_select);
>  }
>  
>  static ssize_t attr_press_to_select_store_tpkbd(struct device *dev,
> @@ -633,7 +633,7 @@ static ssize_t attr_dragging_show_tpkbd(struct device *dev,
>  	struct hid_device *hdev = to_hid_device(dev);
>  	struct lenovo_drvdata *data_pointer = hid_get_drvdata(hdev);
>  
> -	return snprintf(buf, PAGE_SIZE, "%u\n", data_pointer->dragging);
> +	return sysfs_emit(buf, "%u\n", data_pointer->dragging);
>  }
>  
>  static ssize_t attr_dragging_store_tpkbd(struct device *dev,
> @@ -663,7 +663,7 @@ static ssize_t attr_release_to_select_show_tpkbd(struct device *dev,
>  	struct hid_device *hdev = to_hid_device(dev);
>  	struct lenovo_drvdata *data_pointer = hid_get_drvdata(hdev);
>  
> -	return snprintf(buf, PAGE_SIZE, "%u\n", data_pointer->release_to_select);
> +	return sysfs_emit(buf, "%u\n", data_pointer->release_to_select);
>  }
>  
>  static ssize_t attr_release_to_select_store_tpkbd(struct device *dev,
> @@ -693,7 +693,7 @@ static ssize_t attr_select_right_show_tpkbd(struct device *dev,
>  	struct hid_device *hdev = to_hid_device(dev);
>  	struct lenovo_drvdata *data_pointer = hid_get_drvdata(hdev);
>  
> -	return snprintf(buf, PAGE_SIZE, "%u\n", data_pointer->select_right);
> +	return sysfs_emit(buf, "%u\n", data_pointer->select_right);
>  }
>  
>  static ssize_t attr_select_right_store_tpkbd(struct device *dev,
> @@ -723,7 +723,7 @@ static ssize_t attr_sensitivity_show_tpkbd(struct device *dev,
>  	struct hid_device *hdev = to_hid_device(dev);
>  	struct lenovo_drvdata *data_pointer = hid_get_drvdata(hdev);
>  
> -	return snprintf(buf, PAGE_SIZE, "%u\n",
> +	return sysfs_emit(buf, "%u\n",
>  		data_pointer->sensitivity);
Perhaps put this on one line?  It fit before the change of course, but
as you are touching the code, might as well tidy that up.

>  }
>  
> @@ -752,7 +752,7 @@ static ssize_t attr_press_speed_show_tpkbd(struct device *dev,
>  	struct hid_device *hdev = to_hid_device(dev);
>  	struct lenovo_drvdata *data_pointer = hid_get_drvdata(hdev);
>  
> -	return snprintf(buf, PAGE_SIZE, "%u\n",
> +	return sysfs_emit(buf, "%u\n",
>  		data_pointer->press_speed);
Same here.

Thanks,

Jonathan

>  }
>  


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

end of thread, other threads:[~2021-10-15 13:52 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-15 11:07 [PATCH V2 0/5] hid: replace snprintf in show functions with sysfs_emit Qing Wang
2021-10-15 11:07 ` [PATCH V2 1/5] hid-lenovo: " Qing Wang
2021-10-15 13:51   ` Jonathan Cameron
2021-10-15 11:07 ` [PATCH V2 2/5] hid-picolcd: " Qing Wang
2021-10-15 11:07 ` [PATCH V2 3/5] hid-roccat: " Qing Wang
2021-10-15 11:07 ` [PATCH V2 4/5] hid-sensor: " Qing Wang
2021-10-15 13:48   ` Jonathan Cameron
2021-10-15 11:07 ` [PATCH V2 5/5] hid-sony: " Qing Wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).