Skip to content

Commit e490ebd

Browse files
committed
Input: input-polldev - use system-wide freezable workqueue
With introduction of concurrency-managed work queues there is rarely a point in creating private workqueues. Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
1 parent 34abeeb commit e490ebd

1 file changed

Lines changed: 3 additions & 53 deletions

File tree

‎drivers/input/input-polldev.c‎

Lines changed: 3 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -13,51 +13,14 @@
1313
#include <linux/jiffies.h>
1414
#include <linux/slab.h>
1515
#include <linux/mutex.h>
16+
#include <linux/workqueue.h>
1617
#include <linux/input-polldev.h>
1718

1819
MODULE_AUTHOR("Dmitry Torokhov <dtor@mail.ru>");
1920
MODULE_DESCRIPTION("Generic implementation of a polled input device");
2021
MODULE_LICENSE("GPL v2");
2122
MODULE_VERSION("0.1");
2223

23-
static DEFINE_MUTEX(polldev_mutex);
24-
static int polldev_users;
25-
static struct workqueue_struct *polldev_wq;
26-
27-
static int input_polldev_start_workqueue(void)
28-
{
29-
int retval;
30-
31-
retval = mutex_lock_interruptible(&polldev_mutex);
32-
if (retval)
33-
return retval;
34-
35-
if (!polldev_users) {
36-
polldev_wq = create_singlethread_workqueue("ipolldevd");
37-
if (!polldev_wq) {
38-
pr_err("failed to create ipolldevd workqueue\n");
39-
retval = -ENOMEM;
40-
goto out;
41-
}
42-
}
43-
44-
polldev_users++;
45-
46-
out:
47-
mutex_unlock(&polldev_mutex);
48-
return retval;
49-
}
50-
51-
static void input_polldev_stop_workqueue(void)
52-
{
53-
mutex_lock(&polldev_mutex);
54-
55-
if (!--polldev_users)
56-
destroy_workqueue(polldev_wq);
57-
58-
mutex_unlock(&polldev_mutex);
59-
}
60-
6124
static void input_polldev_queue_work(struct input_polled_dev *dev)
6225
{
6326
unsigned long delay;
@@ -66,7 +29,7 @@ static void input_polldev_queue_work(struct input_polled_dev *dev)
6629
if (delay >= HZ)
6730
delay = round_jiffies_relative(delay);
6831

69-
queue_delayed_work(polldev_wq, &dev->work, delay);
32+
queue_delayed_work(system_freezable_wq, &dev->work, delay);
7033
}
7134

7235
static void input_polled_device_work(struct work_struct *work)
@@ -81,18 +44,13 @@ static void input_polled_device_work(struct work_struct *work)
8144
static int input_open_polled_device(struct input_dev *input)
8245
{
8346
struct input_polled_dev *dev = input_get_drvdata(input);
84-
int error;
85-
86-
error = input_polldev_start_workqueue();
87-
if (error)
88-
return error;
8947

9048
if (dev->open)
9149
dev->open(dev);
9250

9351
/* Only start polling if polling is enabled */
9452
if (dev->poll_interval > 0)
95-
queue_delayed_work(polldev_wq, &dev->work, 0);
53+
queue_delayed_work(system_freezable_wq, &dev->work, 0);
9654

9755
return 0;
9856
}
@@ -102,13 +60,6 @@ static void input_close_polled_device(struct input_dev *input)
10260
struct input_polled_dev *dev = input_get_drvdata(input);
10361

10462
cancel_delayed_work_sync(&dev->work);
105-
/*
106-
* Clean up work struct to remove references to the workqueue.
107-
* It may be destroyed by the next call. This causes problems
108-
* at next device open-close in case of poll_interval == 0.
109-
*/
110-
INIT_DELAYED_WORK(&dev->work, dev->work.work.func);
111-
input_polldev_stop_workqueue();
11263

11364
if (dev->close)
11465
dev->close(dev);
@@ -295,4 +246,3 @@ void input_unregister_polled_device(struct input_polled_dev *dev)
295246
input_unregister_device(dev->input);
296247
}
297248
EXPORT_SYMBOL(input_unregister_polled_device);
298-

0 commit comments

Comments
 (0)