mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] media: radio: Replace strlcat() with seq_buf in TEA drivers
@ 2026-11-06  7:46 Mariia Nikitash
  2026-11-06 10:39 ` Alejandro Colomar
  0 siblings, 1 reply; 4+ messages in thread
From: Mariia Nikitash @ 2026-11-06  7:46 UTC (permalink / raw)
  To: hverkuil, mchehab
  Cc: linux-media, linux-kernel, linux-hardening, kees, justinstitt,
	morbo, Mariia Nikitash

In preparation for removing the deprecated strlcat() API[1],
replace the strscpy() and strlcat() calls used to construct
V4L2 card names in the TEA5777 and TEA575x radio drivers.

seq_buf tracks the current write position and remaining capacity
across appends, avoiding repeated scans of the destination buffer.
This preserves the resulting strings, including truncation behavior.

Link: https://github.com/KSPP/linux/issues/370 [1]
Signed-off-by: Mariia Nikitash <nikitash.mariiaw@gmail.com>
---
 drivers/media/radio/radio-tea5777.c | 10 ++++++++--
 drivers/media/radio/tea575x.c       | 10 ++++++++--
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/drivers/media/radio/radio-tea5777.c b/drivers/media/radio/radio-tea5777.c
index fb9de7bbcd19..2b1c7f6ddd60 100644
--- a/drivers/media/radio/radio-tea5777.c
+++ b/drivers/media/radio/radio-tea5777.c
@@ -13,6 +13,7 @@
 #include <linux/init.h>
 #include <linux/module.h>
 #include <linux/sched.h>
+#include <linux/seq_buf.h>
 #include <linux/slab.h>
 #include <media/v4l2-device.h>
 #include <media/v4l2-dev.h>
@@ -255,10 +256,15 @@ static int vidioc_querycap(struct file *file, void  *priv,
 					struct v4l2_capability *v)
 {
 	struct radio_tea5777 *tea = video_drvdata(file);
+	struct seq_buf s;
 
 	strscpy(v->driver, tea->v4l2_dev->name, sizeof(v->driver));
-	strscpy(v->card, tea->card, sizeof(v->card));
-	strlcat(v->card, " TEA5777", sizeof(v->card));
+
+	seq_buf_init(&s, (char *)v->card, sizeof(v->card));
+	seq_buf_puts(&s, (const char *)tea->card);
+	seq_buf_puts(&s, " TEA5777");
+	seq_buf_terminate(&s);
+
 	strscpy(v->bus_info, tea->bus_info, sizeof(v->bus_info));
 	return 0;
 }
diff --git a/drivers/media/radio/tea575x.c b/drivers/media/radio/tea575x.c
index c37315226c42..e49228eb7c46 100644
--- a/drivers/media/radio/tea575x.c
+++ b/drivers/media/radio/tea575x.c
@@ -9,6 +9,7 @@
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/slab.h>
+#include <linux/seq_buf.h>
 #include <linux/sched.h>
 #include <asm/io.h>
 #include <media/v4l2-device.h>
@@ -221,10 +222,15 @@ static int vidioc_querycap(struct file *file, void  *priv,
 					struct v4l2_capability *v)
 {
 	struct snd_tea575x *tea = video_drvdata(file);
+	struct seq_buf s;
 
 	strscpy(v->driver, tea->v4l2_dev->name, sizeof(v->driver));
-	strscpy(v->card, tea->card, sizeof(v->card));
-	strlcat(v->card, tea->tea5759 ? " TEA5759" : " TEA5757", sizeof(v->card));
+
+	seq_buf_init(&s, (char *)v->card, sizeof(v->card));
+	seq_buf_puts(&s, (const char *)tea->card);
+	seq_buf_puts(&s, tea->tea5759 ? " TEA5759" : " TEA5757");
+	seq_buf_terminate(&s);
+
 	strscpy(v->bus_info, tea->bus_info, sizeof(v->bus_info));
 	return 0;
 }
-- 
2.43.0


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

* Re: [PATCH] media: radio: Replace strlcat() with seq_buf in TEA drivers
  2026-11-06  7:46 [PATCH] media: radio: Replace strlcat() with seq_buf in TEA drivers Mariia Nikitash
@ 2026-11-06 10:39 ` Alejandro Colomar
  2026-11-07  4:31   ` Mariia Nikitash
  0 siblings, 1 reply; 4+ messages in thread
From: Alejandro Colomar @ 2026-11-06 10:39 UTC (permalink / raw)
  To: Mariia Nikitash
  Cc: hverkuil, mchehab, linux-media, linux-kernel, linux-hardening,
	kees, justinstitt, morbo

[-- Attachment #1: Type: text/plain, Size: 3144 bytes --]

Hi Mariia,

> Date: 2026-11-05 23:46:39-0800
> From: Mariia Nikitash <nikitash.mariiaw@gmail.com>
>
> In preparation for removing the deprecated strlcat() API[1],
> replace the strscpy() and strlcat() calls used to construct
> V4L2 card names in the TEA5777 and TEA575x radio drivers.
> 
> seq_buf tracks the current write position and remaining capacity
> across appends, avoiding repeated scans of the destination buffer.
> This preserves the resulting strings, including truncation behavior.
> 
> Link: https://github.com/KSPP/linux/issues/370 [1]
> Signed-off-by: Mariia Nikitash <nikitash.mariiaw@gmail.com>
> ---
>  drivers/media/radio/radio-tea5777.c | 10 ++++++++--
>  drivers/media/radio/tea575x.c       | 10 ++++++++--
>  2 files changed, 16 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/media/radio/radio-tea5777.c b/drivers/media/radio/radio-tea5777.c
> index fb9de7bbcd19..2b1c7f6ddd60 100644
> --- a/drivers/media/radio/radio-tea5777.c
> +++ b/drivers/media/radio/radio-tea5777.c
> @@ -13,6 +13,7 @@
>  #include <linux/init.h>
>  #include <linux/module.h>
>  #include <linux/sched.h>
> +#include <linux/seq_buf.h>
>  #include <linux/slab.h>
>  #include <media/v4l2-device.h>
>  #include <media/v4l2-dev.h>
> @@ -255,10 +256,15 @@ static int vidioc_querycap(struct file *file, void  *priv,
>  					struct v4l2_capability *v)
>  {
>  	struct radio_tea5777 *tea = video_drvdata(file);
> +	struct seq_buf s;
>  
>  	strscpy(v->driver, tea->v4l2_dev->name, sizeof(v->driver));
> -	strscpy(v->card, tea->card, sizeof(v->card));
> -	strlcat(v->card, " TEA5777", sizeof(v->card));
> +
> +	seq_buf_init(&s, (char *)v->card, sizeof(v->card));
> +	seq_buf_puts(&s, (const char *)tea->card);
> +	seq_buf_puts(&s, " TEA5777");
> +	seq_buf_terminate(&s);
> +

Why are the casts needed?


Have a lovely day!
Alex

>  	strscpy(v->bus_info, tea->bus_info, sizeof(v->bus_info));
>  	return 0;
>  }
> diff --git a/drivers/media/radio/tea575x.c b/drivers/media/radio/tea575x.c
> index c37315226c42..e49228eb7c46 100644
> --- a/drivers/media/radio/tea575x.c
> +++ b/drivers/media/radio/tea575x.c
> @@ -9,6 +9,7 @@
>  #include <linux/module.h>
>  #include <linux/init.h>
>  #include <linux/slab.h>
> +#include <linux/seq_buf.h>
>  #include <linux/sched.h>
>  #include <asm/io.h>
>  #include <media/v4l2-device.h>
> @@ -221,10 +222,15 @@ static int vidioc_querycap(struct file *file, void  *priv,
>  					struct v4l2_capability *v)
>  {
>  	struct snd_tea575x *tea = video_drvdata(file);
> +	struct seq_buf s;
>  
>  	strscpy(v->driver, tea->v4l2_dev->name, sizeof(v->driver));
> -	strscpy(v->card, tea->card, sizeof(v->card));
> -	strlcat(v->card, tea->tea5759 ? " TEA5759" : " TEA5757", sizeof(v->card));
> +
> +	seq_buf_init(&s, (char *)v->card, sizeof(v->card));
> +	seq_buf_puts(&s, (const char *)tea->card);
> +	seq_buf_puts(&s, tea->tea5759 ? " TEA5759" : " TEA5757");
> +	seq_buf_terminate(&s);
> +
>  	strscpy(v->bus_info, tea->bus_info, sizeof(v->bus_info));
>  	return 0;
>  }
> -- 
> 2.43.0
> 
> 

-- 
<https://www.alejandro-colomar.es>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH] media: radio: Replace strlcat() with seq_buf in TEA drivers
  2026-11-06 10:39 ` Alejandro Colomar
@ 2026-11-07  4:31   ` Mariia Nikitash
  2026-11-07  7:39     ` Alejandro Colomar
  0 siblings, 1 reply; 4+ messages in thread
From: Mariia Nikitash @ 2026-11-07  4:31 UTC (permalink / raw)
  To: Alejandro Colomar
  Cc: hverkuil, mchehab, linux-media, linux-kernel, linux-hardening,
	kees, justinstitt, morbo

On Fri, Nov 6, 2026 at 2:39 AM Alejandro Colomar
<alx+linux-hardening@kernel.org> wrote:
>
> Hi Mariia,
>
> > Date: 2026-11-05 23:46:39-0800
> > From: Mariia Nikitash <nikitash.mariiaw@gmail.com>
> >
> > In preparation for removing the deprecated strlcat() API[1],
> > replace the strscpy() and strlcat() calls used to construct
> > V4L2 card names in the TEA5777 and TEA575x radio drivers.
> >
> > seq_buf tracks the current write position and remaining capacity
> > across appends, avoiding repeated scans of the destination buffer.
> > This preserves the resulting strings, including truncation behavior.
> >
> > Link: https://github.com/KSPP/linux/issues/370 [1]
> > Signed-off-by: Mariia Nikitash <nikitash.mariiaw@gmail.com>
> > ---
> >  drivers/media/radio/radio-tea5777.c | 10 ++++++++--
> >  drivers/media/radio/tea575x.c       | 10 ++++++++--
> >  2 files changed, 16 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/media/radio/radio-tea5777.c b/drivers/media/radio/radio-tea5777.c
> > index fb9de7bbcd19..2b1c7f6ddd60 100644
> > --- a/drivers/media/radio/radio-tea5777.c
> > +++ b/drivers/media/radio/radio-tea5777.c
> > @@ -13,6 +13,7 @@
> >  #include <linux/init.h>
> >  #include <linux/module.h>
> >  #include <linux/sched.h>
> > +#include <linux/seq_buf.h>
> >  #include <linux/slab.h>
> >  #include <media/v4l2-device.h>
> >  #include <media/v4l2-dev.h>
> > @@ -255,10 +256,15 @@ static int vidioc_querycap(struct file *file, void  *priv,
> >                                       struct v4l2_capability *v)
> >  {
> >       struct radio_tea5777 *tea = video_drvdata(file);
> > +     struct seq_buf s;
> >
> >       strscpy(v->driver, tea->v4l2_dev->name, sizeof(v->driver));
> > -     strscpy(v->card, tea->card, sizeof(v->card));
> > -     strlcat(v->card, " TEA5777", sizeof(v->card));
> > +
> > +     seq_buf_init(&s, (char *)v->card, sizeof(v->card));
> > +     seq_buf_puts(&s, (const char *)tea->card);
> > +     seq_buf_puts(&s, " TEA5777");
> > +     seq_buf_terminate(&s);
> > +
>
> Why are the casts needed?

Hi Alex,

I added the casts to make conversions from u8/__u8 to
character-pointer types expected by the seq_buf helpers explicit.

I'm also considering simplifying these two-part string constructions
using scnprintf() instead. Would this approach be preferred?



> Have a lovely day!
> Alex

Thanks,
Mariia
>
> >       strscpy(v->bus_info, tea->bus_info, sizeof(v->bus_info));
> >       return 0;
> >  }
> > diff --git a/drivers/media/radio/tea575x.c b/drivers/media/radio/tea575x.c
> > index c37315226c42..e49228eb7c46 100644
> > --- a/drivers/media/radio/tea575x.c
> > +++ b/drivers/media/radio/tea575x.c
> > @@ -9,6 +9,7 @@
> >  #include <linux/module.h>
> >  #include <linux/init.h>
> >  #include <linux/slab.h>
> > +#include <linux/seq_buf.h>
> >  #include <linux/sched.h>
> >  #include <asm/io.h>
> >  #include <media/v4l2-device.h>
> > @@ -221,10 +222,15 @@ static int vidioc_querycap(struct file *file, void  *priv,
> >                                       struct v4l2_capability *v)
> >  {
> >       struct snd_tea575x *tea = video_drvdata(file);
> > +     struct seq_buf s;
> >
> >       strscpy(v->driver, tea->v4l2_dev->name, sizeof(v->driver));
> > -     strscpy(v->card, tea->card, sizeof(v->card));
> > -     strlcat(v->card, tea->tea5759 ? " TEA5759" : " TEA5757", sizeof(v->card));
> > +
> > +     seq_buf_init(&s, (char *)v->card, sizeof(v->card));
> > +     seq_buf_puts(&s, (const char *)tea->card);
> > +     seq_buf_puts(&s, tea->tea5759 ? " TEA5759" : " TEA5757");
> > +     seq_buf_terminate(&s);
> > +
> >       strscpy(v->bus_info, tea->bus_info, sizeof(v->bus_info));
> >       return 0;
> >  }
> > --
> > 2.43.0
> >
> >
>
> --
> <https://www.alejandro-colomar.es>

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

* Re: [PATCH] media: radio: Replace strlcat() with seq_buf in TEA drivers
  2026-11-07  4:31   ` Mariia Nikitash
@ 2026-11-07  7:39     ` Alejandro Colomar
  0 siblings, 0 replies; 4+ messages in thread
From: Alejandro Colomar @ 2026-11-07  7:39 UTC (permalink / raw)
  To: Mariia Nikitash
  Cc: hverkuil, mchehab, linux-media, linux-kernel, linux-hardening,
	kees, justinstitt, morbo

[-- Attachment #1: Type: text/plain, Size: 1482 bytes --]

Hi Mariia,

> Date: 2026-11-06 20:31:53-0800
> From: Mariia Nikitash <nikitash.mariiaw@gmail.com>
>
[...]
> > > @@ -255,10 +256,15 @@ static int vidioc_querycap(struct file *file, void  *priv,
> > >                                       struct v4l2_capability *v)
> > >  {
> > >       struct radio_tea5777 *tea = video_drvdata(file);
> > > +     struct seq_buf s;
> > >
> > >       strscpy(v->driver, tea->v4l2_dev->name, sizeof(v->driver));
> > > -     strscpy(v->card, tea->card, sizeof(v->card));
> > > -     strlcat(v->card, " TEA5777", sizeof(v->card));
> > > +
> > > +     seq_buf_init(&s, (char *)v->card, sizeof(v->card));
> > > +     seq_buf_puts(&s, (const char *)tea->card);
> > > +     seq_buf_puts(&s, " TEA5777");
> > > +     seq_buf_terminate(&s);
> > > +
> >
> > Why are the casts needed?
> 
> Hi Alex,
> 
> I added the casts to make conversions from u8/__u8 to
> character-pointer types expected by the seq_buf helpers explicit.

I was surprised that it wasn't needed before.  In theory, strscpy()
should be expecting the same types, so if it wasn't needed before, it
shouldn't be needed now (and conversely, if it is needed now, it would
have been needed before).

> 
> I'm also considering simplifying these two-part string constructions
> using scnprintf() instead. Would this approach be preferred?

I certainly prefer scnprintf() over seq_buf.  :)


Have a lovely day!
Alex

-- 
<https://www.alejandro-colomar.es>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

end of thread, other threads:[~2026-11-07  7:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-06  7:46 [PATCH] media: radio: Replace strlcat() with seq_buf in TEA drivers Mariia Nikitash
2026-11-06 10:39 ` Alejandro Colomar
2026-11-07  4:31   ` Mariia Nikitash
2026-11-07  7:39     ` Alejandro Colomar

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®