Re: [PATCH] media: radio: Replace strlcat() with seq_buf in TEA drivers
From: David Laight
Date: Tue Nov 10 2026 - 12:31:17 EST
On Tue, 10 Nov 2026 11:08:30 +0100
Hans Verkuil <hverkuil+cisco@xxxxxxxxxx> wrote:
> On 06/11/2026 08:46, Mariia Nikitash wrote:
> > 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@xxxxxxxxx>
>
> Nacked-by: Hans Verkuil <hverkuil+cisco@xxxxxxxxxx>
>
> This is silly. Just use scnprintf().
Or wait for someone to add a call that just does what is needed.
In this case the first stscpy() returns the length (and it is often
known).
So you could have:
len = strscpy(buf, tea->card[, buflen]);
len = strscpy_at(buf, len, " TEA5777"[, buflen]);
or:
len = strscat(buf, buflen, tea->card, " TEA5777", ....);
or some variant that will do a strnlen(buf, buflen) to get the offset.
But it really is best to leave the strlcat() calls in there for now.
David
>
> Regards,
>
> Hans
>
> > ---
> > 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;
> > }
>
>