wait_event_timeout in callback handler

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

 



Hello 

can I use wait_event_timeout in a callback handler ? 

Below my attempt, which results in a kernel freeze and a 
stack dump of the module. 

Thanks 
Tilman 

static void  usbrsa_test_write_callback(struct urb *urb)
{
        struct usb_serial_port*         port;
        struct usbrsa_port_private*     priv;
        int                             status;
        unsigned long                   flags;
        int                             urb_index;
        int                             retval;
        long                            t;

        dbg("%s() ",__func__);
        port = urb->context;
        status  = urb->status;
        priv    = usb_get_serial_port_data(port);

        usb_serial_debug_data(debug, &port->dev, __func__,
            urb->actual_length, urb->transfer_buffer);
        // reserve urb
        spin_lock_irqsave(&priv->lock, flags);
        clear_bit(0, &priv->write_urb_pool_lock);
        spin_unlock_irqrestore(&priv->lock, flags);

        if (!(status))
        {
                dbg("%s(): nonzero urb status: 0x%d", __func__, status);
        }
        else
        {
                dbg("%s(): submitting read urb",__func__);
                spin_lock_irqsave(&priv->lock, flags);
                // reserve read urb
                set_bit(0, &priv->read_urb_pool_lock);
                spin_unlock_irqrestore(&priv->lock, flags);
                retval = usb_submit_urb(priv->read_urb_pool[urb_index],
                                GFP_ATOMIC);
                if (retval != 0)
                {
                        spin_lock_irqsave(&priv->lock, flags);
                        clear_bit(0, &priv->read_urb_pool_lock);
                        spin_unlock_irqrestore(&priv->lock, flags);
                        return;  //  -ENODEV;
                }

                t = wait_event_timeout(priv->wait_flag,
                 (test_bit(urb_index, &priv->read_urb_pool_lock)==0),
                        COMMAND_TIMEOUT);
                if (!t)
                {
                        dbg("%s - read urb timed out.", __func__);
                }
        }
        usb_serial_port_softint(port);
}

static void  usbrsa_test_read_callback(struct urb *urb)
{
        struct usb_serial_port*         port    = urb->context;
        struct usbrsa_port_private*     priv    =
             usb_get_serial_port_data(port);
        struct tty_struct*                      tty;
        int                             status  = urb->status;
        unsigned char*                  data    = urb->transfer_buffer;
        unsigned long                           flags;

        dbg("%s() - port = %d", __func__, port->number);
        usb_serial_debug_data(debug, &port->dev, __func__,
                        urb->actual_length, data);


        // copy payload to tty buffer


        tty = tty_port_tty_get(&port->port);
        if (tty != NULL && urb->actual_length > 0) 
        {
                tty_insert_flip_string(tty, data, urb->actual_length);
        }
        tty_kref_put(tty);

        // return urb to pool
        dbg("%s: return URB %d",__func__,urb_index);
        spin_lock_irqsave(&priv->lock, flags);
        clear_bit(0, &priv->read_urb_pool_lock);
        spin_unlock_irqrestore(&priv->lock, flags);
        if (status)
        {
                dbg("%s: nonzero urb status: 0x%d", __func__, status);
        }
//      usb_serial_port_softint(port);
}


--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux