public inbox for linux-kernel-mentees@lists.linux-foundation.org
 help / color / mirror / Atom feed
* [PATCH] HID: ft260: Use sysfs_emit to write formatted data to user buffer in sysfs show function.
@ 2025-09-23 14:49 Bhanu Seshu Kumar Valluri
  2025-09-23 14:56 ` Greg KH
  0 siblings, 1 reply; 3+ messages in thread
From: Bhanu Seshu Kumar Valluri @ 2025-09-23 14:49 UTC (permalink / raw)
  To: Michael Zaidman, Jiri Kosina, Benjamin Tissoires
  Cc: bhanuseshukumar, linux-i2c, linux-input, linux-kernel, skhan,
	linux-kernel-mentees

Inline with sysfs documentation, sysfs_emit is used in show function
to write formatted data into user buffer. sysfs_emit is already PAGE_SIZE
aware.

Signed-off-by: Bhanu Seshu Kumar Valluri <bhanuseshukumar@gmail.com>
---
 Note: Patch is compile tested and verified with checkpatch.

 drivers/hid/hid-ft260.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/hid/hid-ft260.c b/drivers/hid/hid-ft260.c
index 333341e80b0e..8677bea46bea 100644
--- a/drivers/hid/hid-ft260.c
+++ b/drivers/hid/hid-ft260.c
@@ -826,7 +826,7 @@ static int ft260_byte_show(struct hid_device *hdev, int id, u8 *cfg, int len,
 	if (ret < 0)
 		return ret;
 
-	return scnprintf(buf, PAGE_SIZE, "%d\n", *field);
+	return sysfs_emit(buf, "%d\n", *field);
 }
 
 static int ft260_word_show(struct hid_device *hdev, int id, u8 *cfg, int len,
@@ -838,7 +838,7 @@ static int ft260_word_show(struct hid_device *hdev, int id, u8 *cfg, int len,
 	if (ret < 0)
 		return ret;
 
-	return scnprintf(buf, PAGE_SIZE, "%d\n", le16_to_cpu(*field));
+	return sysfs_emit(buf, "%d\n", le16_to_cpu(*field));
 }
 
 #define FT260_ATTR_SHOW(name, reptype, id, type, func)			       \
-- 
2.34.1


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

* Re: [PATCH] HID: ft260: Use sysfs_emit to write formatted data to user buffer in sysfs show function.
  2025-09-23 14:49 [PATCH] HID: ft260: Use sysfs_emit to write formatted data to user buffer in sysfs show function Bhanu Seshu Kumar Valluri
@ 2025-09-23 14:56 ` Greg KH
  2025-09-23 14:58   ` bhanuseshukumar
  0 siblings, 1 reply; 3+ messages in thread
From: Greg KH @ 2025-09-23 14:56 UTC (permalink / raw)
  To: Bhanu Seshu Kumar Valluri
  Cc: Michael Zaidman, Jiri Kosina, Benjamin Tissoires, linux-i2c,
	linux-input, linux-kernel, skhan, linux-kernel-mentees

On Tue, Sep 23, 2025 at 08:19:26PM +0530, Bhanu Seshu Kumar Valluri wrote:
> Inline with sysfs documentation, sysfs_emit is used in show function
> to write formatted data into user buffer. sysfs_emit is already PAGE_SIZE
> aware.
> 
> Signed-off-by: Bhanu Seshu Kumar Valluri <bhanuseshukumar@gmail.com>
> ---
>  Note: Patch is compile tested and verified with checkpatch.
> 
>  drivers/hid/hid-ft260.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/hid/hid-ft260.c b/drivers/hid/hid-ft260.c
> index 333341e80b0e..8677bea46bea 100644
> --- a/drivers/hid/hid-ft260.c
> +++ b/drivers/hid/hid-ft260.c
> @@ -826,7 +826,7 @@ static int ft260_byte_show(struct hid_device *hdev, int id, u8 *cfg, int len,
>  	if (ret < 0)
>  		return ret;
>  
> -	return scnprintf(buf, PAGE_SIZE, "%d\n", *field);
> +	return sysfs_emit(buf, "%d\n", *field);
>  }
>  
>  static int ft260_word_show(struct hid_device *hdev, int id, u8 *cfg, int len,
> @@ -838,7 +838,7 @@ static int ft260_word_show(struct hid_device *hdev, int id, u8 *cfg, int len,
>  	if (ret < 0)
>  		return ret;
>  
> -	return scnprintf(buf, PAGE_SIZE, "%d\n", le16_to_cpu(*field));
> +	return sysfs_emit(buf, "%d\n", le16_to_cpu(*field));

There's no need to change existing users in the kernel for stuff like
this, only try to do this for new sysfs files.  We've had too many bugs
where "simple" changes like this cause problems (recently in the USB
core for example.)

thanks,

greg k-h

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

* Re: [PATCH] HID: ft260: Use sysfs_emit to write formatted data to user buffer in sysfs show function.
  2025-09-23 14:56 ` Greg KH
@ 2025-09-23 14:58   ` bhanuseshukumar
  0 siblings, 0 replies; 3+ messages in thread
From: bhanuseshukumar @ 2025-09-23 14:58 UTC (permalink / raw)
  To: Greg KH
  Cc: Michael Zaidman, Jiri Kosina, Benjamin Tissoires, linux-i2c,
	linux-input, linux-kernel, skhan, linux-kernel-mentees

On 23/09/25 20:26, Greg KH wrote:
> On Tue, Sep 23, 2025 at 08:19:26PM +0530, Bhanu Seshu Kumar Valluri wrote:
>> Inline with sysfs documentation, sysfs_emit is used in show function
>> to write formatted data into user buffer. sysfs_emit is already PAGE_SIZE
>> aware.
>>
>> Signed-off-by: Bhanu Seshu Kumar Valluri <bhanuseshukumar@gmail.com>
>> ---
>>  Note: Patch is compile tested and verified with checkpatch.
>>
>>  drivers/hid/hid-ft260.c | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/hid/hid-ft260.c b/drivers/hid/hid-ft260.c
>> index 333341e80b0e..8677bea46bea 100644
>> --- a/drivers/hid/hid-ft260.c
>> +++ b/drivers/hid/hid-ft260.c
>> @@ -826,7 +826,7 @@ static int ft260_byte_show(struct hid_device *hdev, int id, u8 *cfg, int len,
>>  	if (ret < 0)
>>  		return ret;
>>  
>> -	return scnprintf(buf, PAGE_SIZE, "%d\n", *field);
>> +	return sysfs_emit(buf, "%d\n", *field);
>>  }
>>  
>>  static int ft260_word_show(struct hid_device *hdev, int id, u8 *cfg, int len,
>> @@ -838,7 +838,7 @@ static int ft260_word_show(struct hid_device *hdev, int id, u8 *cfg, int len,
>>  	if (ret < 0)
>>  		return ret;
>>  
>> -	return scnprintf(buf, PAGE_SIZE, "%d\n", le16_to_cpu(*field));
>> +	return sysfs_emit(buf, "%d\n", le16_to_cpu(*field));
> 
> There's no need to change existing users in the kernel for stuff like
> this, only try to do this for new sysfs files.  We've had too many bugs
> where "simple" changes like this cause problems (recently in the USB
> core for example.)
> 
> thanks,
> 
> greg k-h

OK. Thanks for the prompt feedback on this. 

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

end of thread, other threads:[~2025-09-23 14:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-23 14:49 [PATCH] HID: ft260: Use sysfs_emit to write formatted data to user buffer in sysfs show function Bhanu Seshu Kumar Valluri
2025-09-23 14:56 ` Greg KH
2025-09-23 14:58   ` bhanuseshukumar

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