Date:2011-07-06 16:56:25 (9 years 7 days ago)
Author:Werner Almesberger
Commit:247b48a72cfd14d1c5b1ae2f9e9addea14ceb310
Message:atusb: merged error checking and request completion for control transfers

Most of the processing in atusb_ctrl_cb and atusb_read_fb_cb was
identical. Merged it.

Also changed bare printk to dev_dbg or dev_info.

Signed-off-by: Werner Almesberger <werner@almesberger.net>
Files: drivers/spi/atusb.c (3 diffs)

Change Details

drivers/spi/atusb.c
109109/* ----- Control transfers ------------------------------------------------- */
110110
111111
112static void atusb_ctrl_cb(struct urb *urb)
112static int atusb_async_errchk(struct urb *urb)
113113{
114114    struct atusb_local *atusb = urb->context;
115115    struct spi_message *msg = atusb->msg;
116    struct usb_device *dev = atusb->udev;
116117
117    if (urb->status) {
118        if (!(urb->status == -ENOENT ||
119            urb->status == -ECONNRESET ||
120            urb->status == -ESHUTDOWN))
121            printk("Async USB failed with error %i\n", urb->status);
122        msg->actual_length = 0;
123    } else {
124        printk("Async USB succeeded with length %i\n",
118    if (!urb->status) {
119        dev_dbg(&dev->dev, "atusb_async_errchk OK len %d\n",
125120            urb->actual_length);
121        return 0;
126122    }
123
124    if (urb->status != -ENOENT && urb->status != -ECONNRESET &&
125        urb->status != -ESHUTDOWN)
126        dev_info(&dev->dev, "atusb_async_errchk FAIL error %d\n",
127            urb->status);
128
129    msg->actual_length = 0;
130
131    return urb->status;
132}
133
134static void atusb_async_finish(struct urb *urb)
135{
136    struct atusb_local *atusb = urb->context;
137    struct spi_message *msg = atusb->msg;
127138
128139    msg->status = urb->status;
129140    msg->complete(msg->context);
...... 
132143    usb_free_urb(urb);
133144}
134145
146static void atusb_ctrl_cb(struct urb *urb)
147{
148    atusb_async_errchk(urb);
149    atusb_async_finish(urb);
150}
151
135152static void atusb_read_fb_cb(struct urb *urb)
136153{
137154    struct atusb_local *atusb = urb->context;
...... 
139156    const struct spi_transfer *xfer;
140157    uint8_t *rx;
141158
142    if (urb->status) {
143        if (!(urb->status == -ENOENT ||
144            urb->status == -ECONNRESET ||
145            urb->status == -ESHUTDOWN))
146            printk("Async USB failed with error %i\n", urb->status);
147        msg->actual_length = 0;
148    } else {
149        printk("Async USB succeeded with length %i\n",
150            urb->actual_length);
159    if (!atusb_async_errchk(urb)) {
151160        BUG_ON(!urb->actual_length);
161
152162        xfer = list_first_entry(&msg->transfers, struct spi_transfer,
153163            transfer_list);
154164        rx = xfer->rx_buf;
155165        rx[1] = atusb->buffer[0];
166
156167        xfer = list_entry(xfer->transfer_list.next,
157168            struct spi_transfer, transfer_list);
158169        memcpy(xfer->rx_buf, atusb->buffer+1, urb->actual_length-1);
159170    }
160171
161    msg->status = urb->status;
162    msg->complete(msg->context);
163
164    kfree(urb->setup_packet);
165    usb_free_urb(urb);
172    atusb_async_finish(urb);
166173}
167174
168175static int submit_control_msg(struct atusb_local *atusb,

Archive Download the corresponding diff file



interactive