Commit 06ffc1ebddbed88662a47646ff6aa6a2b41f0aec

Authored by Eldad Zack
Committed by Takashi Iwai
1 parent f6a8bc70f8

ALSA: usb-audio: UAC2: do clock validity check earlier

Move the check that parse_audio_format_rates_v2() do after
receiving the clock source entity ID directly into the find
function and add a validation flag to the function.

This patch does not introduce any logic flow change.

It is provided to allow introducing automatic clock switching
easier later. By moving this uac_clock_source_is_valid callsite,
2 additional callsites can be avoided.

Signed-off-by: Eldad Zack <eldad@fogrefinery.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>

Showing 3 changed files with 21 additions and 18 deletions Side-by-side Diff

... ... @@ -131,7 +131,8 @@
131 131 }
132 132  
133 133 static int __uac_clock_find_source(struct snd_usb_audio *chip,
134   - int entity_id, unsigned long *visited)
  134 + int entity_id, unsigned long *visited,
  135 + bool validate)
135 136 {
136 137 struct uac_clock_source_descriptor *source;
137 138 struct uac_clock_selector_descriptor *selector;
... ... @@ -148,8 +149,15 @@
148 149  
149 150 /* first, see if the ID we're looking for is a clock source already */
150 151 source = snd_usb_find_clock_source(chip->ctrl_intf, entity_id);
151   - if (source)
152   - return source->bClockID;
  152 + if (source) {
  153 + entity_id = source->bClockID;
  154 + if (validate && !uac_clock_source_is_valid(chip, entity_id)) {
  155 + snd_printk(KERN_ERR "usb-audio:%d: clock source %d is not valid, cannot use\n",
  156 + chip->dev->devnum, entity_id);
  157 + return -ENXIO;
  158 + }
  159 + return entity_id;
  160 + }
153 161  
154 162 selector = snd_usb_find_clock_selector(chip->ctrl_intf, entity_id);
155 163 if (selector) {
... ... @@ -164,7 +172,7 @@
164 172 /* Selector values are one-based */
165 173  
166 174 if (ret > selector->bNrInPins || ret < 1) {
167   - printk(KERN_ERR
  175 + snd_printk(KERN_ERR
168 176 "%s(): selector reported illegal value, id %d, ret %d\n",
169 177 __func__, selector->bClockID, ret);
170 178  
171 179  
... ... @@ -172,14 +180,14 @@
172 180 }
173 181  
174 182 return __uac_clock_find_source(chip, selector->baCSourceID[ret-1],
175   - visited);
  183 + visited, validate);
176 184 }
177 185  
178 186 /* FIXME: multipliers only act as pass-thru element for now */
179 187 multiplier = snd_usb_find_clock_multiplier(chip->ctrl_intf, entity_id);
180 188 if (multiplier)
181 189 return __uac_clock_find_source(chip, multiplier->bCSourceID,
182   - visited);
  190 + visited, validate);
183 191  
184 192 return -EINVAL;
185 193 }
186 194  
... ... @@ -195,11 +203,12 @@
195 203 *
196 204 * Returns the clock source UnitID (>=0) on success, or an error.
197 205 */
198   -int snd_usb_clock_find_source(struct snd_usb_audio *chip, int entity_id)
  206 +int snd_usb_clock_find_source(struct snd_usb_audio *chip, int entity_id,
  207 + bool validate)
199 208 {
200 209 DECLARE_BITMAP(visited, 256);
201 210 memset(visited, 0, sizeof(visited));
202   - return __uac_clock_find_source(chip, entity_id, visited);
  211 + return __uac_clock_find_source(chip, entity_id, visited, validate);
203 212 }
204 213  
205 214 static int set_sample_rate_v1(struct snd_usb_audio *chip, int iface,
206 215  
... ... @@ -275,17 +284,10 @@
275 284 struct usb_device *dev = chip->dev;
276 285 __le32 data;
277 286 int err, cur_rate, prev_rate;
278   - int clock = snd_usb_clock_find_source(chip, fmt->clock);
  287 + int clock = snd_usb_clock_find_source(chip, fmt->clock, true);
279 288  
280 289 if (clock < 0)
281 290 return clock;
282   -
283   - if (!uac_clock_source_is_valid(chip, clock)) {
284   - /* TODO: should we try to find valid clock setups by ourself? */
285   - snd_printk(KERN_ERR "%d:%d:%d: clock source %d is not valid, cannot use\n",
286   - dev->devnum, iface, fmt->altsetting, clock);
287   - return -ENXIO;
288   - }
289 291  
290 292 prev_rate = get_sample_rate_v2(chip, iface, fmt->altsetting, clock);
291 293  
... ... @@ -5,7 +5,8 @@
5 5 struct usb_host_interface *alts,
6 6 struct audioformat *fmt, int rate);
7 7  
8   -int snd_usb_clock_find_source(struct snd_usb_audio *chip, int entity_id);
  8 +int snd_usb_clock_find_source(struct snd_usb_audio *chip, int entity_id,
  9 + bool validate);
9 10  
10 11 #endif /* __USBAUDIO_CLOCK_H */
... ... @@ -280,7 +280,7 @@
280 280 struct usb_device *dev = chip->dev;
281 281 unsigned char tmp[2], *data;
282 282 int nr_triplets, data_size, ret = 0;
283   - int clock = snd_usb_clock_find_source(chip, fp->clock);
  283 + int clock = snd_usb_clock_find_source(chip, fp->clock, false);
284 284  
285 285 if (clock < 0) {
286 286 snd_printk(KERN_ERR "%s(): unable to find clock source (clock %d)\n",