Skip to contentSkip to conversation

soundwire: sysfs_emit() expects a buffer of size PAGE_SIZE

PATCH In review Sergio Perez Gonzalez 3 participants 4 messages Jul 23, 2025 – Jul 25, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 soundwire: sysfs_emit() expects a buffer of size PAGE_SIZE

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

Fixes 35323d8ab811 ("soundwire: replace scnprintf() with sysfs_emit() for sysfs consistency")
---
 drivers/soundwire/debugfs.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/soundwire/debugfs.c +3 -3
index 825f7abbad32..08fb1e29026e 100644
@@ -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;
Signature · 1 line
2.43.0
#1 lore raw
Quoted 18 lines · Sergio Perez Gonzalez

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

Fixes 35323d8ab811 ("soundwire: replace scnprintf() with sysfs_emit() for sysfs consistency")
---
 drivers/soundwire/debugfs.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/soundwire/debugfs.c +0 -0
index 825f7abbad32..08fb1e29026e 100644
@@ -306,12 +306,12 @@ static int cmd_go(void *data, u64 value)
 DEFINE_DEBUGFS_ATTRIBUTE(cmd_go_fops, NULL,
 			 cmd_go, "%llu\n");

drivers/soundwire/debugfs.c static int cmd_go(void *data, u64 value) · line 314

Quoted 10 lines
drivers/soundwire/debugfs.c +3 -3
 
-#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

maintainer
#2 lore raw
Quoted 35 lines · Takashi Iwai
Quoted 18 lines · Sergio Perez Gonzalez

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

Fixes 35323d8ab811 ("soundwire: replace scnprintf() with sysfs_emit() for sysfs consistency")
---
 drivers/soundwire/debugfs.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/soundwire/debugfs.c +0 -0
index 825f7abbad32..08fb1e29026e 100644
@@ -306,12 +306,12 @@ static int cmd_go(void *data, u64 value)
 DEFINE_DEBUGFS_ATTRIBUTE(cmd_go_fops, NULL,
 			 cmd_go, "%llu\n");

drivers/soundwire/debugfs.c static int cmd_go(void *data, u64 value) · line 314

Quoted 10 lines
drivers/soundwire/debugfs.c +3 -3
 
-#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.

Quoted 4 lines

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!

Signature · 1 line
~Vinod
#3 lore raw

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

Thanks,
Sergio

Quoted 46 lines · Vinod Koul
Quoted 35 lines · Takashi Iwai
Quoted 18 lines · Sergio Perez Gonzalez

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

Fixes 35323d8ab811 ("soundwire: replace scnprintf() with sysfs_emit() for sysfs consistency")
---
 drivers/soundwire/debugfs.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/soundwire/debugfs.c +0 -0
index 825f7abbad32..08fb1e29026e 100644
@@ -306,12 +306,12 @@ static int cmd_go(void *data, u64 value)
 DEFINE_DEBUGFS_ATTRIBUTE(cmd_go_fops, NULL,
                     cmd_go, "%llu\n");

drivers/soundwire/debugfs.c static int cmd_go(void *data, u64 value) · line 314

Quoted 10 lines
drivers/soundwire/debugfs.c +3 -3
 
-#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.

Quoted 4 lines

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