Re: open a file in spin_lock_irq()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



>>>>> "Guillaume" == Guillaume Thouvenin <guillaume.thouvenin@polymtl.ca> writes:
Guillaume> I implemented the ioctl as follow:

Guillaume> int my_ioctl(...) {
Guillaume>     ...
Guillaume>     switch(cmd) {
Guillaume>         case REMOVE_AN_ITEM:
Guillaume>             spin_lock_irq(&my_lock);
Guillaume>             update_my_structure();
Guillaume>             spin_unlock_irq(&my_lock);
Guillaume>             break;
Guillaume>          ....
Guillaume>     }
Guillaume> }

Guillaume> Function update_my_structure() remove an item from a list
Guillaume> of items and if the list is empty, it dumps information
Guillaume> about this list in a file. So, in this function I call
Guillaume> filp_open() if list is empty. The problem is that you can
Guillaume> not call filp_open() if you are in a spinlock because irq
Guillaume> must be enable.

Guillaume> So my question is how can you open a file if you are in a
Guillaume> spin_lock_irq()?

Don't.

Do

switch (cmd)
  {
    case REMOVE_AN_ITEM:
      spin_lock_irq (&my_lock);
      is_empty = update_my_structure ();
      spin_unlock_irq (&my_lock);
      if (is_empty)
         dump_stuff_to_file ();
      break;

which is not very good either.  Better return information that the
list is empty to the caller and let it meddle with files from
userspace.

~velco

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux