* [PATCH] ALSA: usb-audio: Support read-only clock selector control
@ 2024-01-25 20:54 Alexander Tsoy
2024-01-26 15:07 ` Takashi Iwai
0 siblings, 1 reply; 2+ messages in thread
From: Alexander Tsoy @ 2024-01-25 20:54 UTC (permalink / raw)
To: linux-sound; +Cc: alsa-devel
Clock selector control might be read-only. Add corresponding checks
to prevent sending control requests that would fail.
Signed-off-by: Alexander Tsoy <alexander@tsoy.me>
---
sound/usb/clock.c | 23 ++++++++++++++++++++++-
1 file changed, 22 insertions(+), 1 deletion(-)
diff --git a/sound/usb/clock.c b/sound/usb/clock.c
index 94e4aaeafe58..7b259641adb5 100644
--- a/sound/usb/clock.c
+++ b/sound/usb/clock.c
@@ -261,6 +261,8 @@ static int __uac_clock_find_source(struct snd_usb_audio *chip,
int ret, i, cur, err, pins, clock_id;
const u8 *sources;
int proto = fmt->protocol;
+ bool readable, writeable;
+ u32 bmControls;
entity_id &= 0xff;
@@ -292,11 +294,27 @@ static int __uac_clock_find_source(struct snd_usb_audio *chip,
sources = GET_VAL(selector, proto, baCSourceID);
cur = 0;
+ if (proto == UAC_VERSION_3)
+ bmControls = le32_to_cpu(*(__le32 *)(&selector->v3.baCSourceID[0] + pins));
+ else
+ bmControls = *(__u8 *)(&selector->v2.baCSourceID[0] + pins);
+
+ readable = uac_v2v3_control_is_readable(bmControls,
+ UAC2_CX_CLOCK_SELECTOR);
+ writeable = uac_v2v3_control_is_writeable(bmControls,
+ UAC2_CX_CLOCK_SELECTOR);
+
if (pins == 1) {
ret = 1;
goto find_source;
}
+ /* for now just warn about buggy device */
+ if (!readable)
+ usb_audio_warn(chip,
+ "%s(): clock selector control is not readable, id %d\n",
+ __func__, clock_id);
+
/* the entity ID we are looking at is a selector.
* find out what it currently selects */
ret = uac_clock_selector_get_val(chip, clock_id);
@@ -326,7 +344,7 @@ static int __uac_clock_find_source(struct snd_usb_audio *chip,
if (ret > 0) {
/* Skip setting clock selector again for some devices */
if (chip->quirk_flags & QUIRK_FLAG_SKIP_CLOCK_SELECTOR ||
- pins == 1)
+ pins == 1 || !writeable)
return ret;
err = uac_clock_selector_set_val(chip, entity_id, cur);
if (err < 0)
@@ -337,6 +355,9 @@ static int __uac_clock_find_source(struct snd_usb_audio *chip,
return ret;
find_others:
+ if (!writeable)
+ return -ENXIO;
+
/* The current clock source is invalid, try others. */
for (i = 1; i <= pins; i++) {
if (i == cur)
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] ALSA: usb-audio: Support read-only clock selector control
2024-01-25 20:54 [PATCH] ALSA: usb-audio: Support read-only clock selector control Alexander Tsoy
@ 2024-01-26 15:07 ` Takashi Iwai
0 siblings, 0 replies; 2+ messages in thread
From: Takashi Iwai @ 2024-01-26 15:07 UTC (permalink / raw)
To: Alexander Tsoy; +Cc: linux-sound, alsa-devel
On Thu, 25 Jan 2024 21:54:57 +0100,
Alexander Tsoy wrote:
>
> Clock selector control might be read-only. Add corresponding checks
> to prevent sending control requests that would fail.
>
> Signed-off-by: Alexander Tsoy <alexander@tsoy.me>
Thanks, applied.
Takashi
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-01-26 15:08 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-25 20:54 [PATCH] ALSA: usb-audio: Support read-only clock selector control Alexander Tsoy
2024-01-26 15:07 ` Takashi Iwai
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.