mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] soundwire: sysfs_emit() expects a buffer of size PAGE_SIZE
@ 2025-07-23 23:09 Sergio Perez Gonzalez
  2025-07-24  7:19 ` Takashi Iwai
  0 siblings, 1 reply; 4+ messages in thread
From: Sergio Perez Gonzalez @ 2025-07-23 23:09 UTC (permalink / raw)
  To: vkoul, yung-chuan.liao
  Cc: Sergio Perez Gonzalez, pierre-louis.bossart, linux-sound, linux-kernel

In read_buffer_show(), allocate sufficient memory to pass on to
sysfs_emit(), which expects a buffer of size PAGE_SIZE.

Link: https://scan7.scan.coverity.com/#/project-view/53936/11354?selectedIssue=1648019
Fixes: 35323d8ab811 ("soundwire: replace scnprintf() with sysfs_emit() for sysfs consistency")
Signed-off-by: Sergio Perez Gonzalez <sperezglz@gmail.com>
---
 drivers/soundwire/debugfs.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/soundwire/debugfs.c b/drivers/soundwire/debugfs.c
index 825f7abbad32..08fb1e29026e 100644
--- a/drivers/soundwire/debugfs.c
+++ b/drivers/soundwire/debugfs.c
@@ -306,12 +306,12 @@ static int cmd_go(void *data, u64 value)
 DEFINE_DEBUGFS_ATTRIBUTE(cmd_go_fops, NULL,
 			 cmd_go, "%llu\n");
 
-#define MAX_LINE_LEN 128
-
 static int read_buffer_show(struct seq_file *s_file, void *data)
 {
-	char buf[MAX_LINE_LEN];
 	int i;
+	char *buf __free(kfree) = kzalloc(PAGE_SIZE, GFP_KERNEL);
+	if (!buf)
+		return -ENOMEM;
 
 	if (num_bytes == 0 || num_bytes > MAX_CMD_BYTES)
 		return -EINVAL;
-- 
2.43.0


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

* Re: [PATCH] soundwire: sysfs_emit() expects a buffer of size PAGE_SIZE
  2025-07-23 23:09 [PATCH] soundwire: sysfs_emit() expects a buffer of size PAGE_SIZE Sergio Perez Gonzalez
@ 2025-07-24  7:19 ` Takashi Iwai
  2025-07-24  9:52   ` Vinod Koul
  0 siblings, 1 reply; 4+ messages in thread
From: Takashi Iwai @ 2025-07-24  7:19 UTC (permalink / raw)
  To: Sergio Perez Gonzalez
  Cc: vkoul, yung-chuan.liao, pierre-louis.bossart, linux-sound, linux-kernel

On Thu, 24 Jul 2025 01:09:25 +0200,
Sergio Perez Gonzalez wrote:
> 
> In read_buffer_show(), allocate sufficient memory to pass on to
> sysfs_emit(), which expects a buffer of size PAGE_SIZE.
> 
> Link: https://scan7.scan.coverity.com/#/project-view/53936/11354?selectedIssue=1648019
> Fixes: 35323d8ab811 ("soundwire: replace scnprintf() with sysfs_emit() for sysfs consistency")
> Signed-off-by: Sergio Perez Gonzalez <sperezglz@gmail.com>
> ---
>  drivers/soundwire/debugfs.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/soundwire/debugfs.c b/drivers/soundwire/debugfs.c
> index 825f7abbad32..08fb1e29026e 100644
> --- a/drivers/soundwire/debugfs.c
> +++ b/drivers/soundwire/debugfs.c
> @@ -306,12 +306,12 @@ static int cmd_go(void *data, u64 value)
>  DEFINE_DEBUGFS_ATTRIBUTE(cmd_go_fops, NULL,
>  			 cmd_go, "%llu\n");
>  
> -#define MAX_LINE_LEN 128
> -
>  static int read_buffer_show(struct seq_file *s_file, void *data)
>  {
> -	char buf[MAX_LINE_LEN];
>  	int i;
> +	char *buf __free(kfree) = kzalloc(PAGE_SIZE, GFP_KERNEL);
> +	if (!buf)
> +		return -ENOMEM;

IMO, it's better to scratch the whole previous change.
It makes little sense to allocate a large buffer here just for the
temporary formatting.

Moreover, *_show() functions there take seq_file pointer, and you can
just use seq_printf() directly.  The sysfs/kobject show callback is
with the a fixed PAGE_SIZE buffer, hence sysfs_emit() is useful, but
in this case, it's a completely different story.


thanks,

Takashi

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

* Re: [PATCH] soundwire: sysfs_emit() expects a buffer of size PAGE_SIZE
  2025-07-24  7:19 ` Takashi Iwai
@ 2025-07-24  9:52   ` Vinod Koul
  2025-07-25 18:22     ` Sergio Pérez
  0 siblings, 1 reply; 4+ messages in thread
From: Vinod Koul @ 2025-07-24  9:52 UTC (permalink / raw)
  To: Takashi Iwai
  Cc: Sergio Perez Gonzalez, yung-chuan.liao, pierre-louis.bossart,
	linux-sound, linux-kernel

On 24-07-25, 09:19, Takashi Iwai wrote:
> On Thu, 24 Jul 2025 01:09:25 +0200,
> Sergio Perez Gonzalez wrote:
> > 
> > In read_buffer_show(), allocate sufficient memory to pass on to
> > sysfs_emit(), which expects a buffer of size PAGE_SIZE.
> > 
> > Link: https://scan7.scan.coverity.com/#/project-view/53936/11354?selectedIssue=1648019
> > Fixes: 35323d8ab811 ("soundwire: replace scnprintf() with sysfs_emit() for sysfs consistency")
> > Signed-off-by: Sergio Perez Gonzalez <sperezglz@gmail.com>
> > ---
> >  drivers/soundwire/debugfs.c | 6 +++---
> >  1 file changed, 3 insertions(+), 3 deletions(-)
> > 
> > diff --git a/drivers/soundwire/debugfs.c b/drivers/soundwire/debugfs.c
> > index 825f7abbad32..08fb1e29026e 100644
> > --- a/drivers/soundwire/debugfs.c
> > +++ b/drivers/soundwire/debugfs.c
> > @@ -306,12 +306,12 @@ static int cmd_go(void *data, u64 value)
> >  DEFINE_DEBUGFS_ATTRIBUTE(cmd_go_fops, NULL,
> >  			 cmd_go, "%llu\n");
> >  
> > -#define MAX_LINE_LEN 128
> > -
> >  static int read_buffer_show(struct seq_file *s_file, void *data)
> >  {
> > -	char buf[MAX_LINE_LEN];
> >  	int i;
> > +	char *buf __free(kfree) = kzalloc(PAGE_SIZE, GFP_KERNEL);
> > +	if (!buf)
> > +		return -ENOMEM;
> 
> IMO, it's better to scratch the whole previous change.
> It makes little sense to allocate a large buffer here just for the
> temporary formatting.
> 
> Moreover, *_show() functions there take seq_file pointer, and you can
> just use seq_printf() directly.  The sysfs/kobject show callback is
> with the a fixed PAGE_SIZE buffer, hence sysfs_emit() is useful, but
> in this case, it's a completely different story.

Agree, dropped now!

-- 
~Vinod

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

* Re: [PATCH] soundwire: sysfs_emit() expects a buffer of size PAGE_SIZE
  2025-07-24  9:52   ` Vinod Koul
@ 2025-07-25 18:22     ` Sergio Pérez
  0 siblings, 0 replies; 4+ messages in thread
From: Sergio Pérez @ 2025-07-25 18:22 UTC (permalink / raw)
  To: Vinod Koul
  Cc: Takashi Iwai, yung-chuan.liao, pierre-louis.bossart, linux-sound,
	linux-kernel

All right, then, this will be handled with a different approach.

Thanks,
Sergio

El jue, 24 jul 2025 a la(s) 3:52 a.m., Vinod Koul (vkoul@kernel.org) escribió:
>
> On 24-07-25, 09:19, Takashi Iwai wrote:
> > On Thu, 24 Jul 2025 01:09:25 +0200,
> > Sergio Perez Gonzalez wrote:
> > >
> > > In read_buffer_show(), allocate sufficient memory to pass on to
> > > sysfs_emit(), which expects a buffer of size PAGE_SIZE.
> > >
> > > Link: https://scan7.scan.coverity.com/#/project-view/53936/11354?selectedIssue=1648019
> > > Fixes: 35323d8ab811 ("soundwire: replace scnprintf() with sysfs_emit() for sysfs consistency")
> > > Signed-off-by: Sergio Perez Gonzalez <sperezglz@gmail.com>
> > > ---
> > >  drivers/soundwire/debugfs.c | 6 +++---
> > >  1 file changed, 3 insertions(+), 3 deletions(-)
> > >
> > > diff --git a/drivers/soundwire/debugfs.c b/drivers/soundwire/debugfs.c
> > > index 825f7abbad32..08fb1e29026e 100644
> > > --- a/drivers/soundwire/debugfs.c
> > > +++ b/drivers/soundwire/debugfs.c
> > > @@ -306,12 +306,12 @@ static int cmd_go(void *data, u64 value)
> > >  DEFINE_DEBUGFS_ATTRIBUTE(cmd_go_fops, NULL,
> > >                      cmd_go, "%llu\n");
> > >
> > > -#define MAX_LINE_LEN 128
> > > -
> > >  static int read_buffer_show(struct seq_file *s_file, void *data)
> > >  {
> > > -   char buf[MAX_LINE_LEN];
> > >     int i;
> > > +   char *buf __free(kfree) = kzalloc(PAGE_SIZE, GFP_KERNEL);
> > > +   if (!buf)
> > > +           return -ENOMEM;
> >
> > IMO, it's better to scratch the whole previous change.
> > It makes little sense to allocate a large buffer here just for the
> > temporary formatting.
> >
> > Moreover, *_show() functions there take seq_file pointer, and you can
> > just use seq_printf() directly.  The sysfs/kobject show callback is
> > with the a fixed PAGE_SIZE buffer, hence sysfs_emit() is useful, but
> > in this case, it's a completely different story.
>
> Agree, dropped now!
>
> --
> ~Vinod

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

end of thread, other threads:[~2025-07-25 18:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-07-23 23:09 [PATCH] soundwire: sysfs_emit() expects a buffer of size PAGE_SIZE Sergio Perez Gonzalez
2025-07-24  7:19 ` Takashi Iwai
2025-07-24  9:52   ` Vinod Koul
2025-07-25 18:22     ` Sergio Pérez

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

all inboxes | Powered by JetHome®