Linux USB
 help / color / mirror / Atom feed
* [PATCH 0/2] usb: gadget: Use sysfs_emit instead of sprintf
@ 2026-01-31 16:01 Krishna Kurapati
  2026-01-31 16:01 ` [PATCH 1/2] usb: gadget: f_fs: Use sysfs_emit() in configfs show function Krishna Kurapati
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Krishna Kurapati @ 2026-01-31 16:01 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Al Viro, Sam Day, Christian Brauner, Chen Ni,
	Mateusz Guzik, Liang Jie, Ingo Rohloff, Owen Gu,
	Christophe JAILLET
  Cc: linux-usb, linux-kernel, Krishna Kurapati

Use sysfs_emit() instead of sprintf() in configfs attribute show functions.
sysfs_emit() is the recommended API for sysfs output as it provides buffer
overflow protection and proper formatting.

Krishna Kurapati (2):
  usb: gadget: f_fs: Use sysfs_emit() in configfs show function
  usb: gadget: f_sourcesink: Use sysfs_emit() in configfs show functions

 drivers/usb/gadget/function/f_fs.c         |  2 +-
 drivers/usb/gadget/function/f_sourcesink.c | 16 ++++++++--------
 2 files changed, 9 insertions(+), 9 deletions(-)

-- 
2.34.1


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

* [PATCH 1/2] usb: gadget: f_fs: Use sysfs_emit() in configfs show function
  2026-01-31 16:01 [PATCH 0/2] usb: gadget: Use sysfs_emit instead of sprintf Krishna Kurapati
@ 2026-01-31 16:01 ` Krishna Kurapati
  2026-01-31 16:01 ` [PATCH 2/2] usb: gadget: f_sourcesink: Use sysfs_emit() in configfs show functions Krishna Kurapati
  2026-02-01  7:28 ` [PATCH 0/2] usb: gadget: Use sysfs_emit instead of sprintf Greg Kroah-Hartman
  2 siblings, 0 replies; 6+ messages in thread
From: Krishna Kurapati @ 2026-01-31 16:01 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Al Viro, Sam Day, Christian Brauner, Chen Ni,
	Mateusz Guzik, Liang Jie, Ingo Rohloff, Owen Gu,
	Christophe JAILLET
  Cc: linux-usb, linux-kernel, Krishna Kurapati

Use sysfs_emit() instead of sprintf() in configfs attribute show function.
sysfs_emit() is the recommended API for sysfs output as it provides buffer
overflow protection and proper formatting.

No functional changes.

Signed-off-by: Krishna Kurapati <krishna.kurapati@oss.qualcomm.com>
---
 drivers/usb/gadget/function/f_fs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c
index c1826aa2f0f8..80dd42a7f391 100644
--- a/drivers/usb/gadget/function/f_fs.c
+++ b/drivers/usb/gadget/function/f_fs.c
@@ -3981,7 +3981,7 @@ static ssize_t f_fs_opts_ready_show(struct config_item *item, char *page)
 	ready = opts->dev->desc_ready;
 	ffs_dev_unlock();
 
-	return sprintf(page, "%d\n", ready);
+	return sysfs_emit(page, "%d\n", ready);
 }
 
 CONFIGFS_ATTR_RO(f_fs_opts_, ready);
-- 
2.34.1


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

* [PATCH 2/2] usb: gadget: f_sourcesink: Use sysfs_emit() in configfs show functions
  2026-01-31 16:01 [PATCH 0/2] usb: gadget: Use sysfs_emit instead of sprintf Krishna Kurapati
  2026-01-31 16:01 ` [PATCH 1/2] usb: gadget: f_fs: Use sysfs_emit() in configfs show function Krishna Kurapati
@ 2026-01-31 16:01 ` Krishna Kurapati
  2026-02-01  7:28 ` [PATCH 0/2] usb: gadget: Use sysfs_emit instead of sprintf Greg Kroah-Hartman
  2 siblings, 0 replies; 6+ messages in thread
From: Krishna Kurapati @ 2026-01-31 16:01 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Al Viro, Sam Day, Christian Brauner, Chen Ni,
	Mateusz Guzik, Liang Jie, Ingo Rohloff, Owen Gu,
	Christophe JAILLET
  Cc: linux-usb, linux-kernel, Krishna Kurapati

Use sysfs_emit() instead of sprintf() in configfs attribute show functions.
sysfs_emit() is the recommended API for sysfs output as it provides buffer
overflow protection and proper formatting.

No functional changes.

Signed-off-by: Krishna Kurapati <krishna.kurapati@oss.qualcomm.com>
---
 drivers/usb/gadget/function/f_sourcesink.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/usb/gadget/function/f_sourcesink.c b/drivers/usb/gadget/function/f_sourcesink.c
index 22104e9c6cab..e6ca80dba7c8 100644
--- a/drivers/usb/gadget/function/f_sourcesink.c
+++ b/drivers/usb/gadget/function/f_sourcesink.c
@@ -900,7 +900,7 @@ static ssize_t f_ss_opts_pattern_show(struct config_item *item, char *page)
 	int result;
 
 	mutex_lock(&opts->lock);
-	result = sprintf(page, "%u\n", opts->pattern);
+	result = sysfs_emit(page, "%u\n", opts->pattern);
 	mutex_unlock(&opts->lock);
 
 	return result;
@@ -943,7 +943,7 @@ static ssize_t f_ss_opts_isoc_interval_show(struct config_item *item, char *page
 	int result;
 
 	mutex_lock(&opts->lock);
-	result = sprintf(page, "%u\n", opts->isoc_interval);
+	result = sysfs_emit(page, "%u\n", opts->isoc_interval);
 	mutex_unlock(&opts->lock);
 
 	return result;
@@ -986,7 +986,7 @@ static ssize_t f_ss_opts_isoc_maxpacket_show(struct config_item *item, char *pag
 	int result;
 
 	mutex_lock(&opts->lock);
-	result = sprintf(page, "%u\n", opts->isoc_maxpacket);
+	result = sysfs_emit(page, "%u\n", opts->isoc_maxpacket);
 	mutex_unlock(&opts->lock);
 
 	return result;
@@ -1029,7 +1029,7 @@ static ssize_t f_ss_opts_isoc_mult_show(struct config_item *item, char *page)
 	int result;
 
 	mutex_lock(&opts->lock);
-	result = sprintf(page, "%u\n", opts->isoc_mult);
+	result = sysfs_emit(page, "%u\n", opts->isoc_mult);
 	mutex_unlock(&opts->lock);
 
 	return result;
@@ -1072,7 +1072,7 @@ static ssize_t f_ss_opts_isoc_maxburst_show(struct config_item *item, char *page
 	int result;
 
 	mutex_lock(&opts->lock);
-	result = sprintf(page, "%u\n", opts->isoc_maxburst);
+	result = sysfs_emit(page, "%u\n", opts->isoc_maxburst);
 	mutex_unlock(&opts->lock);
 
 	return result;
@@ -1158,7 +1158,7 @@ static ssize_t f_ss_opts_bulk_buflen_show(struct config_item *item, char *page)
 	int result;
 
 	mutex_lock(&opts->lock);
-	result = sprintf(page, "%u\n", opts->bulk_buflen);
+	result = sysfs_emit(page, "%u\n", opts->bulk_buflen);
 	mutex_unlock(&opts->lock);
 
 	return result;
@@ -1196,7 +1196,7 @@ static ssize_t f_ss_opts_bulk_qlen_show(struct config_item *item, char *page)
 	int result;
 
 	mutex_lock(&opts->lock);
-	result = sprintf(page, "%u\n", opts->bulk_qlen);
+	result = sysfs_emit(page, "%u\n", opts->bulk_qlen);
 	mutex_unlock(&opts->lock);
 
 	return result;
@@ -1234,7 +1234,7 @@ static ssize_t f_ss_opts_iso_qlen_show(struct config_item *item, char *page)
 	int result;
 
 	mutex_lock(&opts->lock);
-	result = sprintf(page, "%u\n", opts->iso_qlen);
+	result = sysfs_emit(page, "%u\n", opts->iso_qlen);
 	mutex_unlock(&opts->lock);
 
 	return result;
-- 
2.34.1


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

* Re: [PATCH 0/2] usb: gadget: Use sysfs_emit instead of sprintf
  2026-01-31 16:01 [PATCH 0/2] usb: gadget: Use sysfs_emit instead of sprintf Krishna Kurapati
  2026-01-31 16:01 ` [PATCH 1/2] usb: gadget: f_fs: Use sysfs_emit() in configfs show function Krishna Kurapati
  2026-01-31 16:01 ` [PATCH 2/2] usb: gadget: f_sourcesink: Use sysfs_emit() in configfs show functions Krishna Kurapati
@ 2026-02-01  7:28 ` Greg Kroah-Hartman
  2026-02-01 10:31   ` Krishna Kurapati
  2 siblings, 1 reply; 6+ messages in thread
From: Greg Kroah-Hartman @ 2026-02-01  7:28 UTC (permalink / raw)
  To: Krishna Kurapati
  Cc: Al Viro, Sam Day, Christian Brauner, Chen Ni, Mateusz Guzik,
	Liang Jie, Ingo Rohloff, Owen Gu, Christophe JAILLET, linux-usb,
	linux-kernel

On Sat, Jan 31, 2026 at 09:31:09PM +0530, Krishna Kurapati wrote:
> Use sysfs_emit() instead of sprintf() in configfs attribute show functions.
> sysfs_emit() is the recommended API for sysfs output as it provides buffer
> overflow protection and proper formatting.

But this isn't sysfs, as you say, it's configfs, so why switch?  If
there is no need, the churn is not required.

thanks,

greg k-h

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

* Re: [PATCH 0/2] usb: gadget: Use sysfs_emit instead of sprintf
  2026-02-01  7:28 ` [PATCH 0/2] usb: gadget: Use sysfs_emit instead of sprintf Greg Kroah-Hartman
@ 2026-02-01 10:31   ` Krishna Kurapati
  2026-02-01 10:35     ` Greg Kroah-Hartman
  0 siblings, 1 reply; 6+ messages in thread
From: Krishna Kurapati @ 2026-02-01 10:31 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Al Viro, Sam Day, Christian Brauner, Chen Ni, Mateusz Guzik,
	Liang Jie, Ingo Rohloff, Owen Gu, Christophe JAILLET, linux-usb,
	linux-kernel



On 2/1/2026 12:58 PM, Greg Kroah-Hartman wrote:
> On Sat, Jan 31, 2026 at 09:31:09PM +0530, Krishna Kurapati wrote:
>> Use sysfs_emit() instead of sprintf() in configfs attribute show functions.
>> sysfs_emit() is the recommended API for sysfs output as it provides buffer
>> overflow protection and proper formatting.
> 
> But this isn't sysfs, as you say, it's configfs, so why switch?  If
> there is no need, the churn is not required.
> 

My bad. Its for configfs. I see sysfs_emit being used in configfs show 
functions in f_ncm/u_ether_configfs.h and hence tried to move to the 
same in f_fs and source sink.

Regards,
Krishna,

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

* Re: [PATCH 0/2] usb: gadget: Use sysfs_emit instead of sprintf
  2026-02-01 10:31   ` Krishna Kurapati
@ 2026-02-01 10:35     ` Greg Kroah-Hartman
  0 siblings, 0 replies; 6+ messages in thread
From: Greg Kroah-Hartman @ 2026-02-01 10:35 UTC (permalink / raw)
  To: Krishna Kurapati
  Cc: Al Viro, Sam Day, Christian Brauner, Chen Ni, Mateusz Guzik,
	Liang Jie, Ingo Rohloff, Owen Gu, Christophe JAILLET, linux-usb,
	linux-kernel

On Sun, Feb 01, 2026 at 04:01:46PM +0530, Krishna Kurapati wrote:
> 
> 
> On 2/1/2026 12:58 PM, Greg Kroah-Hartman wrote:
> > On Sat, Jan 31, 2026 at 09:31:09PM +0530, Krishna Kurapati wrote:
> > > Use sysfs_emit() instead of sprintf() in configfs attribute show functions.
> > > sysfs_emit() is the recommended API for sysfs output as it provides buffer
> > > overflow protection and proper formatting.
> > 
> > But this isn't sysfs, as you say, it's configfs, so why switch?  If
> > there is no need, the churn is not required.
> > 
> 
> My bad. Its for configfs. I see sysfs_emit being used in configfs show
> functions in f_ncm/u_ether_configfs.h and hence tried to move to the same in
> f_fs and source sink.

You can use it, sure, but there's no need to convert existing code
unless there is a real reason it is required.  Just use it for new code
please.

thanks,

greg k-h

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

end of thread, other threads:[~2026-02-01 10:35 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-31 16:01 [PATCH 0/2] usb: gadget: Use sysfs_emit instead of sprintf Krishna Kurapati
2026-01-31 16:01 ` [PATCH 1/2] usb: gadget: f_fs: Use sysfs_emit() in configfs show function Krishna Kurapati
2026-01-31 16:01 ` [PATCH 2/2] usb: gadget: f_sourcesink: Use sysfs_emit() in configfs show functions Krishna Kurapati
2026-02-01  7:28 ` [PATCH 0/2] usb: gadget: Use sysfs_emit instead of sprintf Greg Kroah-Hartman
2026-02-01 10:31   ` Krishna Kurapati
2026-02-01 10:35     ` Greg Kroah-Hartman

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