Skip to content

Commit 0ba41d9

Browse files
committed
ALSA: usb-audio: Use standard printk helpers
Convert with dev_err() and co from snd_printk(), etc. As there are too deep indirections (e.g. ep->chip->dev->dev), a few new local macros, usb_audio_err() & co, are introduced. Also, the device numbers in some messages are dropped, as they are shown in the prefix automatically. Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent 6436bcf commit 0ba41d9

11 files changed

Lines changed: 325 additions & 254 deletions

File tree

‎sound/usb/card.c‎

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ static int snd_usb_create_stream(struct snd_usb_audio *chip, int ctrlif, int int
139139
struct usb_interface *iface = usb_ifnum_to_if(dev, interface);
140140

141141
if (!iface) {
142-
snd_printk(KERN_ERR "%d:%u:%d : does not exist\n",
143-
dev->devnum, ctrlif, interface);
142+
dev_err(&dev->dev, "%u:%d : does not exist\n",
143+
ctrlif, interface);
144144
return -EINVAL;
145145
}
146146

@@ -165,8 +165,8 @@ static int snd_usb_create_stream(struct snd_usb_audio *chip, int ctrlif, int int
165165
}
166166

167167
if (usb_interface_claimed(iface)) {
168-
snd_printdd(KERN_INFO "%d:%d:%d: skipping, already claimed\n",
169-
dev->devnum, ctrlif, interface);
168+
dev_dbg(&dev->dev, "%d:%d: skipping, already claimed\n",
169+
ctrlif, interface);
170170
return -EINVAL;
171171
}
172172

@@ -176,8 +176,9 @@ static int snd_usb_create_stream(struct snd_usb_audio *chip, int ctrlif, int int
176176
int err = snd_usbmidi_create(chip->card, iface,
177177
&chip->midi_list, NULL);
178178
if (err < 0) {
179-
snd_printk(KERN_ERR "%d:%u:%d: cannot create sequencer device\n",
180-
dev->devnum, ctrlif, interface);
179+
dev_err(&dev->dev,
180+
"%u:%d: cannot create sequencer device\n",
181+
ctrlif, interface);
181182
return -EINVAL;
182183
}
183184
usb_driver_claim_interface(&usb_audio_driver, iface, (void *)-1L);
@@ -188,14 +189,15 @@ static int snd_usb_create_stream(struct snd_usb_audio *chip, int ctrlif, int int
188189
if ((altsd->bInterfaceClass != USB_CLASS_AUDIO &&
189190
altsd->bInterfaceClass != USB_CLASS_VENDOR_SPEC) ||
190191
altsd->bInterfaceSubClass != USB_SUBCLASS_AUDIOSTREAMING) {
191-
snd_printdd(KERN_ERR "%d:%u:%d: skipping non-supported interface %d\n",
192-
dev->devnum, ctrlif, interface, altsd->bInterfaceClass);
192+
dev_dbg(&dev->dev,
193+
"%u:%d: skipping non-supported interface %d\n",
194+
ctrlif, interface, altsd->bInterfaceClass);
193195
/* skip non-supported classes */
194196
return -EINVAL;
195197
}
196198

197199
if (snd_usb_get_speed(dev) == USB_SPEED_LOW) {
198-
snd_printk(KERN_ERR "low speed audio streaming not supported\n");
200+
dev_err(&dev->dev, "low speed audio streaming not supported\n");
199201
return -EINVAL;
200202
}
201203

@@ -228,26 +230,27 @@ static int snd_usb_create_streams(struct snd_usb_audio *chip, int ctrlif)
228230
protocol = altsd->bInterfaceProtocol;
229231

230232
if (!control_header) {
231-
snd_printk(KERN_ERR "cannot find UAC_HEADER\n");
233+
dev_err(&dev->dev, "cannot find UAC_HEADER\n");
232234
return -EINVAL;
233235
}
234236

235237
switch (protocol) {
236238
default:
237-
snd_printdd(KERN_WARNING "unknown interface protocol %#02x, assuming v1\n",
238-
protocol);
239+
dev_warn(&dev->dev,
240+
"unknown interface protocol %#02x, assuming v1\n",
241+
protocol);
239242
/* fall through */
240243

241244
case UAC_VERSION_1: {
242245
struct uac1_ac_header_descriptor *h1 = control_header;
243246

244247
if (!h1->bInCollection) {
245-
snd_printk(KERN_INFO "skipping empty audio interface (v1)\n");
248+
dev_info(&dev->dev, "skipping empty audio interface (v1)\n");
246249
return -EINVAL;
247250
}
248251

249252
if (h1->bLength < sizeof(*h1) + h1->bInCollection) {
250-
snd_printk(KERN_ERR "invalid UAC_HEADER (v1)\n");
253+
dev_err(&dev->dev, "invalid UAC_HEADER (v1)\n");
251254
return -EINVAL;
252255
}
253256

@@ -277,7 +280,7 @@ static int snd_usb_create_streams(struct snd_usb_audio *chip, int ctrlif)
277280
}
278281

279282
if (!assoc) {
280-
snd_printk(KERN_ERR "Audio class v2 interfaces need an interface association\n");
283+
dev_err(&dev->dev, "Audio class v2 interfaces need an interface association\n");
281284
return -EINVAL;
282285
}
283286

@@ -351,14 +354,14 @@ static int snd_usb_audio_create(struct usb_interface *intf,
351354
case USB_SPEED_SUPER:
352355
break;
353356
default:
354-
snd_printk(KERN_ERR "unknown device speed %d\n", snd_usb_get_speed(dev));
357+
dev_err(&dev->dev, "unknown device speed %d\n", snd_usb_get_speed(dev));
355358
return -ENXIO;
356359
}
357360

358361
err = snd_card_new(&intf->dev, index[idx], id[idx], THIS_MODULE,
359362
0, &card);
360363
if (err < 0) {
361-
snd_printk(KERN_ERR "cannot create card instance %d\n", idx);
364+
dev_err(&dev->dev, "cannot create card instance %d\n", idx);
362365
return err;
363366
}
364367

@@ -499,7 +502,7 @@ snd_usb_audio_probe(struct usb_device *dev,
499502
for (i = 0; i < SNDRV_CARDS; i++) {
500503
if (usb_chip[i] && usb_chip[i]->dev == dev) {
501504
if (usb_chip[i]->shutdown) {
502-
snd_printk(KERN_ERR "USB device is in the shutdown state, cannot create a card instance\n");
505+
dev_err(&dev->dev, "USB device is in the shutdown state, cannot create a card instance\n");
503506
goto __error;
504507
}
505508
chip = usb_chip[i];
@@ -523,7 +526,7 @@ snd_usb_audio_probe(struct usb_device *dev,
523526
break;
524527
}
525528
if (!chip) {
526-
printk(KERN_ERR "no available usb audio device\n");
529+
dev_err(&dev->dev, "no available usb audio device\n");
527530
goto __error;
528531
}
529532
}

‎sound/usb/clock.c‎

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ static int uac_clock_selector_set_val(struct snd_usb_audio *chip, int selector_i
115115
return ret;
116116

117117
if (ret != sizeof(pin)) {
118-
snd_printk(KERN_ERR
119-
"usb-audio:%d: setting selector (id %d) unexpected length %d\n",
120-
chip->dev->devnum, selector_id, ret);
118+
usb_audio_err(chip,
119+
"setting selector (id %d) unexpected length %d\n",
120+
selector_id, ret);
121121
return -EINVAL;
122122
}
123123

@@ -126,9 +126,9 @@ static int uac_clock_selector_set_val(struct snd_usb_audio *chip, int selector_i
126126
return ret;
127127

128128
if (ret != pin) {
129-
snd_printk(KERN_ERR
130-
"usb-audio:%d: setting selector (id %d) to %x failed (current: %d)\n",
131-
chip->dev->devnum, selector_id, pin, ret);
129+
usb_audio_err(chip,
130+
"setting selector (id %d) to %x failed (current: %d)\n",
131+
selector_id, pin, ret);
132132
return -EINVAL;
133133
}
134134

@@ -158,7 +158,8 @@ static bool uac_clock_source_is_valid(struct snd_usb_audio *chip, int source_id)
158158
&data, sizeof(data));
159159

160160
if (err < 0) {
161-
snd_printk(KERN_WARNING "%s(): cannot get clock validity for id %d\n",
161+
dev_warn(&dev->dev,
162+
"%s(): cannot get clock validity for id %d\n",
162163
__func__, source_id);
163164
return 0;
164165
}
@@ -177,9 +178,9 @@ static int __uac_clock_find_source(struct snd_usb_audio *chip,
177178
entity_id &= 0xff;
178179

179180
if (test_and_set_bit(entity_id, visited)) {
180-
snd_printk(KERN_WARNING
181-
"%s(): recursive clock topology detected, id %d.\n",
182-
__func__, entity_id);
181+
usb_audio_warn(chip,
182+
"%s(): recursive clock topology detected, id %d.\n",
183+
__func__, entity_id);
183184
return -EINVAL;
184185
}
185186

@@ -188,8 +189,9 @@ static int __uac_clock_find_source(struct snd_usb_audio *chip,
188189
if (source) {
189190
entity_id = source->bClockID;
190191
if (validate && !uac_clock_source_is_valid(chip, entity_id)) {
191-
snd_printk(KERN_ERR "usb-audio:%d: clock source %d is not valid, cannot use\n",
192-
chip->dev->devnum, entity_id);
192+
usb_audio_err(chip,
193+
"clock source %d is not valid, cannot use\n",
194+
entity_id);
193195
return -ENXIO;
194196
}
195197
return entity_id;
@@ -208,7 +210,7 @@ static int __uac_clock_find_source(struct snd_usb_audio *chip,
208210
/* Selector values are one-based */
209211

210212
if (ret > selector->bNrInPins || ret < 1) {
211-
snd_printk(KERN_ERR
213+
usb_audio_err(chip,
212214
"%s(): selector reported illegal value, id %d, ret %d\n",
213215
__func__, selector->bClockID, ret);
214216

@@ -237,9 +239,9 @@ static int __uac_clock_find_source(struct snd_usb_audio *chip,
237239
if (err < 0)
238240
continue;
239241

240-
snd_printk(KERN_INFO
241-
"usb-audio:%d: found and selected valid clock source %d\n",
242-
chip->dev->devnum, ret);
242+
usb_audio_info(chip,
243+
"found and selected valid clock source %d\n",
244+
ret);
243245
return ret;
244246
}
245247

@@ -296,23 +298,23 @@ static int set_sample_rate_v1(struct snd_usb_audio *chip, int iface,
296298
USB_TYPE_CLASS | USB_RECIP_ENDPOINT | USB_DIR_OUT,
297299
UAC_EP_CS_ATTR_SAMPLE_RATE << 8, ep,
298300
data, sizeof(data))) < 0) {
299-
snd_printk(KERN_ERR "%d:%d:%d: cannot set freq %d to ep %#x\n",
300-
dev->devnum, iface, fmt->altsetting, rate, ep);
301+
dev_err(&dev->dev, "%d:%d: cannot set freq %d to ep %#x\n",
302+
iface, fmt->altsetting, rate, ep);
301303
return err;
302304
}
303305

304306
if ((err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC_GET_CUR,
305307
USB_TYPE_CLASS | USB_RECIP_ENDPOINT | USB_DIR_IN,
306308
UAC_EP_CS_ATTR_SAMPLE_RATE << 8, ep,
307309
data, sizeof(data))) < 0) {
308-
snd_printk(KERN_WARNING "%d:%d:%d: cannot get freq at ep %#x\n",
309-
dev->devnum, iface, fmt->altsetting, ep);
310+
dev_err(&dev->dev, "%d:%d: cannot get freq at ep %#x\n",
311+
iface, fmt->altsetting, ep);
310312
return 0; /* some devices don't support reading */
311313
}
312314

313315
crate = data[0] | (data[1] << 8) | (data[2] << 16);
314316
if (crate != rate) {
315-
snd_printd(KERN_WARNING "current rate %d is different from the runtime rate %d\n", crate, rate);
317+
dev_warn(&dev->dev, "current rate %d is different from the runtime rate %d\n", crate, rate);
316318
// runtime->rate = crate;
317319
}
318320

@@ -332,8 +334,8 @@ static int get_sample_rate_v2(struct snd_usb_audio *chip, int iface,
332334
snd_usb_ctrl_intf(chip) | (clock << 8),
333335
&data, sizeof(data));
334336
if (err < 0) {
335-
snd_printk(KERN_WARNING "%d:%d:%d: cannot get freq (v2): err %d\n",
336-
dev->devnum, iface, altsetting, err);
337+
dev_warn(&dev->dev, "%d:%d: cannot get freq (v2): err %d\n",
338+
iface, altsetting, err);
337339
return 0;
338340
}
339341

@@ -369,8 +371,9 @@ static int set_sample_rate_v2(struct snd_usb_audio *chip, int iface,
369371
snd_usb_ctrl_intf(chip) | (clock << 8),
370372
&data, sizeof(data));
371373
if (err < 0) {
372-
snd_printk(KERN_ERR "%d:%d:%d: cannot set freq %d (v2): err %d\n",
373-
dev->devnum, iface, fmt->altsetting, rate, err);
374+
usb_audio_err(chip,
375+
"%d:%d: cannot set freq %d (v2): err %d\n",
376+
iface, fmt->altsetting, rate, err);
374377
return err;
375378
}
376379

@@ -381,14 +384,14 @@ static int set_sample_rate_v2(struct snd_usb_audio *chip, int iface,
381384

382385
if (cur_rate != rate) {
383386
if (!writeable) {
384-
snd_printk(KERN_WARNING
385-
"%d:%d:%d: freq mismatch (RO clock): req %d, clock runs @%d\n",
386-
dev->devnum, iface, fmt->altsetting, rate, cur_rate);
387+
usb_audio_warn(chip,
388+
"%d:%d: freq mismatch (RO clock): req %d, clock runs @%d\n",
389+
iface, fmt->altsetting, rate, cur_rate);
387390
return -ENXIO;
388391
}
389-
snd_printd(KERN_WARNING
390-
"current rate %d is different from the runtime rate %d\n",
391-
cur_rate, rate);
392+
usb_audio_dbg(chip,
393+
"current rate %d is different from the runtime rate %d\n",
394+
cur_rate, rate);
392395
}
393396

394397
/* Some devices doesn't respond to sample rate changes while the

‎sound/usb/endpoint.c‎

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,9 @@ static void queue_pending_output_urbs(struct snd_usb_endpoint *ep)
333333

334334
err = usb_submit_urb(ctx->urb, GFP_ATOMIC);
335335
if (err < 0)
336-
snd_printk(KERN_ERR "Unable to submit urb #%d: %d (urb %p)\n",
337-
ctx->index, err, ctx->urb);
336+
usb_audio_err(ep->chip,
337+
"Unable to submit urb #%d: %d (urb %p)\n",
338+
ctx->index, err, ctx->urb);
338339
else
339340
set_bit(ctx->index, &ep->active_mask);
340341
}
@@ -387,7 +388,7 @@ static void snd_complete_urb(struct urb *urb)
387388
if (err == 0)
388389
return;
389390

390-
snd_printk(KERN_ERR "cannot submit urb (err = %d)\n", err);
391+
usb_audio_err(ep->chip, "cannot submit urb (err = %d)\n", err);
391392
//snd_pcm_stop(substream, SNDRV_PCM_STATE_XRUN);
392393

393394
exit_clear:
@@ -426,13 +427,14 @@ struct snd_usb_endpoint *snd_usb_add_endpoint(struct snd_usb_audio *chip,
426427
if (ep->ep_num == ep_num &&
427428
ep->iface == alts->desc.bInterfaceNumber &&
428429
ep->altsetting == alts->desc.bAlternateSetting) {
429-
snd_printdd(KERN_DEBUG "Re-using EP %x in iface %d,%d @%p\n",
430+
usb_audio_dbg(ep->chip,
431+
"Re-using EP %x in iface %d,%d @%p\n",
430432
ep_num, ep->iface, ep->altsetting, ep);
431433
goto __exit_unlock;
432434
}
433435
}
434436

435-
snd_printdd(KERN_DEBUG "Creating new %s %s endpoint #%x\n",
437+
usb_audio_dbg(chip, "Creating new %s %s endpoint #%x\n",
436438
is_playback ? "playback" : "capture",
437439
type == SND_USB_ENDPOINT_TYPE_DATA ? "data" : "sync",
438440
ep_num);
@@ -496,8 +498,9 @@ static int wait_clear_urbs(struct snd_usb_endpoint *ep)
496498
} while (time_before(jiffies, end_time));
497499

498500
if (alive)
499-
snd_printk(KERN_ERR "timeout: still %d active urbs on EP #%x\n",
500-
alive, ep->ep_num);
501+
usb_audio_err(ep->chip,
502+
"timeout: still %d active urbs on EP #%x\n",
503+
alive, ep->ep_num);
501504
clear_bit(EP_FLAG_STOPPING, &ep->flags);
502505

503506
return 0;
@@ -794,8 +797,9 @@ int snd_usb_endpoint_set_params(struct snd_usb_endpoint *ep,
794797
int err;
795798

796799
if (ep->use_count != 0) {
797-
snd_printk(KERN_WARNING "Unable to change format on ep #%x: already in use\n",
798-
ep->ep_num);
800+
usb_audio_warn(ep->chip,
801+
"Unable to change format on ep #%x: already in use\n",
802+
ep->ep_num);
799803
return -EBUSY;
800804
}
801805

@@ -830,8 +834,9 @@ int snd_usb_endpoint_set_params(struct snd_usb_endpoint *ep,
830834
err = -EINVAL;
831835
}
832836

833-
snd_printdd(KERN_DEBUG "Setting params for ep #%x (type %d, %d urbs), ret=%d\n",
834-
ep->ep_num, ep->type, ep->nurbs, err);
837+
usb_audio_dbg(ep->chip,
838+
"Setting params for ep #%x (type %d, %d urbs), ret=%d\n",
839+
ep->ep_num, ep->type, ep->nurbs, err);
835840

836841
return err;
837842
}
@@ -906,8 +911,9 @@ int snd_usb_endpoint_start(struct snd_usb_endpoint *ep, bool can_sleep)
906911

907912
err = usb_submit_urb(urb, GFP_ATOMIC);
908913
if (err < 0) {
909-
snd_printk(KERN_ERR "cannot submit urb %d, error %d: %s\n",
910-
i, err, usb_error_string(err));
914+
usb_audio_err(ep->chip,
915+
"cannot submit urb %d, error %d: %s\n",
916+
i, err, usb_error_string(err));
911917
goto __error;
912918
}
913919
set_bit(i, &ep->active_mask);

0 commit comments

Comments
 (0)