* [PATCH] ALSA: cmipci: Use strscpy() in snd_cmipci_create()
@ 2026-10-22 16:40 Thorsten Blum
2026-10-23 13:41 ` Takashi Iwai
2026-10-23 18:40 ` David Laight
0 siblings, 2 replies; 5+ messages in thread
From: Thorsten Blum @ 2026-10-22 16:40 UTC (permalink / raw)
To: Jaroslav Kysela, Takashi Iwai,
Uwe Kleine-König (The Capable Hub),
Zhao Dongdong
Cc: Thorsten Blum, Takashi Iwai, linux-sound, linux-kernel
To prepare for removing strlcat() from the kernel [1], use strscpy()
instead with the current driver name length as the append offset. Also
use size_t in the multi-channel branch to match strlen()'s return type.
No functional change.
Link: https://github.com/KSPP/linux/issues/370 [1]
Signed-off-by: Thorsten Blum <blum@kernel.org>
---
sound/pci/cmipci.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/sound/pci/cmipci.c b/sound/pci/cmipci.c
index 9d9f784e3a8c..5722b722da95 100644
--- a/sound/pci/cmipci.c
+++ b/sound/pci/cmipci.c
@@ -2980,11 +2980,15 @@ static int snd_cmipci_create(struct snd_card *card, struct pci_dev *pci,
query_chip(cm);
/* added -MCx suffix for chip supporting multi-channels */
if (cm->can_multi_ch) {
- int l = strlen(cm->card->driver);
+ size_t l = strlen(cm->card->driver);
+
scnprintf(cm->card->driver + l, sizeof(cm->card->driver) - l,
"-MC%d", cm->max_channels);
- } else if (cm->can_ac3_sw)
- strlcat(cm->card->driver, "-SWIEC", sizeof(cm->card->driver));
+ } else if (cm->can_ac3_sw) {
+ size_t l = strlen(cm->card->driver);
+
+ strscpy(cm->card->driver + l, "-SWIEC", sizeof(cm->card->driver) - l);
+ }
cm->dig_status = SNDRV_PCM_DEFAULT_CON_SPDIF;
cm->dig_pcm_status = SNDRV_PCM_DEFAULT_CON_SPDIF;
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] ALSA: cmipci: Use strscpy() in snd_cmipci_create()
2026-10-22 16:40 [PATCH] ALSA: cmipci: Use strscpy() in snd_cmipci_create() Thorsten Blum
@ 2026-10-23 13:41 ` Takashi Iwai
2026-10-23 18:40 ` David Laight
1 sibling, 0 replies; 5+ messages in thread
From: Takashi Iwai @ 2026-10-23 13:41 UTC (permalink / raw)
To: Thorsten Blum
Cc: Jaroslav Kysela, Takashi Iwai,
"Uwe Kleine-König (The Capable Hub)",
Zhao Dongdong, Takashi Iwai, linux-sound, linux-kernel
On Thu, 22 Oct 2026 18:40:11 +0200,
Thorsten Blum wrote:
>
> To prepare for removing strlcat() from the kernel [1], use strscpy()
> instead with the current driver name length as the append offset. Also
> use size_t in the multi-channel branch to match strlen()'s return type.
>
> No functional change.
>
> Link: https://github.com/KSPP/linux/issues/370 [1]
> Signed-off-by: Thorsten Blum <blum@kernel.org>
Applied now. Thanks.
Takashi
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] ALSA: cmipci: Use strscpy() in snd_cmipci_create()
2026-10-22 16:40 [PATCH] ALSA: cmipci: Use strscpy() in snd_cmipci_create() Thorsten Blum
2026-10-23 13:41 ` Takashi Iwai
@ 2026-10-23 18:40 ` David Laight
2026-10-23 19:38 ` Takashi Iwai
1 sibling, 1 reply; 5+ messages in thread
From: David Laight @ 2026-10-23 18:40 UTC (permalink / raw)
To: Thorsten Blum
Cc: Jaroslav Kysela, Takashi Iwai,
Uwe Kleine-König (The Capable Hub),
Zhao Dongdong, Takashi Iwai, linux-sound, linux-kernel
On Thu, 22 Oct 2026 18:40:11 +0200
Thorsten Blum <blum@kernel.org> wrote:
> To prepare for removing strlcat() from the kernel [1], use strscpy()
> instead with the current driver name length as the append offset. Also
> use size_t in the multi-channel branch to match strlen()'s return type.
>
> No functional change.
>
> Link: https://github.com/KSPP/linux/issues/370 [1]
> Signed-off-by: Thorsten Blum <blum@kernel.org>
> ---
> sound/pci/cmipci.c | 10 +++++++---
> 1 file changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/sound/pci/cmipci.c b/sound/pci/cmipci.c
> index 9d9f784e3a8c..5722b722da95 100644
> --- a/sound/pci/cmipci.c
> +++ b/sound/pci/cmipci.c
> @@ -2980,11 +2980,15 @@ static int snd_cmipci_create(struct snd_card *card, struct pci_dev *pci,
> query_chip(cm);
> /* added -MCx suffix for chip supporting multi-channels */
> if (cm->can_multi_ch) {
> - int l = strlen(cm->card->driver);
> + size_t l = strlen(cm->card->driver);
> +
> scnprintf(cm->card->driver + l, sizeof(cm->card->driver) - l,
> "-MC%d", cm->max_channels);
> - } else if (cm->can_ac3_sw)
> - strlcat(cm->card->driver, "-SWIEC", sizeof(cm->card->driver));
> + } else if (cm->can_ac3_sw) {
> + size_t l = strlen(cm->card->driver);
> +
> + strscpy(cm->card->driver + l, "-SWIEC", sizeof(cm->card->driver) - l);
> + }
There are all sorts of reasons for not using strlcat() and various ways
of changing code so that it doesn't need to do the string concatenation.
But replacing calls with strlen() and strscpy() is just plain stupid.
It has no benefits and lots of downsides.
David
>
> cm->dig_status = SNDRV_PCM_DEFAULT_CON_SPDIF;
> cm->dig_pcm_status = SNDRV_PCM_DEFAULT_CON_SPDIF;
>
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] ALSA: cmipci: Use strscpy() in snd_cmipci_create()
2026-10-23 18:40 ` David Laight
@ 2026-10-23 19:38 ` Takashi Iwai
2026-10-23 21:01 ` David Laight
0 siblings, 1 reply; 5+ messages in thread
From: Takashi Iwai @ 2026-10-23 19:38 UTC (permalink / raw)
To: David Laight
Cc: Thorsten Blum, Jaroslav Kysela, Takashi Iwai,
"Uwe Kleine-König (The Capable Hub)",
Zhao Dongdong, Takashi Iwai, linux-sound, linux-kernel
On Fri, 23 Oct 2026 20:40:59 +0200,
David Laight wrote:
>
> On Thu, 22 Oct 2026 18:40:11 +0200
> Thorsten Blum <blum@kernel.org> wrote:
>
> > To prepare for removing strlcat() from the kernel [1], use strscpy()
> > instead with the current driver name length as the append offset. Also
> > use size_t in the multi-channel branch to match strlen()'s return type.
> >
> > No functional change.
> >
> > Link: https://github.com/KSPP/linux/issues/370 [1]
> > Signed-off-by: Thorsten Blum <blum@kernel.org>
> > ---
> > sound/pci/cmipci.c | 10 +++++++---
> > 1 file changed, 7 insertions(+), 3 deletions(-)
> >
> > diff --git a/sound/pci/cmipci.c b/sound/pci/cmipci.c
> > index 9d9f784e3a8c..5722b722da95 100644
> > --- a/sound/pci/cmipci.c
> > +++ b/sound/pci/cmipci.c
> > @@ -2980,11 +2980,15 @@ static int snd_cmipci_create(struct snd_card *card, struct pci_dev *pci,
> > query_chip(cm);
> > /* added -MCx suffix for chip supporting multi-channels */
> > if (cm->can_multi_ch) {
> > - int l = strlen(cm->card->driver);
> > + size_t l = strlen(cm->card->driver);
> > +
> > scnprintf(cm->card->driver + l, sizeof(cm->card->driver) - l,
> > "-MC%d", cm->max_channels);
> > - } else if (cm->can_ac3_sw)
> > - strlcat(cm->card->driver, "-SWIEC", sizeof(cm->card->driver));
> > + } else if (cm->can_ac3_sw) {
> > + size_t l = strlen(cm->card->driver);
> > +
> > + strscpy(cm->card->driver + l, "-SWIEC", sizeof(cm->card->driver) - l);
> > + }
>
> There are all sorts of reasons for not using strlcat() and various ways
> of changing code so that it doesn't need to do the string concatenation.
> But replacing calls with strlen() and strscpy() is just plain stupid.
>
> It has no benefits and lots of downsides.
Right. The whole actions look to me like a crusade to a wrong goal.
I was too tired of discussing the same thing again and again, so I
gave and took it once; but now I change mind and drop it again from
the queue. The other patches from Thomas were OK as they can be seen
as optimizations, but this one has only downsides.
thanks,
Takashi
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] ALSA: cmipci: Use strscpy() in snd_cmipci_create()
2026-10-23 19:38 ` Takashi Iwai
@ 2026-10-23 21:01 ` David Laight
0 siblings, 0 replies; 5+ messages in thread
From: David Laight @ 2026-10-23 21:01 UTC (permalink / raw)
To: Takashi Iwai
Cc: Thorsten Blum, Jaroslav Kysela, Takashi Iwai,
Uwe Kleine-König (The Capable Hub),
Zhao Dongdong, linux-sound, linux-kernel
On Fri, 23 Oct 2026 21:38:22 +0200
Takashi Iwai <tiwai@suse.de> wrote:
> On Fri, 23 Oct 2026 20:40:59 +0200,
> David Laight wrote:
> >
> > On Thu, 22 Oct 2026 18:40:11 +0200
> > Thorsten Blum <blum@kernel.org> wrote:
> >
> > > To prepare for removing strlcat() from the kernel [1], use strscpy()
> > > instead with the current driver name length as the append offset. Also
> > > use size_t in the multi-channel branch to match strlen()'s return type.
> > >
> > > No functional change.
> > >
> > > Link: https://github.com/KSPP/linux/issues/370 [1]
> > > Signed-off-by: Thorsten Blum <blum@kernel.org>
> > > ---
> > > sound/pci/cmipci.c | 10 +++++++---
> > > 1 file changed, 7 insertions(+), 3 deletions(-)
> > >
> > > diff --git a/sound/pci/cmipci.c b/sound/pci/cmipci.c
> > > index 9d9f784e3a8c..5722b722da95 100644
> > > --- a/sound/pci/cmipci.c
> > > +++ b/sound/pci/cmipci.c
> > > @@ -2980,11 +2980,15 @@ static int snd_cmipci_create(struct snd_card *card, struct pci_dev *pci,
> > > query_chip(cm);
> > > /* added -MCx suffix for chip supporting multi-channels */
> > > if (cm->can_multi_ch) {
> > > - int l = strlen(cm->card->driver);
> > > + size_t l = strlen(cm->card->driver);
> > > +
> > > scnprintf(cm->card->driver + l, sizeof(cm->card->driver) - l,
> > > "-MC%d", cm->max_channels);
> > > - } else if (cm->can_ac3_sw)
> > > - strlcat(cm->card->driver, "-SWIEC", sizeof(cm->card->driver));
> > > + } else if (cm->can_ac3_sw) {
> > > + size_t l = strlen(cm->card->driver);
> > > +
> > > + strscpy(cm->card->driver + l, "-SWIEC", sizeof(cm->card->driver) - l);
> > > + }
> >
> > There are all sorts of reasons for not using strlcat() and various ways
> > of changing code so that it doesn't need to do the string concatenation.
> > But replacing calls with strlen() and strscpy() is just plain stupid.
> >
> > It has no benefits and lots of downsides.
>
> Right. The whole actions look to me like a crusade to a wrong goal.
There are places where you either know the length from earlier
or can get the string all built at once.
Changing those does make sense.
Similarly changing places which repeatedly strcat() bits of string.
But these ones are silly.
David
>
> I was too tired of discussing the same thing again and again, so I
> gave and took it once; but now I change mind and drop it again from
> the queue. The other patches from Thomas were OK as they can be seen
> as optimizations, but this one has only downsides.
>
>
> thanks,
>
> Takashi
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-10-23 21:01 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-22 16:40 [PATCH] ALSA: cmipci: Use strscpy() in snd_cmipci_create() Thorsten Blum
2026-10-23 13:41 ` Takashi Iwai
2026-10-23 18:40 ` David Laight
2026-10-23 19:38 ` Takashi Iwai
2026-10-23 21:01 ` David Laight
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®