patch-2.4.10 linux/drivers/usb/rio500.c
Next file: linux/drivers/usb/scanner.c
Previous file: linux/drivers/usb/pwc.h
Back to the patch index
Back to the overall index
- Lines: 194
- Date:
Fri Sep 14 14:04:07 2001
- Orig file:
v2.4.9/linux/drivers/usb/rio500.c
- Orig date:
Sun Aug 12 13:28:00 2001
diff -u --recursive --new-file v2.4.9/linux/drivers/usb/rio500.c linux/drivers/usb/rio500.c
@@ -120,13 +120,17 @@
unsigned char *buffer;
int result, requesttype;
int retries;
- int retval;
+ int retval=0;
+ down(&(rio->lock));
/* Sanity check to make sure rio is connected, powered, etc */
if ( rio == NULL ||
rio->present == 0 ||
rio->rio_dev == NULL )
- return -1;
+ {
+ retval = -ENODEV;
+ goto err_out;
+ }
switch (cmd) {
case RIO_RECV_COMMAND:
@@ -142,8 +146,10 @@
goto err_out;
}
buffer = (unsigned char *) __get_free_page(GFP_KERNEL);
- if (buffer == NULL)
- return -ENOMEM;
+ if (buffer == NULL) {
+ retval = -ENOMEM;
+ goto err_out;
+ }
if (copy_from_user(buffer, rio_cmd.buffer, rio_cmd.length)) {
retval = -EFAULT;
free_page((unsigned long) buffer);
@@ -158,7 +164,6 @@
rio_cmd.index, rio_cmd.length);
/* Send rio control message */
retries = 3;
- down(&(rio->lock));
while (retries) {
result = usb_control_msg(rio->rio_dev,
usb_rcvctrlpipe(rio-> rio_dev, 0),
@@ -180,7 +185,6 @@
le32_to_cpu(*((long *) buffer)));
if (copy_to_user(rio_cmd.buffer, buffer,
rio_cmd.length)) {
- up(&(rio->lock));
free_page((unsigned long) buffer);
retval = -EFAULT;
goto err_out;
@@ -196,7 +200,6 @@
be swapped at the app level */
}
- up(&(rio->lock));
free_page((unsigned long) buffer);
break;
@@ -204,16 +207,23 @@
data = (void *) arg;
if (data == NULL)
break;
- if (copy_from_user(&rio_cmd, data, sizeof(struct RioCommand)))
- return -EFAULT;
- if (rio_cmd.length > PAGE_SIZE)
- return -EINVAL;
+ if (copy_from_user(&rio_cmd, data, sizeof(struct RioCommand))) {
+ retval = -EFAULT;
+ goto err_out;
+ }
+ if (rio_cmd.length > PAGE_SIZE) {
+ retval = -EINVAL;
+ goto err_out;
+ }
buffer = (unsigned char *) __get_free_page(GFP_KERNEL);
- if (buffer == NULL)
- return -ENOMEM;
+ if (buffer == NULL) {
+ retval = -ENOMEM;
+ goto err_out;
+ }
if (copy_from_user(buffer, rio_cmd.buffer, rio_cmd.length)) {
free_page((unsigned long)buffer);
- return -EFAULT;
+ retval = -EFAULT;
+ goto err_out;
}
requesttype = rio_cmd.requesttype | USB_DIR_OUT |
@@ -223,7 +233,6 @@
rio_cmd.index, rio_cmd.length);
/* Send rio control message */
retries = 3;
- down(&(rio->lock));
while (retries) {
result = usb_control_msg(rio->rio_dev,
usb_sndctrlpipe(rio-> rio_dev, 0),
@@ -247,16 +256,14 @@
}
}
- up(&(rio->lock));
free_page((unsigned long) buffer);
break;
default:
- return -ENOIOCTLCMD;
+ retval = -ENOTTY;
break;
}
- return 0;
err_out:
up(&(rio->lock));
@@ -277,13 +284,17 @@
int maxretry;
int errn = 0;
+ down(&(rio->lock));
/* Sanity check to make sure rio is connected, powered, etc */
if ( rio == NULL ||
rio->present == 0 ||
rio->rio_dev == NULL )
- return -1;
+ {
+ up(&(rio->lock));
+ return -ENODEV;
+ }
+
- down(&(rio->lock));
do {
unsigned long thistime;
@@ -356,17 +367,20 @@
int maxretry = 10;
char *ibuf;
- /* Sanity check to make sure rio is connected, powered, etc */
+ down(&(rio->lock));
+ /* Sanity check to make sure rio is connected, powered, etc */
if ( rio == NULL ||
rio->present == 0 ||
rio->rio_dev == NULL )
- return -1;
+ {
+ up(&(rio->lock));
+ return -ENODEV;
+ }
ibuf = rio->ibuf;
read_count = 0;
- down(&(rio->lock));
while (count > 0) {
if (signal_pending(current)) {
@@ -461,7 +475,7 @@
S_IWGRP, &usb_rio_fops, NULL);
if (rio->devfs == NULL)
dbg("probe_rio: device node registration failed");
-
+
init_MUTEX(&(rio->lock));
return rio;
@@ -473,10 +487,12 @@
devfs_unregister(rio->devfs);
+ down(&(rio->lock));
if (rio->isopen) {
rio->isopen = 0;
/* better let it finish - the release will do whats needed */
rio->rio_dev = NULL;
+ up(&(rio->lock));
return;
}
kfree(rio->ibuf);
@@ -485,6 +501,7 @@
info("USB Rio disconnected.");
rio->present = 0;
+ up(&(rio->lock));
}
static struct usb_device_id rio_table [] = {
@@ -529,4 +546,5 @@
MODULE_AUTHOR( DRIVER_AUTHOR );
MODULE_DESCRIPTION( DRIVER_DESC );
+MODULE_LICENSE("GPL");
FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)