mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 1/4] ALSA: usb-audio: qcom: Improve error logging in USB offload
@ 2026-06-03  9:10 wangdich9700
  2026-06-03  9:11 ` [PATCH 2/4] ALSA: usb-audio: qcom: Use snprintf for mixer control name formatting wangdich9700
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: wangdich9700 @ 2026-06-03  9:10 UTC (permalink / raw)
  To: tiwai, perex, wangdicheng, wangdich9700; +Cc: linux-sound, linux-kernel

From: wangdicheng <wangdicheng@kylinos.cn>

Add error codes to error messages for better debugging.
This helps identify the root cause when USB audio offload fails.

Error messages now include the actual error code returned by
xhci_sideband operations, making it easier to diagnose failures
during USB audio offload setup.

Signed-off-by: wangdicheng <wangdicheng@kylinos.cn>
---
 sound/usb/qcom/qc_audio_offload.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sound/usb/qcom/qc_audio_offload.c b/sound/usb/qcom/qc_audio_offload.c
index a0009503b2c5..f99f8bddb237 100644
--- a/sound/usb/qcom/qc_audio_offload.c
+++ b/sound/usb/qcom/qc_audio_offload.c
@@ -1140,7 +1140,7 @@ uaudio_endpoint_setup(struct snd_usb_substream *subs,
 	ret = xhci_sideband_add_endpoint(uadev[card_num].sb, ep);
 	if (ret < 0) {
 		dev_err(&subs->dev->dev,
-			"failed to add data ep to sec intr\n");
+			"failed to add data ep to sec intr: %d\n", ret);
 		ret = -ENODEV;
 		goto exit;
 	}
@@ -1148,7 +1148,7 @@ uaudio_endpoint_setup(struct snd_usb_substream *subs,
 	sgt = xhci_sideband_get_endpoint_buffer(uadev[card_num].sb, ep);
 	if (!sgt) {
 		dev_err(&subs->dev->dev,
-			"failed to get data ep ring address\n");
+			"failed to get data ep ring address: %d\n", ret);
 		ret = -ENODEV;
 		goto remove_ep;
 	}
-- 
2.25.1


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

* [PATCH 2/4] ALSA: usb-audio: qcom: Use snprintf for mixer control name formatting
  2026-06-03  9:10 [PATCH 1/4] ALSA: usb-audio: qcom: Improve error logging in USB offload wangdich9700
@ 2026-06-03  9:11 ` wangdich9700
  2026-06-03  9:11 ` [PATCH 3/4] ALSA: usb-audio: qcom: Fix return value in qc_usb_audio_offload_fill_avail_pcms wangdich9700
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: wangdich9700 @ 2026-06-03  9:11 UTC (permalink / raw)
  To: tiwai, perex, wangdicheng, wangdich9700; +Cc: linux-sound, linux-kernel

From: wangdicheng <wangdicheng@kylinos.cn>

The current code uses sprintf() to format control names without bounds
checking, which could lead to buffer overflow if PCM index is large.
Replace sprintf with snprintf to ensure buffer safety.

The ctl_name buffer is 48 bytes, and the formatted string could exceed
this with large PCM index values. Using snprintf with sizeof(ctl_name)
prevents potential buffer overflow.

Signed-off-by: wangdicheng <wangdicheng@kylinos.cn>
---
 sound/usb/qcom/mixer_usb_offload.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sound/usb/qcom/mixer_usb_offload.c b/sound/usb/qcom/mixer_usb_offload.c
index 2adeb64f4d33..48e55d5872d5 100644
--- a/sound/usb/qcom/mixer_usb_offload.c
+++ b/sound/usb/qcom/mixer_usb_offload.c
@@ -128,7 +128,7 @@ int snd_usb_offload_create_ctl(struct snd_usb_audio *chip, struct device *bedev)
 		 */
 		chip_kctl->private_value = as->pcm_index |
 					  chip->card->number << 16;
-		sprintf(ctl_name, "USB Offload Playback Card Route PCM#%d",
+		snprintf(ctl_name, sizeof(ctl_name), "USB Offload Playback Card Route PCM#%d",
 			as->pcm_index);
 		chip_kctl->name = ctl_name;
 		ret = snd_ctl_add(chip->card, snd_ctl_new1(chip_kctl, bedev));
@@ -143,7 +143,7 @@ int snd_usb_offload_create_ctl(struct snd_usb_audio *chip, struct device *bedev)
 		 */
 		chip_kctl->private_value = as->pcm_index |
 					  chip->card->number << 16;
-		sprintf(ctl_name, "USB Offload Playback PCM Route PCM#%d",
+		snprintf(ctl_name, sizeof(ctl_name), "USB Offload Playback PCM Route PCM#%d",
 			as->pcm_index);
 		chip_kctl->name = ctl_name;
 		ret = snd_ctl_add(chip->card, snd_ctl_new1(chip_kctl, bedev));
-- 
2.25.1


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

* [PATCH 3/4] ALSA: usb-audio: qcom: Fix return value in qc_usb_audio_offload_fill_avail_pcms
  2026-06-03  9:10 [PATCH 1/4] ALSA: usb-audio: qcom: Improve error logging in USB offload wangdich9700
  2026-06-03  9:11 ` [PATCH 2/4] ALSA: usb-audio: qcom: Use snprintf for mixer control name formatting wangdich9700
@ 2026-06-03  9:11 ` wangdich9700
  2026-06-03  9:11 ` [PATCH 4/4] ALSA: usb-audio: qcom: Use PAGE_ALIGN macro for buffer size calculation wangdich9700
  2026-06-04  8:16 ` [PATCH 1/4] ALSA: usb-audio: qcom: Improve error logging in USB offload Takashi Iwai
  3 siblings, 0 replies; 5+ messages in thread
From: wangdich9700 @ 2026-06-03  9:11 UTC (permalink / raw)
  To: tiwai, perex, wangdicheng, wangdich9700; +Cc: linux-sound, linux-kernel

From: wangdicheng <wangdicheng@kylinos.cn>

The function qc_usb_audio_offload_fill_avail_pcms() always returns -1
regardless of how many PCM devices were successfully filled. This makes
it impossible for callers to know the actual number of available PCMs.

Return the actual count of filled PCM devices instead, which allows
callers to verify that all expected PCMs were properly enumerated.

Signed-off-by: wangdicheng <wangdicheng@kylinos.cn>
---
 sound/usb/qcom/qc_audio_offload.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sound/usb/qcom/qc_audio_offload.c b/sound/usb/qcom/qc_audio_offload.c
index f99f8bddb237..fa7ee61d6934 100644
--- a/sound/usb/qcom/qc_audio_offload.c
+++ b/sound/usb/qcom/qc_audio_offload.c
@@ -1753,7 +1753,7 @@ static int qc_usb_audio_offload_fill_avail_pcms(struct snd_usb_audio *chip,
 			break;
 	}
 
-	return -1;
+	return idx;
 }
 
 /**
-- 
2.25.1


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

* [PATCH 4/4] ALSA: usb-audio: qcom: Use PAGE_ALIGN macro for buffer size calculation
  2026-06-03  9:10 [PATCH 1/4] ALSA: usb-audio: qcom: Improve error logging in USB offload wangdich9700
  2026-06-03  9:11 ` [PATCH 2/4] ALSA: usb-audio: qcom: Use snprintf for mixer control name formatting wangdich9700
  2026-06-03  9:11 ` [PATCH 3/4] ALSA: usb-audio: qcom: Fix return value in qc_usb_audio_offload_fill_avail_pcms wangdich9700
@ 2026-06-03  9:11 ` wangdich9700
  2026-06-04  8:16 ` [PATCH 1/4] ALSA: usb-audio: qcom: Improve error logging in USB offload Takashi Iwai
  3 siblings, 0 replies; 5+ messages in thread
From: wangdich9700 @ 2026-06-03  9:11 UTC (permalink / raw)
  To: tiwai, perex, wangdicheng, wangdich9700; +Cc: linux-sound, linux-kernel

From: wangdicheng <wangdicheng@kylinos.cn>

Use the kernel's PAGE_ALIGN() macro instead of open-coding the page
alignment calculation. This improves code readability and follows
kernel coding style.

The manual calculation:
  mult = len / PAGE_SIZE;
  remainder = len % PAGE_SIZE;
  len = mult * PAGE_SIZE;
  len += remainder ? PAGE_SIZE : 0;

is equivalent to:
  len = PAGE_ALIGN(len);

Signed-off-by: wangdicheng <wangdicheng@kylinos.cn>
---
 sound/usb/qcom/qc_audio_offload.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/sound/usb/qcom/qc_audio_offload.c b/sound/usb/qcom/qc_audio_offload.c
index fa7ee61d6934..32982318fbed 100644
--- a/sound/usb/qcom/qc_audio_offload.c
+++ b/sound/usb/qcom/qc_audio_offload.c
@@ -1052,10 +1052,7 @@ static int uaudio_transfer_buffer_setup(struct snd_usb_substream *subs,
 	if (!len)
 		len = PAGE_SIZE;
 
-	mult = len / PAGE_SIZE;
-	remainder = len % PAGE_SIZE;
-	len = mult * PAGE_SIZE;
-	len += remainder ? PAGE_SIZE : 0;
+	len = PAGE_ALIGN(len);
 
 	if (len > MAX_XFER_BUFF_LEN) {
 		dev_err(uaudio_qdev->data->dev,
-- 
2.25.1


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

* Re: [PATCH 1/4] ALSA: usb-audio: qcom: Improve error logging in USB offload
  2026-06-03  9:10 [PATCH 1/4] ALSA: usb-audio: qcom: Improve error logging in USB offload wangdich9700
                   ` (2 preceding siblings ...)
  2026-06-03  9:11 ` [PATCH 4/4] ALSA: usb-audio: qcom: Use PAGE_ALIGN macro for buffer size calculation wangdich9700
@ 2026-06-04  8:16 ` Takashi Iwai
  3 siblings, 0 replies; 5+ messages in thread
From: Takashi Iwai @ 2026-06-04  8:16 UTC (permalink / raw)
  To: wangdich9700; +Cc: tiwai, perex, wangdicheng, linux-sound, linux-kernel

On Wed, 03 Jun 2026 11:10:59 +0200,
wangdich9700@163.com wrote:
> 
> From: wangdicheng <wangdicheng@kylinos.cn>
> 
> Add error codes to error messages for better debugging.
> This helps identify the root cause when USB audio offload fails.
> 
> Error messages now include the actual error code returned by
> xhci_sideband operations, making it easier to diagnose failures
> during USB audio offload setup.
> 
> Signed-off-by: wangdicheng <wangdicheng@kylinos.cn>

Applied all four patches to for-next branch now.

But, at the next time, when there are a series of patches, please give
a cover letter to understand better the big picture.


thanks,

Takashi

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

end of thread, other threads:[~2026-06-04  8:16 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-03  9:10 [PATCH 1/4] ALSA: usb-audio: qcom: Improve error logging in USB offload wangdich9700
2026-06-03  9:11 ` [PATCH 2/4] ALSA: usb-audio: qcom: Use snprintf for mixer control name formatting wangdich9700
2026-06-03  9:11 ` [PATCH 3/4] ALSA: usb-audio: qcom: Fix return value in qc_usb_audio_offload_fill_avail_pcms wangdich9700
2026-06-03  9:11 ` [PATCH 4/4] ALSA: usb-audio: qcom: Use PAGE_ALIGN macro for buffer size calculation wangdich9700
2026-06-04  8:16 ` [PATCH 1/4] ALSA: usb-audio: qcom: Improve error logging in USB offload Takashi Iwai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox