Hi,

Am Samstag, 13. M�rz 2004 15:18 schrieb Juergen Stuber:
> Hi Oliver,
> 
> Oliver Neukum <[EMAIL PROTECTED]> writes:
> >
> > [..]
> >> +  atomic_t                interrupt_in_running;
> >> +  atomic_t                interrupt_in_done;
> >
> > what use are these atomic declarations?
> 
> good question.
> I got this pattern from the use of write_busy in usb-skeleton.c .
> I think it is a safe programming style for concurrently accessed
> variables, but that it isn't strictly necessary if you only read
> and set byte values.

The problem is that it leads to sloppy thinking about locking. People
tend to assume that if they use enough atomic_t races vanish
automagically.
Code like this:
+       atomic_set (&dev->interrupt_in_running, 1);
+       atomic_set (&dev->interrupt_in_done, 0);
+       retval = usb_submit_urb (dev->interrupt_in_urb, GFP_KERNEL);

is potentially racy. It seems to me that you'd rather be clearer with
code like this:

dev->interrupt_in_running = 1;
wmb();
dev->interrupt_in_done = 0;

> > [..]
> >> @@ -628,22 +740,23 @@ static void tower_interrupt_out_callback
> >>  {
> >>    struct lego_usb_tower *dev = (struct lego_usb_tower *)urb->context;
> >>  
> >> -  dbg(4," %s : enter, status %d", __func__, urb->status);
> >> -  lego_usb_tower_debug_data(5,__func__, urb->actual_length, 
> >> urb->transfer_buffer);
> >> +  dbg(4, "%s: enter, status %d", __FUNCTION__, urb->status);
> >> +  lego_usb_tower_debug_data(5, __FUNCTION__, urb->actual_length, 
> >> urb->transfer_buffer);
> >>  
> >>    if (urb->status != 0) {
> >> -          if ((urb->status != -ENOENT) && 
> >> +          if ((urb->status != -ENOENT) &&
> >
> > You should also check for ESHUTDOWN.
> 
> Ok, and also in the in callback I suppose
> (and that should also be fixed in usb-skeleton, I'll send a patch).
> Btw, are the error codes documented somewhere?

Deep in the introductory pages on http://www.linux-usb.org

        Regards
                Oliver



-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id70&alloc_id638&op=click
_______________________________________________
[EMAIL PROTECTED]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to