Skip to contentSkip to conversation

media: verisilicon: Replace strlcat() with seq_buf

PATCH Superseded Mariia Nikitash 7 participants 10 messages Nov 5 – Nov 12

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

PATCH 1/1 media: verisilicon: Replace strlcat() with seq_buf

In preparation for removing the deprecated strlcat() API[1], replace the strscpy() and strlcat() calls with seq_buf operations when constructing Hantro video device names.

This preserves the resulting strings, including truncation when the compatible string and suffix exceed the destination buffer's capacity.

---
 drivers/media/platform/verisilicon/hantro_drv.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/media/platform/verisilicon/hantro_drv.c +8 -3
index 26e5d5547466..2bfcd45cc55e 100644
@@ -17,6 +17,7 @@
 #include <linux/platform_device.h>
 #include <linux/pm.h>
 #include <linux/pm_runtime.h>
+#include <linux/seq_buf.h>
 #include <linux/slab.h>
 #include <linux/videodev2.h>
 #include <linux/workqueue.h>
@@ -883,6 +884,7 @@ static int hantro_add_func(struct hantro_dev *vpu, unsigned int funcid)
 	const struct of_device_id *match;
 	struct hantro_func *func;
 	struct video_device *vfd;
+	struct seq_buf s;
 	int ret;
 
 	match = of_match_node(of_hantro_match, vpu->dev->of_node);
@@ -902,9 +904,12 @@ static int hantro_add_func(struct hantro_dev *vpu, unsigned int funcid)
 	vfd->vfl_dir = VFL_DIR_M2M;
 	vfd->device_caps = V4L2_CAP_STREAMING | V4L2_CAP_VIDEO_M2M_MPLANE;
 	vfd->ioctl_ops = &hantro_ioctl_ops;
-	strscpy(vfd->name, match->compatible, sizeof(vfd->name));
-	strlcat(vfd->name, funcid == MEDIA_ENT_F_PROC_VIDEO_ENCODER ?
-		"-enc" : "-dec", sizeof(vfd->name));
+
+	seq_buf_init(&s, vfd->name, sizeof(vfd->name));
+	seq_buf_puts(&s, match->compatible);
+	seq_buf_puts(&s, funcid == MEDIA_ENT_F_PROC_VIDEO_ENCODER ?
+			"-enc" : "-dec");
+	seq_buf_terminate(&s);
 
 	if (funcid == MEDIA_ENT_F_PROC_VIDEO_ENCODER) {
 		vpu->encoder = func;
Signature · 1 line
2.43.0
#1 lore raw
Quoted 7 lines · On Thu, 5 Nov 2026 00:45:18 -0800 Mariia Nikitash…

In preparation for removing the deprecated strlcat() API[1], replace the strscpy() and strlcat() calls with seq_buf operations when constructing Hantro video device names.

This preserves the resulting strings, including truncation when the compatible string and suffix exceed the destination buffer's capacity.

This is just stupid...

David

Quoted 43 lines
---
 drivers/media/platform/verisilicon/hantro_drv.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/media/platform/verisilicon/hantro_drv.c +8 -3
index 26e5d5547466..2bfcd45cc55e 100644
@@ -17,6 +17,7 @@
 #include <linux/platform_device.h>
 #include <linux/pm.h>
 #include <linux/pm_runtime.h>
+#include <linux/seq_buf.h>
 #include <linux/slab.h>
 #include <linux/videodev2.h>
 #include <linux/workqueue.h>
@@ -883,6 +884,7 @@ static int hantro_add_func(struct hantro_dev *vpu, unsigned int funcid)
 	const struct of_device_id *match;
 	struct hantro_func *func;
 	struct video_device *vfd;
+	struct seq_buf s;
 	int ret;
 
 	match = of_match_node(of_hantro_match, vpu->dev->of_node);
@@ -902,9 +904,12 @@ static int hantro_add_func(struct hantro_dev *vpu, unsigned int funcid)
 	vfd->vfl_dir = VFL_DIR_M2M;
 	vfd->device_caps = V4L2_CAP_STREAMING | V4L2_CAP_VIDEO_M2M_MPLANE;
 	vfd->ioctl_ops = &hantro_ioctl_ops;
-	strscpy(vfd->name, match->compatible, sizeof(vfd->name));
-	strlcat(vfd->name, funcid == MEDIA_ENT_F_PROC_VIDEO_ENCODER ?
-		"-enc" : "-dec", sizeof(vfd->name));
+
+	seq_buf_init(&s, vfd->name, sizeof(vfd->name));
+	seq_buf_puts(&s, match->compatible);
+	seq_buf_puts(&s, funcid == MEDIA_ENT_F_PROC_VIDEO_ENCODER ?
+			"-enc" : "-dec");
+	seq_buf_terminate(&s);
 
 	if (funcid == MEDIA_ENT_F_PROC_VIDEO_ENCODER) {
 		vpu->encoder = func;
Nacked-by NAK
#2 lore raw
Quoted 7 lines · David Laight
Quoted 4 lines · On Thu, 5 Nov 2026 00:45:18 -0800 Mariia Nikitash…

In preparation for removing the deprecated strlcat() API[1], replace the strscpy() and strlcat() calls with seq_buf operations when constructing Hantro video device names.

Quoted 11 lines
Quoted 3 lines

This preserves the resulting strings, including truncation when the compatible string and suffix exceed the destination buffer's capacity.

This is just stupid...

David

Quoted 3 lines

Just use scnprintf.

Regards,

Hans

Quoted 42 lines
Quoted 40 lines
---
 drivers/media/platform/verisilicon/hantro_drv.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/media/platform/verisilicon/hantro_drv.c +8 -3
index 26e5d5547466..2bfcd45cc55e 100644
@@ -17,6 +17,7 @@
 #include <linux/platform_device.h>
 #include <linux/pm.h>
 #include <linux/pm_runtime.h>
+#include <linux/seq_buf.h>
 #include <linux/slab.h>
 #include <linux/videodev2.h>
 #include <linux/workqueue.h>
@@ -883,6 +884,7 @@ static int hantro_add_func(struct hantro_dev *vpu, unsigned int funcid)
 	const struct of_device_id *match;
 	struct hantro_func *func;
 	struct video_device *vfd;
+	struct seq_buf s;
 	int ret;
 
 	match = of_match_node(of_hantro_match, vpu->dev->of_node);
@@ -902,9 +904,12 @@ static int hantro_add_func(struct hantro_dev *vpu, unsigned int funcid)
 	vfd->vfl_dir = VFL_DIR_M2M;
 	vfd->device_caps = V4L2_CAP_STREAMING | V4L2_CAP_VIDEO_M2M_MPLANE;
 	vfd->ioctl_ops = &hantro_ioctl_ops;
-	strscpy(vfd->name, match->compatible, sizeof(vfd->name));
-	strlcat(vfd->name, funcid == MEDIA_ENT_F_PROC_VIDEO_ENCODER ?
-		"-enc" : "-dec", sizeof(vfd->name));
+
+	seq_buf_init(&s, vfd->name, sizeof(vfd->name));
+	seq_buf_puts(&s, match->compatible);
+	seq_buf_puts(&s, funcid == MEDIA_ENT_F_PROC_VIDEO_ENCODER ?
+			"-enc" : "-dec");
+	seq_buf_terminate(&s);
 
 	if (funcid == MEDIA_ENT_F_PROC_VIDEO_ENCODER) {
 		vpu->encoder = func;
#3 lore raw
Quoted 18 lines · Hans Verkuil
Quoted 16 lines · David Laight
Quoted 7 lines · On Thu, 5 Nov 2026 00:45:18 -0800 Mariia Nikitash…

In preparation for removing the deprecated strlcat() API[1], replace the strscpy() and strlcat() calls with seq_buf operations when constructing Hantro video device names.

This preserves the resulting strings, including truncation when the compatible string and suffix exceed the destination buffer's capacity.

This is just stupid...

David

Quoted 1 line
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines

Just use scnprintf.

Thanks for the reviews, I will simplify it to use scnprintf and send a v2.

Quoted 5 lines

Regards,

Hans

Best,
Mariia

Quoted 43 lines
Quoted 42 lines
Quoted 40 lines
---
 drivers/media/platform/verisilicon/hantro_drv.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/media/platform/verisilicon/hantro_drv.c +8 -3
index 26e5d5547466..2bfcd45cc55e 100644
@@ -17,6 +17,7 @@
 #include <linux/platform_device.h>
 #include <linux/pm.h>
 #include <linux/pm_runtime.h>
+#include <linux/seq_buf.h>
 #include <linux/slab.h>
 #include <linux/videodev2.h>
 #include <linux/workqueue.h>
@@ -883,6 +884,7 @@ static int hantro_add_func(struct hantro_dev *vpu, unsigned int funcid)
     const struct of_device_id *match;
     struct hantro_func *func;
     struct video_device *vfd;
+    struct seq_buf s;
     int ret;
 
     match = of_match_node(of_hantro_match, vpu->dev->of_node);
@@ -902,9 +904,12 @@ static int hantro_add_func(struct hantro_dev *vpu, unsigned int funcid)
     vfd->vfl_dir = VFL_DIR_M2M;
     vfd->device_caps = V4L2_CAP_STREAMING | V4L2_CAP_VIDEO_M2M_MPLANE;
     vfd->ioctl_ops = &hantro_ioctl_ops;
-    strscpy(vfd->name, match->compatible, sizeof(vfd->name));
-    strlcat(vfd->name, funcid == MEDIA_ENT_F_PROC_VIDEO_ENCODER ?
-            "-enc" : "-dec", sizeof(vfd->name));
+
+    seq_buf_init(&s, vfd->name, sizeof(vfd->name));
+    seq_buf_puts(&s, match->compatible);
+    seq_buf_puts(&s, funcid == MEDIA_ENT_F_PROC_VIDEO_ENCODER ?
+                    "-enc" : "-dec");
+    seq_buf_terminate(&s);
 
     if (funcid == MEDIA_ENT_F_PROC_VIDEO_ENCODER) {
             vpu->encoder = func;
#4 lore raw
In reply to David Laight
Quoted 7 lines · David Laight
Quoted 4 lines · On Thu, 5 Nov 2026 00:45:18 -0800 Mariia Nikitash…

In preparation for removing the deprecated strlcat() API[1], replace the strscpy() and strlcat() calls with seq_buf operations when constructing Hantro video device names.

Quoted 5 lines
Quoted 3 lines

This preserves the resulting strings, including truncation when the compatible string and suffix exceed the destination buffer's capacity.

This is just stupid...

David, this isn't very helpful. I realize there are other threads where you get into more detail, but as a stand-alone reply, I'd expect more constructive feedback (or none at all, or a pointer to an earlier thread if you feel like something needs repeating, etc).

Signature · 1 line
Kees Cook
#5 lore raw

PATCH v2 1/1 media: verisilicon: Replace strlcat() with scnprintf()

In reply to Mariia Nikitash

In preparation for removing the deprecated strlcat() API [1], replace the strscpy() and strlcat() calls in hantro_add_func() with a single scnprintf() call.

This preserves the resulting string, including NUL termination and truncation behavior.

---
Changes in v2:
- Replace seq_buf with a single scnprintf() call, as suggested by Hans Verkuil.

 drivers/media/platform/verisilicon/hantro_drv.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/media/platform/verisilicon/hantro_drv.c +2 -3
index 26e5d5547466..d8854ceb4fed 100644
@@ -902,9 +902,8 @@ static int hantro_add_func(struct hantro_dev *vpu, unsigned int funcid)
 	vfd->vfl_dir = VFL_DIR_M2M;
 	vfd->device_caps = V4L2_CAP_STREAMING | V4L2_CAP_VIDEO_M2M_MPLANE;
 	vfd->ioctl_ops = &hantro_ioctl_ops;
-	strscpy(vfd->name, match->compatible, sizeof(vfd->name));
-	strlcat(vfd->name, funcid == MEDIA_ENT_F_PROC_VIDEO_ENCODER ?
-		"-enc" : "-dec", sizeof(vfd->name));
+	scnprintf(vfd->name, sizeof(vfd->name), "%s%s", match->compatible,
+		  funcid == MEDIA_ENT_F_PROC_VIDEO_ENCODER ? "-enc" : "-dec");
 
 	if (funcid == MEDIA_ENT_F_PROC_VIDEO_ENCODER) {
 		vpu->encoder = func;
Signature · 1 line
2.43.0
Reviewed-by on v2 1/1
#6 lore raw

Re: [PATCH v2] media: verisilicon: Replace strlcat() with scnprintf()

Hi Mariia,

Quoted 7 lines

Date: 2026-11-10 19:24:46-0800
From: Mariia Nikitash <[email protected]>

In preparation for removing the deprecated strlcat() API [1], replace the strscpy() and strlcat() calls in hantro_add_func() with a single scnprintf() call.

Quoted 5 lines

This preserves the resulting string, including NUL termination and truncation behavior.

Have a lovely day!
Alex

Quoted 28 lines

---
Changes in v2:
- Replace seq_buf with a single scnprintf() call, as suggested by Hans Verkuil.

 drivers/media/platform/verisilicon/hantro_drv.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/media/platform/verisilicon/hantro_drv.c +2 -3
index 26e5d5547466..d8854ceb4fed 100644
@@ -902,9 +902,8 @@ static int hantro_add_func(struct hantro_dev *vpu, unsigned int funcid)
 	vfd->vfl_dir = VFL_DIR_M2M;
 	vfd->device_caps = V4L2_CAP_STREAMING | V4L2_CAP_VIDEO_M2M_MPLANE;
 	vfd->ioctl_ops = &hantro_ioctl_ops;
-	strscpy(vfd->name, match->compatible, sizeof(vfd->name));
-	strlcat(vfd->name, funcid == MEDIA_ENT_F_PROC_VIDEO_ENCODER ?
-		"-enc" : "-dec", sizeof(vfd->name));
+	scnprintf(vfd->name, sizeof(vfd->name), "%s%s", match->compatible,
+		  funcid == MEDIA_ENT_F_PROC_VIDEO_ENCODER ? "-enc" : "-dec");
 
 	if (funcid == MEDIA_ENT_F_PROC_VIDEO_ENCODER) {
 		vpu->encoder = func;
Signature · 1 line
2.43.0
Signature · 1 line
<https://www.alejandro-colomar.es>
Reviewed-by on v2 1/1
#7 lore raw

Re: [PATCH v2] media: verisilicon: Replace strlcat() with scnprintf()

In reply to Mariia Nikitash
Quoted 9 lines · Mariia Nikitash

In preparation for removing the deprecated strlcat() API [1], replace the strscpy() and strlcat() calls in hantro_add_func() with a single scnprintf() call.

This preserves the resulting string, including NUL termination and truncation behavior.

Quoted 7 lines

---
Changes in v2:
- Replace seq_buf with a single scnprintf() call, as suggested by Hans Verkuil.

 drivers/media/platform/verisilicon/hantro_drv.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

Nit: the prefix "media: hantro:" would probably be a better fit.

Otherwise, this looks good to me.

Reviewed-by on v2 1/1
#8 lore raw

Re: [PATCH v2] media: verisilicon: Replace strlcat() with scnprintf()

In reply to Mariia Nikitash
Quoted 7 lines · Mariia Nikitash

In preparation for removing the deprecated strlcat() API [1], replace the strscpy() and strlcat() calls in hantro_add_func() with a single scnprintf() call.

This preserves the resulting string, including NUL termination and truncation behavior.

Quoted 6 lines

---
Changes in v2:
- Replace seq_buf with a single scnprintf() call, as suggested by Hans Verkuil.

I think the Subject prefix is fine, it matches the prior poking of this area:

b66215e7b780 ("media: verisilicon: replace snprintf with strscpy+strlcat")

For vfd->name,

	struct video_device {
		...
		        char name[64];

Does this need to be raised?

Because match->compatible is quite large:

struct of_device_id {
...

        char    compatible[128];

The real question remains: how should truncation of vfd->name (by anything that constructs it) be handled?

-Kees

Quoted 23 lines
 drivers/media/platform/verisilicon/hantro_drv.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/media/platform/verisilicon/hantro_drv.c +2 -3
index 26e5d5547466..d8854ceb4fed 100644
@@ -902,9 +902,8 @@ static int hantro_add_func(struct hantro_dev *vpu, unsigned int funcid)
 	vfd->vfl_dir = VFL_DIR_M2M;
 	vfd->device_caps = V4L2_CAP_STREAMING | V4L2_CAP_VIDEO_M2M_MPLANE;
 	vfd->ioctl_ops = &hantro_ioctl_ops;
-	strscpy(vfd->name, match->compatible, sizeof(vfd->name));
-	strlcat(vfd->name, funcid == MEDIA_ENT_F_PROC_VIDEO_ENCODER ?
-		"-enc" : "-dec", sizeof(vfd->name));
+	scnprintf(vfd->name, sizeof(vfd->name), "%s%s", match->compatible,
+		  funcid == MEDIA_ENT_F_PROC_VIDEO_ENCODER ? "-enc" : "-dec");
 
 	if (funcid == MEDIA_ENT_F_PROC_VIDEO_ENCODER) {
 		vpu->encoder = func;
Signature · 1 line
2.43.0
Signature · 1 line
Kees Cook
Reviewed-by on v1 1/1
#9 lore raw
In reply to Mariia Nikitash

Hi,

Quoted 53 lines · Mariia Nikitash

In preparation for removing the deprecated strlcat() API[1], replace the strscpy() and strlcat() calls with seq_buf operations when constructing Hantro video device names.

This preserves the resulting strings, including truncation when the compatible string and suffix exceed the destination buffer's capacity.

---
 drivers/media/platform/verisilicon/hantro_drv.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/media/platform/verisilicon/hantro_drv.c +8 -3
index 26e5d5547466..2bfcd45cc55e 100644
@@ -17,6 +17,7 @@
 #include <linux/platform_device.h>
 #include <linux/pm.h>
 #include <linux/pm_runtime.h>
+#include <linux/seq_buf.h>
 #include <linux/slab.h>
 #include <linux/videodev2.h>
 #include <linux/workqueue.h>
@@ -883,6 +884,7 @@ static int hantro_add_func(struct hantro_dev *vpu, unsigned int funcid)
 	const struct of_device_id *match;
 	struct hantro_func *func;
 	struct video_device *vfd;
+	struct seq_buf s;
 	int ret;
 
 	match = of_match_node(of_hantro_match, vpu->dev->of_node);
@@ -902,9 +904,12 @@ static int hantro_add_func(struct hantro_dev *vpu, unsigned int funcid)
 	vfd->vfl_dir = VFL_DIR_M2M;
 	vfd->device_caps = V4L2_CAP_STREAMING | V4L2_CAP_VIDEO_M2M_MPLANE;
 	vfd->ioctl_ops = &hantro_ioctl_ops;
-	strscpy(vfd->name, match->compatible, sizeof(vfd->name));
-	strlcat(vfd->name, funcid == MEDIA_ENT_F_PROC_VIDEO_ENCODER ?
-		"-enc" : "-dec", sizeof(vfd->name));
+
+	seq_buf_init(&s, vfd->name, sizeof(vfd->name));
+	seq_buf_puts(&s, match->compatible);
+	seq_buf_puts(&s, funcid == MEDIA_ENT_F_PROC_VIDEO_ENCODER ?
+			"-enc" : "-dec");
+	seq_buf_terminate(&s);
 
 	if (funcid == MEDIA_ENT_F_PROC_VIDEO_ENCODER) {
 		vpu->encoder = func;
Signature · 1 line
2.43.0

Justin