Skip to content

Commit

Permalink
ALSA: usb-audio: Use standard printk helpers
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
tiwai committed Feb 26, 2014
1 parent 6436bcf commit 0ba41d9
Show file tree
Hide file tree
Showing 11 changed files with 325 additions and 254 deletions.
41 changes: 22 additions & 19 deletions sound/usb/card.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ static int snd_usb_create_stream(struct snd_usb_audio *chip, int ctrlif, int int
struct usb_interface *iface = usb_ifnum_to_if(dev, interface);

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

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

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

Expand All @@ -176,8 +176,9 @@ static int snd_usb_create_stream(struct snd_usb_audio *chip, int ctrlif, int int
int err = snd_usbmidi_create(chip->card, iface,
&chip->midi_list, NULL);
if (err < 0) {
snd_printk(KERN_ERR "%d:%u:%d: cannot create sequencer device\n",
dev->devnum, ctrlif, interface);
dev_err(&dev->dev,
"%u:%d: cannot create sequencer device\n",
ctrlif, interface);
return -EINVAL;
}
usb_driver_claim_interface(&usb_audio_driver, iface, (void *)-1L);
Expand All @@ -188,14 +189,15 @@ static int snd_usb_create_stream(struct snd_usb_audio *chip, int ctrlif, int int
if ((altsd->bInterfaceClass != USB_CLASS_AUDIO &&
altsd->bInterfaceClass != USB_CLASS_VENDOR_SPEC) ||
altsd->bInterfaceSubClass != USB_SUBCLASS_AUDIOSTREAMING) {
snd_printdd(KERN_ERR "%d:%u:%d: skipping non-supported interface %d\n",
dev->devnum, ctrlif, interface, altsd->bInterfaceClass);
dev_dbg(&dev->dev,
"%u:%d: skipping non-supported interface %d\n",
ctrlif, interface, altsd->bInterfaceClass);
/* skip non-supported classes */
return -EINVAL;
}

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

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

if (!control_header) {
snd_printk(KERN_ERR "cannot find UAC_HEADER\n");
dev_err(&dev->dev, "cannot find UAC_HEADER\n");
return -EINVAL;
}

switch (protocol) {
default:
snd_printdd(KERN_WARNING "unknown interface protocol %#02x, assuming v1\n",
protocol);
dev_warn(&dev->dev,
"unknown interface protocol %#02x, assuming v1\n",
protocol);
/* fall through */

case UAC_VERSION_1: {
struct uac1_ac_header_descriptor *h1 = control_header;

if (!h1->bInCollection) {
snd_printk(KERN_INFO "skipping empty audio interface (v1)\n");
dev_info(&dev->dev, "skipping empty audio interface (v1)\n");
return -EINVAL;
}

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

Expand Down Expand Up @@ -277,7 +280,7 @@ static int snd_usb_create_streams(struct snd_usb_audio *chip, int ctrlif)
}

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

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

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

Expand Down Expand Up @@ -499,7 +502,7 @@ snd_usb_audio_probe(struct usb_device *dev,
for (i = 0; i < SNDRV_CARDS; i++) {
if (usb_chip[i] && usb_chip[i]->dev == dev) {
if (usb_chip[i]->shutdown) {
snd_printk(KERN_ERR "USB device is in the shutdown state, cannot create a card instance\n");
dev_err(&dev->dev, "USB device is in the shutdown state, cannot create a card instance\n");
goto __error;
}
chip = usb_chip[i];
Expand All @@ -523,7 +526,7 @@ snd_usb_audio_probe(struct usb_device *dev,
break;
}
if (!chip) {
printk(KERN_ERR "no available usb audio device\n");
dev_err(&dev->dev, "no available usb audio device\n");
goto __error;
}
}
Expand Down
65 changes: 34 additions & 31 deletions sound/usb/clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ static int uac_clock_selector_set_val(struct snd_usb_audio *chip, int selector_i
return ret;

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

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

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

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

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

if (test_and_set_bit(entity_id, visited)) {
snd_printk(KERN_WARNING
"%s(): recursive clock topology detected, id %d.\n",
__func__, entity_id);
usb_audio_warn(chip,
"%s(): recursive clock topology detected, id %d.\n",
__func__, entity_id);
return -EINVAL;
}

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

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

Expand Down Expand Up @@ -237,9 +239,9 @@ static int __uac_clock_find_source(struct snd_usb_audio *chip,
if (err < 0)
continue;

snd_printk(KERN_INFO
"usb-audio:%d: found and selected valid clock source %d\n",
chip->dev->devnum, ret);
usb_audio_info(chip,
"found and selected valid clock source %d\n",
ret);
return ret;
}

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

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

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

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

Expand Down Expand Up @@ -369,8 +371,9 @@ static int set_sample_rate_v2(struct snd_usb_audio *chip, int iface,
snd_usb_ctrl_intf(chip) | (clock << 8),
&data, sizeof(data));
if (err < 0) {
snd_printk(KERN_ERR "%d:%d:%d: cannot set freq %d (v2): err %d\n",
dev->devnum, iface, fmt->altsetting, rate, err);
usb_audio_err(chip,
"%d:%d: cannot set freq %d (v2): err %d\n",
iface, fmt->altsetting, rate, err);
return err;
}

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

if (cur_rate != rate) {
if (!writeable) {
snd_printk(KERN_WARNING
"%d:%d:%d: freq mismatch (RO clock): req %d, clock runs @%d\n",
dev->devnum, iface, fmt->altsetting, rate, cur_rate);
usb_audio_warn(chip,
"%d:%d: freq mismatch (RO clock): req %d, clock runs @%d\n",
iface, fmt->altsetting, rate, cur_rate);
return -ENXIO;
}
snd_printd(KERN_WARNING
"current rate %d is different from the runtime rate %d\n",
cur_rate, rate);
usb_audio_dbg(chip,
"current rate %d is different from the runtime rate %d\n",
cur_rate, rate);
}

/* Some devices doesn't respond to sample rate changes while the
Expand Down
32 changes: 19 additions & 13 deletions sound/usb/endpoint.c
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,9 @@ static void queue_pending_output_urbs(struct snd_usb_endpoint *ep)

err = usb_submit_urb(ctx->urb, GFP_ATOMIC);
if (err < 0)
snd_printk(KERN_ERR "Unable to submit urb #%d: %d (urb %p)\n",
ctx->index, err, ctx->urb);
usb_audio_err(ep->chip,
"Unable to submit urb #%d: %d (urb %p)\n",
ctx->index, err, ctx->urb);
else
set_bit(ctx->index, &ep->active_mask);
}
Expand Down Expand Up @@ -387,7 +388,7 @@ static void snd_complete_urb(struct urb *urb)
if (err == 0)
return;

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

exit_clear:
Expand Down Expand Up @@ -426,13 +427,14 @@ struct snd_usb_endpoint *snd_usb_add_endpoint(struct snd_usb_audio *chip,
if (ep->ep_num == ep_num &&
ep->iface == alts->desc.bInterfaceNumber &&
ep->altsetting == alts->desc.bAlternateSetting) {
snd_printdd(KERN_DEBUG "Re-using EP %x in iface %d,%d @%p\n",
usb_audio_dbg(ep->chip,
"Re-using EP %x in iface %d,%d @%p\n",
ep_num, ep->iface, ep->altsetting, ep);
goto __exit_unlock;
}
}

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

if (alive)
snd_printk(KERN_ERR "timeout: still %d active urbs on EP #%x\n",
alive, ep->ep_num);
usb_audio_err(ep->chip,
"timeout: still %d active urbs on EP #%x\n",
alive, ep->ep_num);
clear_bit(EP_FLAG_STOPPING, &ep->flags);

return 0;
Expand Down Expand Up @@ -794,8 +797,9 @@ int snd_usb_endpoint_set_params(struct snd_usb_endpoint *ep,
int err;

if (ep->use_count != 0) {
snd_printk(KERN_WARNING "Unable to change format on ep #%x: already in use\n",
ep->ep_num);
usb_audio_warn(ep->chip,
"Unable to change format on ep #%x: already in use\n",
ep->ep_num);
return -EBUSY;
}

Expand Down Expand Up @@ -830,8 +834,9 @@ int snd_usb_endpoint_set_params(struct snd_usb_endpoint *ep,
err = -EINVAL;
}

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

return err;
}
Expand Down Expand Up @@ -906,8 +911,9 @@ int snd_usb_endpoint_start(struct snd_usb_endpoint *ep, bool can_sleep)

err = usb_submit_urb(urb, GFP_ATOMIC);
if (err < 0) {
snd_printk(KERN_ERR "cannot submit urb %d, error %d: %s\n",
i, err, usb_error_string(err));
usb_audio_err(ep->chip,
"cannot submit urb %d, error %d: %s\n",
i, err, usb_error_string(err));
goto __error;
}
set_bit(i, &ep->active_mask);
Expand Down
Loading

0 comments on commit 0ba41d9

Please sign in to comment.