Skip to contentSkip to conversation

drm/nouveau/debugfs: Simplify character output in nouveau_debugfs_vbios_image()

PATCH Superseded Markus Elfring 3 participants 6 messages Jul 15, 2024 – Jul 24, 2024

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

PATCH 1/1 drm/nouveau/debugfs: Simplify character output in nouveau_debugfs_vbios_image()

From: Markus Elfring <[email protected]>
Date: Mon, 15 Jul 2024 13:36:54 +0200

Single characters should be put into a sequence.
Thus use the corresponding function “seq_putc” for one selected call.

This issue was transformed by using the Coccinelle software.

---
 drivers/gpu/drm/nouveau/nouveau_debugfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/nouveau/nouveau_debugfs.c +1 -1
index e83db051e851..931b62097366 100644
@@ -42,7 +42,7 @@ nouveau_debugfs_vbios_image(struct seq_file *m, void *data)
 	int i;
 
 	for (i = 0; i < drm->vbios.length; i++)
-		seq_printf(m, "%c", drm->vbios.data[i]);
+		seq_putc(m, drm->vbios.data[i]);
 	return 0;
 }
 

--
2.45.2

#1 lore raw
Quoted 20 lines · Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 15 Jul 2024 13:36:54 +0200

Single characters should be put into a sequence.
Thus use the corresponding function “seq_putc” for one selected call.

This issue was transformed by using the Coccinelle software.

---
 drivers/gpu/drm/nouveau/nouveau_debugfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/nouveau/nouveau_debugfs.c +0 -0
index e83db051e851..931b62097366 100644

drivers/gpu/drm/nouveau/nouveau_debugfs.c nouveau_debugfs_vbios_image(struct seq_file *m, void *data) · line 45

Quoted 5 lines
drivers/gpu/drm/nouveau/nouveau_debugfs.c +1 -1
@@ -42,7 +42,7 @@ nouveau_debugfs_vbios_image(struct seq_file *m, void *data)
        int i;
 
        for (i = 0; i < drm->vbios.length; i++)
-               seq_printf(m, "%c", drm->vbios.data[i]);
+               seq_putc(m, drm->vbios.data[i]);

Is there some reason this whole thing isn't just

seq_write(m, drm->vbios.data, drm->vbios.length)

Quoted 6 lines
drivers/gpu/drm/nouveau/nouveau_debugfs.c +0 -1
        return 0;
 }
 
--

2.45.2

#2 lore raw

PATCH v2 1/1 drm/nouveau/debugfs: Optimise data output in nouveau_debugfs_vbios_image()

From: Markus Elfring <[email protected]>
Date: Tue, 23 Jul 2024 18:08:15 +0200

Some characters should be put into a sequence.

* Thus print all data by the corresponding function “seq_write” at once.

* Return also the value from this function call.

* Omit a local variable which became redundant with this refactoring.

This issue was detected by using the Coccinelle software.

---

V2:
A patch review suggestion from Ilia Mirkin was integrated.

 drivers/gpu/drm/nouveau/nouveau_debugfs.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/gpu/drm/nouveau/nouveau_debugfs.c +1 -4
index e83db051e851..980cff265060 100644
@@ -39,11 +39,8 @@ nouveau_debugfs_vbios_image(struct seq_file *m, void *data)
 {
 	struct drm_info_node *node = (struct drm_info_node *) m->private;
 	struct nouveau_drm *drm = nouveau_drm(node->minor->dev);
-	int i;
 
-	for (i = 0; i < drm->vbios.length; i++)
-		seq_printf(m, "%c", drm->vbios.data[i]);
-	return 0;
+	return seq_write(m, drm->vbios.data, drm->vbios.length);
 }
 
 static int

--
2.45.2

#3 lore raw
In reply to Ilia Mirkin

Le 15/07/2024 à 15:15, Ilia Mirkin a écrit :

Quoted 23 lines · Markus Elfring
Quoted 22 lines

From: Markus Elfring <[email protected]>
Date: Mon, 15 Jul 2024 13:36:54 +0200

Single characters should be put into a sequence.
Thus use the corresponding function “seq_putc” for one selected call.

This issue was transformed by using the Coccinelle software.

---
  drivers/gpu/drm/nouveau/nouveau_debugfs.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/nouveau/nouveau_debugfs.c +0 -0
index e83db051e851..931b62097366 100644
@@ -42,7 +42,7 @@ nouveau_debugfs_vbios_image(struct seq_file *m, void *data)
         int i;
 
Quoted 7 lines

drivers/gpu/drm/nouveau/nouveau_debugfs.c nouveau_debugfs_vbios_image(struct seq_file *m, void *data) · line 45

Quoted 3 lines
drivers/gpu/drm/nouveau/nouveau_debugfs.c +1 -1
         for (i = 0; i < drm->vbios.length; i++)
-               seq_printf(m, "%c", drm->vbios.data[i]);
+               seq_putc(m, drm->vbios.data[i]);

Is there some reason this whole thing isn't just

seq_write(m, drm->vbios.data, drm->vbios.length)

Hi,

I don't know if my answer is relevant or not here but:

	for () seq_putc();	==> will fill 'm' with everything that fits in
and
	seq_write()		==> is all or nothing. So if 'm' is too small, then 

nothing will be appended.

I've not looked at the calling tree, but I would expect 'm' to be able to have PAGE_SIZE chars, so most probably 4096.

And having gpu + "vbios.rom", I would expect it to be bigger than 4096.

If I'm correct, then changing for seq_write() would just show... nothing.

I don't know if it can happen., but testing should be easy enough to figure it out.

just my 2c.

CJ

Quoted 9 lines
Quoted 7 lines
drivers/gpu/drm/nouveau/nouveau_debugfs.c +0 -1
         return 0;
  }
 
--

2.45.2

#4 lore raw
Quoted 44 lines · Christophe JAILLET
Quoted 23 lines · Ilia Mirkin
Quoted 22 lines · Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 15 Jul 2024 13:36:54 +0200

Single characters should be put into a sequence.
Thus use the corresponding function “seq_putc” for one selected call.

This issue was transformed by using the Coccinelle software.

---
  drivers/gpu/drm/nouveau/nouveau_debugfs.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/nouveau/nouveau_debugfs.c +0 -0
index e83db051e851..931b62097366 100644
@@ -42,7 +42,7 @@ nouveau_debugfs_vbios_image(struct seq_file *m, void *data)
         int i;
 
Quoted 7 lines

drivers/gpu/drm/nouveau/nouveau_debugfs.c nouveau_debugfs_vbios_image(struct seq_file *m, void *data) · line 45

Quoted 3 lines
drivers/gpu/drm/nouveau/nouveau_debugfs.c +1 -1
         for (i = 0; i < drm->vbios.length; i++)
-               seq_printf(m, "%c", drm->vbios.data[i]);
+               seq_putc(m, drm->vbios.data[i]);

Is there some reason this whole thing isn't just

seq_write(m, drm->vbios.data, drm->vbios.length)

Hi,

I don't know if my answer is relevant or not here but:

        for () seq_putc();      ==> will fill 'm' with everything that fits in
and
        seq_write()             ==> is all or nothing. So if 'm' is too small, then

nothing will be appended.

I've not looked at the calling tree, but I would expect 'm' to be able to have PAGE_SIZE chars, so most probably 4096.

Quoted 7 lines

And having gpu + "vbios.rom", I would expect it to be bigger than 4096.

If I'm correct, then changing for seq_write() would just show... nothing.

I don't know if it can happen., but testing should be easy enough to figure it out.

The vbios can definitely be much much larger than 4k. But it does currently work as-is, i.e. you don't just get the first 4k, you get everything. So I think there's some internal resizing/extension/etc going on.

But I totally agree -- testing required here. Not sure if the author has done that.

Cheers,

-ilia

#5 lore raw
In reply to Christophe JAILLET
Quoted 3 lines
Quoted 3 lines

Is there some reason this whole thing isn't just

seq_write(m, drm->vbios.data, drm->vbios.length)

…

Quoted 2 lines

I don't know if my answer is relevant or not here but:
    for () seq_putc();    ==> will fill 'm' with everything that fits in

I find such a discussion approach strange.

Quoted 2 lines

and
    seq_write()        ==> is all or nothing. So if 'm' is too small, then nothing will be appended.

The clarification can become more interesting for this system detail.
https://elixir.bootlin.com/linux/v6.10/source/fs/seq_file.c#L816

Was the sequence size (or the file capacity) appropriately configured?

Regards,
Markus