usb: gadget: u_audio:
Subsystems (2)
cover usb: gadget: u_audio:
The first patch is a fix that has no practital consequences in the real world. So I consider it more as a clean-up than as a fix.
The 2 other patches are just clean-ups to be more consistent with string related API usages within this file.
All 3 patches are compile tested only.
Christophe JAILLET (3):
usb: gadget: u_audio: Fix the size of a buffer in a strscpy() call
usb: gadget: u_audio: Use the 2-argument version of strscpy()
usb: gadget: u_audio: Use snprintf() instead of sprintf()
drivers/usb/gadget/function/u_audio.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
Signature · 1 line
2.44.0
PATCH 1/3 usb: gadget: u_audio: Fix the size of a buffer in a strscpy() call
The size given to strscpy() is not consistent with the destination buffer that is used. The size is related to 'driver' and the buffer is 'mixername'.
sizeof(card->mixername) is 80 and sizeof(card->driver) is 16, so in theory this could lead to unneeded string truncation.
In practice, this is not the case because g_audio_setup() has only 2 callers. 'card_name' is either "UAC1_Gadget" or "UAC2_Gadget".
Anyway, using the correct size is cleaner and more future proof.
In order to be less verbose, use the new 2-argument version of strscpy() which computes auto-magically the size of the destination.
---
Compile tested only.
As this doesn't fix anything in the real world, no Fixes tag is provided. Should one not agree with me, it is:
--- drivers/usb/gadget/function/u_audio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/gadget/function/u_audio.c +1 -1
@@ -1257,7 +1257,7 @@ int g_audio_setup(struct g_audio *g_audio, const char *pcm_name,if ((c_chmask && g_audio->in_ep_fback) || (p_chmask && params->p_fu.id) || (c_chmask && params->c_fu.id)) -strscpy (card->mixername, card_name,sizeof (card->driver)); +strscpy (card->mixername, card_name);if (c_chmask && g_audio->in_ep_fback) { kctl = snd_ctl_new1(&u_audio_controls[UAC_FBACK_CTRL],
Signature · 1 line
2.44.0
PATCH 2/3 usb: gadget: u_audio: Use the 2-argument version of strscpy()
In reply to Christophe JAILLETIn order to be consistent with other strscpy() usage in this file and less verbose, use the new 2-argument version of strscpy() which computes auto-magically the size of the destination.
---
Compile tested only
--- drivers/usb/gadget/function/u_audio.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/usb/gadget/function/u_audio.c +3 -3
@@ -1243,7 +1243,7 @@ int g_audio_setup(struct g_audio *g_audio, const char *pcm_name,if (err <0 ) goto snd_fail; -strscpy (pcm->name, pcm_name,sizeof (pcm->name)); +strscpy (pcm->name, pcm_name); pcm->private_data = uac; uac->pcm = pcm;
@@ -1386,8 +1386,8 @@ int g_audio_setup(struct g_audio *g_audio, const char *pcm_name, prm->snd_kctl_rate = kctl; } -strscpy (card->driver, card_name,sizeof (card->driver)); -strscpy (card->shortname, card_name,sizeof (card->shortname)); +strscpy (card->driver, card_name); +strscpy (card->shortname, card_name);sprintf (card->longname,"%s %i" , card_name, card->dev->id); snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS,
Signature · 1 line
2.44.0
PATCH 3/3 usb: gadget: u_audio: Use snprintf() instead of sprintf()
In reply to Christophe JAILLETIn order to be consistent with other s[n]printf() usage in this file, switch to snprintf() here as well.
---
Compile tested only
--- drivers/usb/gadget/function/u_audio.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/usb/gadget/function/u_audio.c +2 -1
@@ -1388,7 +1388,8 @@ int g_audio_setup(struct g_audio *g_audio, const char *pcm_name,strscpy (card->driver, card_name);strscpy (card->shortname, card_name); -sprintf (card->longname,"%s %i" , card_name, card->dev->id); +snprintf (card->longname,sizeof (card->longname),"%s %i" , + card_name, card->dev->id);snd_pcm_set_managed_buffer_all (pcm,SNDRV_DMA_TYPE_CONTINUOUS ,NULL ,0 ,BUFF_SIZE_MAX );
Signature · 1 line
2.44.0