speedtch usbatm.c,1.12,1.13 usbatm.h,1.8,1.9
Duncan Sands
duncan at infradead.org
Mon Feb 7 18:21:04 EST 2005
Update of /home/cvs/speedtch
In directory phoenix.infradead.org:/tmp/cvs-serv17516
Modified Files:
usbatm.c usbatm.h
Log Message:
Specify which struct usbatm_data fields can be accessed by minidrivers,
and which are private. Call bind once the public fields are initialized.
Stop the tasklets before calling atm_stop and unbind, in case they are
calling into the minidriver somehow.
Index: usbatm.c
===================================================================
RCS file: /home/cvs/speedtch/usbatm.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- usbatm.c 7 Feb 2005 22:30:00 -0000 1.12
+++ usbatm.c 7 Feb 2005 23:21:01 -0000 1.13
@@ -969,8 +969,10 @@
/* temp init ATM device, set to 128kbit */
atm_dev->link_rate = 128 * 1000 / 424;
- if (instance->driver->atm_start && ((ret = instance->driver->atm_start(instance, atm_dev)) < 0))
+ if (instance->driver->atm_start && ((ret = instance->driver->atm_start(instance, atm_dev)) < 0)) {
+ dbg("usbatm_atm_init: atm_start failed: %d!", ret);
goto fail;
+ }
/* ready for ATM callbacks */
usbatm_get_instance(instance); /* dropped in usbatm_atm_dev_close */
@@ -1052,16 +1054,10 @@
memset(instance, 0, sizeof(*instance));
- kref_init(&instance->refcount); /* dropped in usbatm_usb_disconnect */
-
- init_MUTEX(&instance->serialize);
+ /* public fields */
instance->driver = driver;
- instance->thread_pid = -1;
- init_completion(&instance->thread_started);
- init_completion(&instance->thread_exited);
-
instance->usb_dev = dev;
instance->usb_intf = intf;
instance->tx_endpoint = usb_sndbulkpipe(dev, driver->out);
@@ -1069,6 +1065,43 @@
instance->tx_padding = driver->tx_padding;
instance->rx_padding = driver->rx_padding;
+ buf = instance->description;
+ length = sizeof(instance->description);
+
+ if ((i = usb_string(dev, dev->descriptor.iProduct, buf, length)) < 0)
+ goto bind;
+
+ buf += i;
+ length -= i;
+
+ i = scnprintf(buf, length, " (");
+ buf += i;
+ length -= i;
+
+ if (length <= 0 || (i = usb_make_path(dev, buf, length)) < 0)
+ goto bind;
+
+ buf += i;
+ length -= i;
+
+ snprintf(buf, length, ")");
+
+ bind:
+ need_heavy = 1;
+ if (driver->bind && (error = driver->bind(instance, intf, &need_heavy)) < 0) {
+ dev_dbg(&intf->dev, "bind failed: %d!\n", error);
+ goto fail_free;
+ }
+
+ /* private fields */
+
+ kref_init(&instance->refcount); /* dropped in usbatm_usb_disconnect */
+ init_MUTEX(&instance->serialize);
+
+ instance->thread_pid = -1;
+ init_completion(&instance->thread_started);
+ init_completion(&instance->thread_exited);
+
INIT_LIST_HEAD(&instance->vcc_list);
spin_lock_init(&instance->receive_lock);
@@ -1084,8 +1117,7 @@
INIT_LIST_HEAD(&instance->spare_senders);
INIT_LIST_HEAD(&instance->spare_send_buffers);
- tasklet_init(&instance->send_tasklet, usbatm_process_send,
- (unsigned long)instance);
+ tasklet_init(&instance->send_tasklet, usbatm_process_send, (unsigned long)instance);
INIT_LIST_HEAD(&instance->filled_send_buffers);
/* receive init */
@@ -1094,7 +1126,7 @@
if (!(rcv->urb = usb_alloc_urb(0, GFP_KERNEL))) {
dev_dbg(&intf->dev, "no memory for receive urb %d!\n", i);
- goto fail;
+ goto fail_unbind;
}
rcv->instance = instance;
@@ -1109,7 +1141,7 @@
GFP_KERNEL);
if (!buf->base) {
dev_dbg(&intf->dev, "no memory for receive buffer %d!\n", i);
- goto fail;
+ goto fail_unbind;
}
list_add(&buf->list, &instance->spare_receive_buffers);
@@ -1121,7 +1153,7 @@
if (!(snd->urb = usb_alloc_urb(0, GFP_KERNEL))) {
dev_dbg(&intf->dev, "usbatm_usb_probe: no memory for send urb %d!\n", i);
- goto fail;
+ goto fail_unbind;
}
snd->instance = instance;
@@ -1136,64 +1168,31 @@
GFP_KERNEL);
if (!buf->base) {
dev_dbg(&intf->dev, "no memory for send buffer %d!\n", i);
- goto fail;
+ goto fail_unbind;
}
list_add(&buf->list, &instance->spare_send_buffers);
}
- /* device description */
- buf = instance->description;
- length = sizeof(instance->description);
-
- if ((i = usb_string(dev, dev->descriptor.iProduct, buf, length)) < 0)
- goto bind;
-
- buf += i;
- length -= i;
-
- i = scnprintf(buf, length, " (");
- buf += i;
- length -= i;
-
- if (length <= 0 || (i = usb_make_path(dev, buf, length)) < 0)
- goto bind;
-
- buf += i;
- length -= i;
-
- snprintf(buf, length, ")");
-
- bind:
- need_heavy = 1;
- if (driver->bind && (error = driver->bind(instance, intf, &need_heavy)) < 0) {
- dev_dbg(&intf->dev, "bind failed: %d!\n", error);
- goto fail;
- }
-
if (need_heavy && driver->heavy_init) {
error = usbatm_heavy_init(instance);
- if (error < 0)
- dev_dbg(&intf->dev, "failed to start heavy init: %d!\n", error);
} else {
complete(&instance->thread_exited); /* pretend that heavy_init was run */
error = usbatm_atm_init(instance);
- if (error < 0)
- dev_dbg(&intf->dev, "atm_init failed: %d!\n", error);
}
- if (error) {
- if (instance->driver->unbind)
- instance->driver->unbind(instance, intf);
- goto fail;
- }
+ if (error < 0)
+ goto fail_unbind;
usb_get_dev(dev);
usb_set_intfdata(intf, instance);
return 0;
- fail:
+ fail_unbind:
+ if (instance->driver->unbind)
+ instance->driver->unbind(instance, intf);
+ fail_free:
for (i = 0; i < num_snd_bufs; i++)
kfree(instance->send_buffers[i].base);
@@ -1233,6 +1232,9 @@
wait_for_completion(&instance->thread_exited);
+ tasklet_disable(&instance->receive_tasklet);
+ tasklet_disable(&instance->send_tasklet);
+
if (instance->atm_dev && instance->driver->atm_stop)
instance->driver->atm_stop(instance, instance->atm_dev);
@@ -1240,7 +1242,6 @@
instance->driver->unbind(instance, intf);
/* receive finalize */
- tasklet_disable(&instance->receive_tasklet);
for (i = 0; i < num_rcv_urbs; i++)
usb_kill_urb(instance->receivers[i].urb);
@@ -1258,7 +1259,6 @@
kfree(instance->receive_buffers[i].base);
/* send finalize */
- tasklet_disable(&instance->send_tasklet);
for (i = 0; i < num_snd_urbs; i++)
usb_kill_urb(instance->senders[i].urb);
Index: usbatm.h
===================================================================
RCS file: /home/cvs/speedtch/usbatm.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- usbatm.h 1 Feb 2005 23:20:49 -0000 1.8
+++ usbatm.h 7 Feb 2005 23:21:01 -0000 1.9
@@ -147,19 +147,15 @@
/* main driver data */
struct usbatm_data {
- struct kref refcount;
- struct semaphore serialize;
+ /******************
+ * public fields *
+ ******************/
- /* mini driver part */
+ /* mini driver */
struct usbatm_driver *driver;
void *driver_data;
- /* heavy init part */
- int thread_pid;
- struct completion thread_started;
- struct completion thread_exited;
-
- /* USB device part */
+ /* USB device */
struct usb_device *usb_dev;
struct usb_interface *usb_intf;
char description[64];
@@ -168,8 +164,22 @@
int tx_padding;
int rx_padding;
- /* ATM device part */
+ /* ATM device */
struct atm_dev *atm_dev;
+
+ /********************************
+ * private fields - do not use *
+ ********************************/
+
+ struct kref refcount;
+ struct semaphore serialize;
+
+ /* heavy init */
+ int thread_pid;
+ struct completion thread_started;
+ struct completion thread_exited;
+
+ /* ATM device */
struct list_head vcc_list;
/* receive */
More information about the Usbatm-commits
mailing list