sleeping in ioctl

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

 



Hello,
   I am trying to implement a device driver here. The read fop of my
driver sleeps itself untill the data is available. Here is the
relevent code:

static ssize_t ict3k5_read (struct file *filep, char *buff, 
		  size_t count, loff_t *offp)
{
  DECLARE_WAITQUEUE (wait, current);
  ssize_t retval;
  ssize_t i = 0;
  
  add_wait_queue (&port_data_wait, &wait);
  current->state = TASK_INTERRUPTIBLE;
   
  do {
    spin_lock_irq (&port_data_lock);
     
    /* code to get the data from the queue
       delived by an interrupt handler */

    spin_unlock_irq (&port_data_lock);
                
    if (i >= count) {
      break;
    }

    if (filep->f_flags & O_NONBLOCK) {
      retval = -EAGAIN;
      break;
    }
    
    if (signal_pending (current)) {
      retval = -ERESTARTSYS;
      break;
    }
 
    schedule ();
        
  } while (1);
  
  current->state = TASK_RUNNING;
  remove_wait_queue (&port_data_wait, &wait);

  if (retval >= 0) {
    retval = count;
  }

  return retval;
}

   This works perfect when called from the user-space. Now i wanted to
utilize read in my ioctl fop. But when i call read from my ioctl, i
get this error:

Debug: sleeping function called from invalid context at
include/linux/rwsem.h:43in_atomic():0, irqs_disabled():1
 [<0211691d>] __might_sleep+0x80/0x8a
 [<0213f071>] rw_vm+0x85/0x1ea
 [<02115617>] recalc_task_prio+0x141/0x14c
 [<02115e97>] default_wake_function+0x0/0xc
 [<0213f423>] put_user_size+0x29/0x2d
 [<02115e97>] default_wake_function+0x0/0xc
 [<129cf14a>] ict3k5_read+0xaa/0x1a0 [ict3k5]
 [<02115e97>] default_wake_function+0x0/0xc
 [<02115e97>] default_wake_function+0x0/0xc
 [<021479f9>] chrdev_open+0xfa/0x127
 [<129cf3da>] ict3k5_ioctl+0x8a/0x200 [ict3k5]
 [<129cc0f1>] card_reader_ioctl+0x41/0x60 [card_reader_driver]
 [<0214ea0e>] sys_ioctl+0x1f2/0x224

   Can anyone tell me what I am doing wrong? Am I not allowed to sleep
inside ioctl? Thanks in advance.

--
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