media: verisilicon: Replace strlcat() with seq_buf
Subsystems (3)
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
@@ -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
Quoted 7 lines · On Thu, 5 Nov 2026 00:45:18 -0800 Mariia Nikitash…
In preparation for removing the deprecated
strlcat()API[1], replace thestrscpy()andstrlcat()calls withseq_bufoperations 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
Signed-off-by Mariia Nikitash <[email protected]>--- drivers/media/platform/verisilicon/hantro_drv.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)drivers/media/platform/verisilicon/hantro_drv.c +8
-3@@ -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;
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 thestrscpy()andstrlcat()calls withseq_bufoperations 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
Signed-off-by Mariia Nikitash <[email protected]>
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@@ -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;
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 thestrscpy()andstrlcat()calls withseq_bufoperations 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
Signed-off-by Mariia Nikitash <[email protected]>Nacked-by Hans Verkuil <[email protected]>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@@ -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;
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 thestrscpy()andstrlcat()calls withseq_bufoperations 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
PATCH v2 1/1 media: verisilicon: Replace strlcat() with scnprintf()
In reply to Mariia NikitashIn 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
@@ -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
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 thestrscpy()andstrlcat()calls inhantro_add_func()with a singlescnprintf()call.
Quoted 5 lines
This preserves the resulting string, including NUL termination and truncation behavior.
Signed-off-by Mariia Nikitash <[email protected]>
Have a lovely day!
Alex
Quoted 28 lines
---
Changes in v2:
- Replaceseq_bufwith a singlescnprintf()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@@ -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>
Re: [PATCH v2] media: verisilicon: Replace strlcat() with scnprintf()
In reply to Mariia NikitashQuoted 9 lines · Mariia Nikitash
In preparation for removing the deprecated
strlcat()API [1], replace thestrscpy()andstrlcat()calls inhantro_add_func()with a singlescnprintf()call.This preserves the resulting string, including NUL termination and truncation behavior.
Signed-off-by Mariia Nikitash <[email protected]>
Quoted 7 lines
---
Changes in v2:
- Replaceseq_bufwith a singlescnprintf()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.
Re: [PATCH v2] media: verisilicon: Replace strlcat() with scnprintf()
In reply to Mariia NikitashQuoted 7 lines · Mariia Nikitash
In preparation for removing the deprecated
strlcat()API [1], replace thestrscpy()andstrlcat()calls inhantro_add_func()with a singlescnprintf()call.This preserves the resulting string, including NUL termination and truncation behavior.
Quoted 6 lines
Signed-off-by Mariia Nikitash <[email protected]>---
Changes in v2:
- Replaceseq_bufwith a singlescnprintf()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@@ -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
Hi,
Quoted 53 lines · Mariia Nikitash
In preparation for removing the deprecated
strlcat()API[1], replace thestrscpy()andstrlcat()calls withseq_bufoperations 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.
Signed-off-by Mariia Nikitash <[email protected]>--- drivers/media/platform/verisilicon/hantro_drv.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)drivers/media/platform/verisilicon/hantro_drv.c +8
-3@@ -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