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)
static int snd_usX2Y_hwdep_dsp_load(snd_hwdep_t *hw, snd_hwdep_dsp_image_t *dsp)
{
int lret, err;
char* buf;
usX2Ydev_t *priv = hw->private_data;
int lret, err = -EINVAL;
snd_printdd( "dsp_load %s\n", dsp->name);
buf = dsp->image;
err = -EINVAL;
if (access_ok(VERIFY_READ, dsp->image, dsp->length)) {
struct usb_device* dev = ((usX2Ydev_t*)hw->private_data)->chip.dev;
buf = kmalloc(dsp->length, GFP_KERNEL);
copy_from_user(buf, dsp->image, dsp->length);
if ((err = usb_set_interface(dev, 0, 1)))
struct usb_device* dev = priv->chip.dev;
char *buf = kmalloc(dsp->length, GFP_KERNEL);
if (!buf)
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");
else
err = usb_bulk_msg(dev, usb_sndbulkpipe(dev, 2), buf, dsp->length, &lret, 6*HZ);
kfree(buf);
}
if (!err && 1 == dsp->index)
do {
set_current_state(TASK_UNINTERRUPTIBLE);
schedule_timeout(HZ/4); // give the device some time
if ((err = usX2Y_AsyncSeq04_init((usX2Ydev_t*)hw->private_data))) {
snd_printk("usX2Y_AsyncSeq04_init error \n");
break;
}
if ((err = usX2Y_In04_init((usX2Ydev_t*)hw->private_data))) {
snd_printk("usX2Y_In04_init error \n");
break;
}
if ((err = usX2Y_create_alsa_devices(hw->card))) {
snd_printk("usX2Y_create_alsa_devices error %i \n", err);
snd_card_free(hw->card);
break;
}
((usX2Ydev_t*)hw->private_data)->chip_status |= USX2Y_STAT_CHIP_INIT;
snd_printdd("%s: alsa all started\n", hw->name);
} while (0);
if (err)
return err;
if (dsp->index == 1) {
set_current_state(TASK_UNINTERRUPTIBLE);
schedule_timeout(HZ/4); // give the device some time
err = usX2Y_AsyncSeq04_init(priv);
if (err) {
snd_printk("usX2Y_AsyncSeq04_init error \n");
return err;
}
err = usX2Y_In04_init(priv);
if (err) {
snd_printk("usX2Y_In04_init error \n");
return err;
}
err = usX2Y_create_alsa_devices(hw->card);
if (err) {
snd_printk("usX2Y_create_alsa_devices error %i \n", err);
snd_card_free(hw->card);
return err;
}
priv->chip_status |= USX2Y_STAT_CHIP_INIT;
snd_printdd("%s: alsa all started\n", hw->name);
}
return err;
}
......
......@@ -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_US428) ||
!(card = usX2Y_create_card(device)))
return 0;
return NULL;
if ((err = usX2Y_hwdep_new(card, device)) < 0 ||
(err = snd_card_register(card)) < 0) {
snd_card_free(card);
return 0;
return NULL;
}
return card;
}
......
......@@ -411,7 +411,7 @@ static void usX2Y_urb_release(struct urb** urb, int free_tb)
if (free_tb)
kfree((*urb)->transfer_buffer);
usb_free_urb(*urb);
*urb = 0;
*urb = NULL;
}
}
/*
......@@ -427,7 +427,7 @@ static void usX2Y_urbs_release(snd_usX2Y_substream_t *subs)
if (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)
return err;
snd_printdd("starting capture pipe for playpipe\n");
usX2Y_urbs_allocate(capsubs);
capsubs->completed_urb = 0;
capsubs->completed_urb = NULL;
{
DECLARE_WAITQUEUE(wait, current);
add_wait_queue(&capsubs->wait_queue, &wait);
......@@ -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->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