Skip to content

Commit

Permalink
Input: synaptics_i2c - switch to using __cancel_delayed_work()
Browse files Browse the repository at this point in the history
cancel_delayed_work() may spin and therefore should not be used in
interrupt contexts.

Acked-by: Mike Rapoport <mike@compulab.co.il>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
  • Loading branch information
Dmitry Torokhov committed Sep 18, 2009
1 parent 36fb252 commit 30b3713
Showing 1 changed file with 32 additions and 19 deletions.
51 changes: 32 additions & 19 deletions drivers/input/mouse/synaptics_i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ MODULE_PARM_DESC(no_filter, "No Filter. Default = 0 (off)");
* and the irq configuration should be set to Falling Edge Trigger
*/
/* Control IRQ / Polling option */
static int polling_req;
static bool polling_req;
module_param(polling_req, bool, 0444);
MODULE_PARM_DESC(polling_req, "Request Polling. Default = 0 (use irq)");

Expand All @@ -217,6 +217,7 @@ struct synaptics_i2c {
struct i2c_client *client;
struct input_dev *input;
struct delayed_work dwork;
spinlock_t lock;
int no_data_count;
int no_decel_param;
int reduce_report_param;
Expand Down Expand Up @@ -366,17 +367,28 @@ static bool synaptics_i2c_get_input(struct synaptics_i2c *touch)
return xy_delta || gesture;
}

static irqreturn_t synaptics_i2c_irq(int irq, void *dev_id)
static void synaptics_i2c_reschedule_work(struct synaptics_i2c *touch,
unsigned long delay)
{
struct synaptics_i2c *touch = dev_id;
unsigned long flags;

spin_lock_irqsave(&touch->lock, flags);

/*
* We want to have the work run immediately but it might have
* already been scheduled with a delay, that's why we have to
* cancel it first.
* If work is already scheduled then subsequent schedules will not
* change the scheduled time that's why we have to cancel it first.
*/
cancel_delayed_work(&touch->dwork);
schedule_delayed_work(&touch->dwork, 0);
__cancel_delayed_work(&touch->dwork);
schedule_delayed_work(&touch->dwork, delay);

spin_unlock_irqrestore(&touch->lock, flags);
}

static irqreturn_t synaptics_i2c_irq(int irq, void *dev_id)
{
struct synaptics_i2c *touch = dev_id;

synaptics_i2c_reschedule_work(touch, 0);

return IRQ_HANDLED;
}
Expand Down Expand Up @@ -452,7 +464,7 @@ static void synaptics_i2c_work_handler(struct work_struct *work)
* We poll the device once in THREAD_IRQ_SLEEP_SECS and
* if error is detected, we try to reset and reconfigure the touchpad.
*/
schedule_delayed_work(&touch->dwork, delay);
synaptics_i2c_reschedule_work(touch, delay);
}

static int synaptics_i2c_open(struct input_dev *input)
Expand All @@ -465,8 +477,8 @@ static int synaptics_i2c_open(struct input_dev *input)
return ret;

if (polling_req)
schedule_delayed_work(&touch->dwork,
msecs_to_jiffies(NO_DATA_SLEEP_MSECS));
synaptics_i2c_reschedule_work(touch,
msecs_to_jiffies(NO_DATA_SLEEP_MSECS));

return 0;
}
Expand Down Expand Up @@ -521,6 +533,7 @@ struct synaptics_i2c *synaptics_i2c_touch_create(struct i2c_client *client)
touch->scan_rate_param = scan_rate;
set_scan_rate(touch, scan_rate);
INIT_DELAYED_WORK(&touch->dwork, synaptics_i2c_work_handler);
spin_lock_init(&touch->lock);

return touch;
}
Expand All @@ -535,14 +548,12 @@ static int __devinit synaptics_i2c_probe(struct i2c_client *client,
if (!touch)
return -ENOMEM;

i2c_set_clientdata(client, touch);

ret = synaptics_i2c_reset_config(client);
if (ret)
goto err_mem_free;

if (client->irq < 1)
polling_req = 1;
polling_req = true;

touch->input = input_allocate_device();
if (!touch->input) {
Expand All @@ -563,7 +574,7 @@ static int __devinit synaptics_i2c_probe(struct i2c_client *client,
dev_warn(&touch->client->dev,
"IRQ request failed: %d, "
"falling back to polling\n", ret);
polling_req = 1;
polling_req = true;
synaptics_i2c_reg_set(touch->client,
INTERRUPT_EN_REG, 0);
}
Expand All @@ -580,12 +591,14 @@ static int __devinit synaptics_i2c_probe(struct i2c_client *client,
"Input device register failed: %d\n", ret);
goto err_input_free;
}

i2c_set_clientdata(client, touch);

return 0;

err_input_free:
input_free_device(touch->input);
err_mem_free:
i2c_set_clientdata(client, NULL);
kfree(touch);

return ret;
Expand All @@ -596,7 +609,7 @@ static int __devexit synaptics_i2c_remove(struct i2c_client *client)
struct synaptics_i2c *touch = i2c_get_clientdata(client);

if (!polling_req)
free_irq(touch->client->irq, touch);
free_irq(client->irq, touch);

input_unregister_device(touch->input);
i2c_set_clientdata(client, NULL);
Expand Down Expand Up @@ -627,8 +640,8 @@ static int synaptics_i2c_resume(struct i2c_client *client)
if (ret)
return ret;

schedule_delayed_work(&touch->dwork,
msecs_to_jiffies(NO_DATA_SLEEP_MSECS));
synaptics_i2c_reschedule_work(touch,
msecs_to_jiffies(NO_DATA_SLEEP_MSECS));

return 0;
}
Expand Down

0 comments on commit 30b3713

Please sign in to comment.