ALSA: cmipci: Use strscpy() in snd_cmipci_create()
PATCH 1/1 ALSA: cmipci: Use strscpy() in snd_cmipci_create()
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.
--- sound/pci/cmipci.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
sound/pci/cmipci.c +7 -3
@@ -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 ;
Quoted 9 lines · Thorsten Blum
To prepare for removing
strlcat()from the kernel [1], usestrscpy()instead with the current driver name length as the append offset. Also usesize_tin the multi-channel branch to match strlen()'s return type.No functional change.
Signed-off-by Thorsten Blum <[email protected]>
Applied now. Thanks.
Takashi
Quoted 22 lines · On Thu, 22 Oct 2026 18:40:11 +0200 Thorsten Blum <[email protected]> wrote:
To prepare for removing
strlcat()from the kernel [1], usestrscpy()instead with the current driver name length as the append offset. Also usesize_tin the multi-channel branch to match strlen()'s return type.No functional change.
Signed-off-by Thorsten Blum <[email protected]>--- sound/pci/cmipci.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)sound/pci/cmipci.c +1
-1@@ -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);
sound/pci/cmipci.c static int snd_cmipci_create(struct snd_card *card, struct pci_dev *pci, · line 2991
Quoted 10 lines
sound/pci/cmipci.c +6
-2+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
Quoted 4 lines
sound/pci/cmipci.c +0
-0cm->dig_status =SNDRV_PCM_DEFAULT_CON_SPDIF ; cm->dig_pcm_status =SNDRV_PCM_DEFAULT_CON_SPDIF ;
Quoted 41 lines · David Laight
Quoted 22 lines · On Thu, 22 Oct 2026 18:40:11 +0200 Thorsten Blum <[email protected]> wrote:
To prepare for removing
strlcat()from the kernel [1], usestrscpy()instead with the current driver name length as the append offset. Also usesize_tin the multi-channel branch to match strlen()'s return type.No functional change.
Signed-off-by Thorsten Blum <[email protected]>--- sound/pci/cmipci.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)sound/pci/cmipci.c +1
-1@@ -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);sound/pci/cmipci.c static int snd_cmipci_create(struct snd_card *card, struct pci_dev *pci, · line 2991
Quoted 10 lines
sound/pci/cmipci.c +6
-2+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 withstrlen()andstrscpy()is just plain stupid.
Quoted 1 line
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
Quoted 43 lines · On Fri, 23 Oct 2026 21:38:22 +0200 Takashi Iwai <[email protected]> wrote:
Quoted 41 lines · David Laight
Quoted 22 lines · On Thu, 22 Oct 2026 18:40:11 +0200 Thorsten Blum <[email protected]> wrote:
To prepare for removing
strlcat()from the kernel [1], usestrscpy()instead with the current driver name length as the append offset. Also usesize_tin the multi-channel branch to match strlen()'s return type.No functional change.
Signed-off-by Thorsten Blum <[email protected]>--- sound/pci/cmipci.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)sound/pci/cmipci.c +1
-1@@ -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);sound/pci/cmipci.c static int snd_cmipci_create(struct snd_card *card, struct pci_dev *pci, · line 2991
Quoted 10 lines
sound/pci/cmipci.c +6
-2+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 withstrlen()andstrscpy()is just plain stupid.
Quoted 3 lines
Quoted 1 line
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
Quoted 10 lines
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