Kernel-Janitors Archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] usb: gadget: u_audio:
@ 2024-03-23  6:57 Christophe JAILLET
  2024-03-23  6:57 ` [PATCH 1/3] usb: gadget: u_audio: Fix the size of a buffer in a strscpy() call Christophe JAILLET
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Christophe JAILLET @ 2024-03-23  6:57 UTC (permalink / raw
  To: gregkh, jbrunet, ruslan.bilovol
  Cc: linux-usb, linux-kernel, kernel-janitors, Christophe JAILLET

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(-)

-- 
2.44.0


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

* [PATCH 1/3] usb: gadget: u_audio: Fix the size of a buffer in a strscpy() call
  2024-03-23  6:57 [PATCH 0/3] usb: gadget: u_audio: Christophe JAILLET
@ 2024-03-23  6:57 ` Christophe JAILLET
  2024-03-23  6:57 ` [PATCH 2/3] usb: gadget: u_audio: Use the 2-argument version of strscpy() Christophe JAILLET
  2024-03-23  6:57 ` [PATCH 3/3] usb: gadget: u_audio: Use snprintf() instead of sprintf() Christophe JAILLET
  2 siblings, 0 replies; 4+ messages in thread
From: Christophe JAILLET @ 2024-03-23  6:57 UTC (permalink / raw
  To: gregkh, jbrunet, ruslan.bilovol
  Cc: linux-usb, linux-kernel, kernel-janitors, Christophe JAILLET

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.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
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:
Fixes: e89bb4288378 ("usb: gadget: u_audio: add real feedback implementation")
---
 drivers/usb/gadget/function/u_audio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/function/u_audio.c b/drivers/usb/gadget/function/u_audio.c
index 4a42574b4a7f..00ff623b4ebb 100644
--- a/drivers/usb/gadget/function/u_audio.c
+++ b/drivers/usb/gadget/function/u_audio.c
@@ -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],
-- 
2.44.0


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

* [PATCH 2/3] usb: gadget: u_audio: Use the 2-argument version of strscpy()
  2024-03-23  6:57 [PATCH 0/3] usb: gadget: u_audio: Christophe JAILLET
  2024-03-23  6:57 ` [PATCH 1/3] usb: gadget: u_audio: Fix the size of a buffer in a strscpy() call Christophe JAILLET
@ 2024-03-23  6:57 ` Christophe JAILLET
  2024-03-23  6:57 ` [PATCH 3/3] usb: gadget: u_audio: Use snprintf() instead of sprintf() Christophe JAILLET
  2 siblings, 0 replies; 4+ messages in thread
From: Christophe JAILLET @ 2024-03-23  6:57 UTC (permalink / raw
  To: gregkh, jbrunet, ruslan.bilovol
  Cc: linux-usb, linux-kernel, kernel-janitors, Christophe JAILLET

In 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.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
Compile tested only
---
 drivers/usb/gadget/function/u_audio.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/gadget/function/u_audio.c b/drivers/usb/gadget/function/u_audio.c
index 00ff623b4ebb..5dba7ed9b0a1 100644
--- a/drivers/usb/gadget/function/u_audio.c
+++ b/drivers/usb/gadget/function/u_audio.c
@@ -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,
-- 
2.44.0


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

* [PATCH 3/3] usb: gadget: u_audio: Use snprintf() instead of sprintf()
  2024-03-23  6:57 [PATCH 0/3] usb: gadget: u_audio: Christophe JAILLET
  2024-03-23  6:57 ` [PATCH 1/3] usb: gadget: u_audio: Fix the size of a buffer in a strscpy() call Christophe JAILLET
  2024-03-23  6:57 ` [PATCH 2/3] usb: gadget: u_audio: Use the 2-argument version of strscpy() Christophe JAILLET
@ 2024-03-23  6:57 ` Christophe JAILLET
  2 siblings, 0 replies; 4+ messages in thread
From: Christophe JAILLET @ 2024-03-23  6:57 UTC (permalink / raw
  To: gregkh, jbrunet, ruslan.bilovol
  Cc: linux-usb, linux-kernel, kernel-janitors, Christophe JAILLET

In order to be consistent with other s[n]printf() usage in this file,
switch to snprintf() here as well.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
Compile tested only
---
 drivers/usb/gadget/function/u_audio.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/function/u_audio.c b/drivers/usb/gadget/function/u_audio.c
index 5dba7ed9b0a1..1a634646bd24 100644
--- a/drivers/usb/gadget/function/u_audio.c
+++ b/drivers/usb/gadget/function/u_audio.c
@@ -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);
-- 
2.44.0


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

end of thread, other threads:[~2024-03-23  6:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-23  6:57 [PATCH 0/3] usb: gadget: u_audio: Christophe JAILLET
2024-03-23  6:57 ` [PATCH 1/3] usb: gadget: u_audio: Fix the size of a buffer in a strscpy() call Christophe JAILLET
2024-03-23  6:57 ` [PATCH 2/3] usb: gadget: u_audio: Use the 2-argument version of strscpy() Christophe JAILLET
2024-03-23  6:57 ` [PATCH 3/3] usb: gadget: u_audio: Use snprintf() instead of sprintf() Christophe JAILLET

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).