Commit 8df01d97 authored by Alexander Viro's avatar Alexander Viro Committed by Linus Torvalds

[PATCH] usx2y cleanups and fixes

Sigh...
	a) mixing of userland and kernel pointers is bad
	b) so's not checking result of kmalloc()
	c) so's not checking result of copy_from_user()
	d) use of do { .... break; ... break; ... } while(0); is *highly*
unidiomatic.  Do not confuse kernel with IOCCC, please. And if you have
religious aversion to multiple return statements in a function, at least
learn the reasons why it is frowned upon in many situations.  Hint: they
all apply to use of break in that manner.
	e) 0 instead of NULL
Signed-off-by: default avatarAl Viro <viro@parcelfarce.linux.org.uk>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent fef4f8b9
...@@ -211,43 +211,50 @@ static int usX2Y_create_alsa_devices(snd_card_t* card) ...@@ -211,43 +211,50 @@ static int usX2Y_create_alsa_devices(snd_card_t* card)
static int snd_usX2Y_hwdep_dsp_load(snd_hwdep_t *hw, snd_hwdep_dsp_image_t *dsp) static int snd_usX2Y_hwdep_dsp_load(snd_hwdep_t *hw, snd_hwdep_dsp_image_t *dsp)
{ {
int lret, err; usX2Ydev_t *priv = hw->private_data;
char* buf; int lret, err = -EINVAL;
snd_printdd( "dsp_load %s\n", dsp->name); snd_printdd( "dsp_load %s\n", dsp->name);
buf = dsp->image;
err = -EINVAL;
if (access_ok(VERIFY_READ, dsp->image, dsp->length)) { if (access_ok(VERIFY_READ, dsp->image, dsp->length)) {
struct usb_device* dev = ((usX2Ydev_t*)hw->private_data)->chip.dev; struct usb_device* dev = priv->chip.dev;
buf = kmalloc(dsp->length, GFP_KERNEL); char *buf = kmalloc(dsp->length, GFP_KERNEL);
copy_from_user(buf, dsp->image, dsp->length); if (!buf)
if ((err = usb_set_interface(dev, 0, 1))) return -ENOMEM;
if (copy_from_user(buf, dsp->image, dsp->length)) {
kfree(buf);
return -EFAULT;
}
err = usb_set_interface(dev, 0, 1);
if (err)
snd_printk("usb_set_interface error \n"); snd_printk("usb_set_interface error \n");
else else
err = usb_bulk_msg(dev, usb_sndbulkpipe(dev, 2), buf, dsp->length, &lret, 6*HZ); err = usb_bulk_msg(dev, usb_sndbulkpipe(dev, 2), buf, dsp->length, &lret, 6*HZ);
kfree(buf); kfree(buf);
} }
if (!err && 1 == dsp->index) if (err)
do { return err;
set_current_state(TASK_UNINTERRUPTIBLE); if (dsp->index == 1) {
schedule_timeout(HZ/4); // give the device some time set_current_state(TASK_UNINTERRUPTIBLE);
if ((err = usX2Y_AsyncSeq04_init((usX2Ydev_t*)hw->private_data))) { schedule_timeout(HZ/4); // give the device some time
snd_printk("usX2Y_AsyncSeq04_init error \n"); err = usX2Y_AsyncSeq04_init(priv);
break; if (err) {
} snd_printk("usX2Y_AsyncSeq04_init error \n");
if ((err = usX2Y_In04_init((usX2Ydev_t*)hw->private_data))) { return err;
snd_printk("usX2Y_In04_init error \n"); }
break; err = usX2Y_In04_init(priv);
} if (err) {
if ((err = usX2Y_create_alsa_devices(hw->card))) { snd_printk("usX2Y_In04_init error \n");
snd_printk("usX2Y_create_alsa_devices error %i \n", err); return err;
snd_card_free(hw->card); }
break; err = usX2Y_create_alsa_devices(hw->card);
} if (err) {
((usX2Ydev_t*)hw->private_data)->chip_status |= USX2Y_STAT_CHIP_INIT; snd_printk("usX2Y_create_alsa_devices error %i \n", err);
snd_printdd("%s: alsa all started\n", hw->name); snd_card_free(hw->card);
} while (0); return err;
}
priv->chip_status |= USX2Y_STAT_CHIP_INIT;
snd_printdd("%s: alsa all started\n", hw->name);
}
return err; return err;
} }
......
...@@ -346,11 +346,11 @@ static void* usX2Y_usb_probe(struct usb_device* device, struct usb_interface *in ...@@ -346,11 +346,11 @@ static void* usX2Y_usb_probe(struct usb_device* device, struct usb_interface *in
device->descriptor.idProduct != USB_ID_US224 && device->descriptor.idProduct != USB_ID_US224 &&
device->descriptor.idProduct != USB_ID_US428) || device->descriptor.idProduct != USB_ID_US428) ||
!(card = usX2Y_create_card(device))) !(card = usX2Y_create_card(device)))
return 0; return NULL;
if ((err = usX2Y_hwdep_new(card, device)) < 0 || if ((err = usX2Y_hwdep_new(card, device)) < 0 ||
(err = snd_card_register(card)) < 0) { (err = snd_card_register(card)) < 0) {
snd_card_free(card); snd_card_free(card);
return 0; return NULL;
} }
return card; return card;
} }
......
...@@ -411,7 +411,7 @@ static void usX2Y_urb_release(struct urb** urb, int free_tb) ...@@ -411,7 +411,7 @@ static void usX2Y_urb_release(struct urb** urb, int free_tb)
if (free_tb) if (free_tb)
kfree((*urb)->transfer_buffer); kfree((*urb)->transfer_buffer);
usb_free_urb(*urb); usb_free_urb(*urb);
*urb = 0; *urb = NULL;
} }
} }
/* /*
...@@ -427,7 +427,7 @@ static void usX2Y_urbs_release(snd_usX2Y_substream_t *subs) ...@@ -427,7 +427,7 @@ static void usX2Y_urbs_release(snd_usX2Y_substream_t *subs)
if (subs->tmpbuf) { if (subs->tmpbuf) {
kfree(subs->tmpbuf); kfree(subs->tmpbuf);
subs->tmpbuf = 0; subs->tmpbuf = NULL;
} }
} }
...@@ -794,7 +794,7 @@ static int snd_usX2Y_pcm_prepare(snd_pcm_substream_t *substream) ...@@ -794,7 +794,7 @@ static int snd_usX2Y_pcm_prepare(snd_pcm_substream_t *substream)
return err; return err;
snd_printdd("starting capture pipe for playpipe\n"); snd_printdd("starting capture pipe for playpipe\n");
usX2Y_urbs_allocate(capsubs); usX2Y_urbs_allocate(capsubs);
capsubs->completed_urb = 0; capsubs->completed_urb = NULL;
{ {
DECLARE_WAITQUEUE(wait, current); DECLARE_WAITQUEUE(wait, current);
add_wait_queue(&capsubs->wait_queue, &wait); add_wait_queue(&capsubs->wait_queue, &wait);
...@@ -838,7 +838,7 @@ static int snd_usX2Y_pcm_prepare(snd_pcm_substream_t *substream) ...@@ -838,7 +838,7 @@ static int snd_usX2Y_pcm_prepare(snd_pcm_substream_t *substream)
} }
} }
} }
subs->completed_urb = 0; subs->completed_urb = NULL;
subs->next_urb_complete = -1; subs->next_urb_complete = -1;
subs->stalled = 0; subs->stalled = 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment