On Wed, Jun 21, 2006 at 06:15:13PM -0300, Luiz Fernando N. Capitulino wrote:
> On Wed, 21 Jun 2006 17:43:36 +0100
> Russell King <[EMAIL PROTECTED]> wrote:
> 
> | In the uart_update_mctrl() case, the purpose of the locking is to
> | prevent two concurrent changes to the modem control state resulting
> | in an inconsistency between the hardware and the software state.  If
> | it's provable that it is always called from process context (and
> | it isn't called from a lock_kernel()-section or the lock_kernel()
> | section doesn't mind a rescheduling point being introduced there),
> | there's no problem converting that to a mutex.
> 
>  Ok, then I can submit my debug patch to answer these questions.
> 
>  might_sleep() can catch the lock_kernel()-section case right?
> 
> | With get_mctrl(), the situation is slightly more complicated, because
> | we need to atomically update tty->hw_stopped in some circumstances
> | (that may also be modified from irq context.)  Therefore, to give
> | the driver a consistent locking picture, the spinlock is _always_
> | held.
> 
>  Is it too bad (wrong?) to only protect the tty->hw_stopped update
> by the spinlock? Then the call to get_mctrl() could be protected by
> a mutex, or is it messy?

Consider this scenario with what you're proposing:

        thread                          irq

        take mutex
        get_mctrl
                                        cts changes state
                                        take port lock
                                        mctrl state read
                                        tty->hw_stopped changed state
                                        release port lock
        releaes mutex
        take port lock
        update tty->hw_stopped
        release port lock

Now, tty->hw_stopped does not reflect the hardware state, which will be
buggy and can cause a loss of transmission.

I'm not sure what to suggest on this one since for USB drivers you do
need to be able to sleep in this method... but for UARTs you must not.

-- 
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:  2.6 Serial core

All the advantages of Linux Managed Hosting--Without the Cost and Risk!
Fully trained technicians. The highest number of Red Hat certifications in
the hosting industry. Fanatical Support. Click to learn more
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=107521&bid=248729&dat=121642
_______________________________________________
linux-usb-devel@lists.sourceforge.net
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to