Hi,

On Sun, Sep 13, 2009 at 3:53 PM, Mark Ryden <[email protected]> wrote:
> Hello,
>
> I have a question about spinlocks and copy_to_user():
> copy_to_user() can sleep
> so it should not be called when a spin_lock is held.
>
> However, I have data (a structure, not atomic variable) which can be
> changed in interrupt context
> in my module;  so this data is protected by spinlocks.
>
> I use ioctl to pass this data to user space; this ioctl() calls
> copy_to_user(); when I call spin_lock_bh()
> before cp[y_to_user() in this ioctl , I get:
>
Use a local  variable in ioctl:
In the critical section copy your data into this variable using memcpy.
Outside the critical section call copy_to_user.


> "kernel: BUG: sleeping function called from invalid
> context at include/linux/kernel.h:155".
>
> How should I call copy_to_user() so that it won't pass wrong data to
> user space ? If I remove the
> spin_lock_bh() before the call to copy_to_user()  , I have a chance to
> copy wrong data (to copy data while it is changing in my module ).
>
> Regards,
> Mark
>
> --
> To unsubscribe from this list: send an email with
> "unsubscribe kernelnewbies" to [email protected]
> Please read the FAQ at http://kernelnewbies.org/FAQ
>
>

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to [email protected]
Please read the FAQ at http://kernelnewbies.org/FAQ

Reply via email to