hc
2024-05-10 23fa18eaa71266feff7ba8d83022d9e1cc83c65a
kernel/drivers/input/evdev.c
....@@ -1,11 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Event char devices, giving access to raw input device events.
34 *
45 * Copyright (c) 1999-2002 Vojtech Pavlik
5
- *
6
- * This program is free software; you can redistribute it and/or modify it
7
- * under the terms of the GNU General Public License version 2 as published by
8
- * the Free Software Foundation.
96 */
107
118 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
....@@ -31,7 +28,6 @@
3128 struct evdev {
3229 int open;
3330 struct input_handle handle;
34
- wait_queue_head_t wait;
3531 struct evdev_client __rcu *grab;
3632 struct list_head client_list;
3733 spinlock_t client_lock; /* protects client_list */
....@@ -46,6 +42,7 @@
4642 unsigned int tail;
4743 unsigned int packet_head; /* [future] position of the first element of next packet */
4844 spinlock_t buffer_lock; /* protects access to buffer, head and tail */
45
+ wait_queue_head_t wait;
4946 struct fasync_struct *fasync;
5047 struct evdev *evdev;
5148 struct list_head node;
....@@ -248,7 +245,6 @@
248245 const struct input_value *vals, unsigned int count,
249246 ktime_t *ev_time)
250247 {
251
- struct evdev *evdev = client->evdev;
252248 const struct input_value *v;
253249 struct input_event event;
254250 struct timespec64 ts;
....@@ -285,7 +281,8 @@
285281 spin_unlock(&client->buffer_lock);
286282
287283 if (wakeup)
288
- wake_up_interruptible(&evdev->wait);
284
+ wake_up_interruptible_poll(&client->wait,
285
+ EPOLLIN | EPOLLOUT | EPOLLRDNORM | EPOLLWRNORM);
289286 }
290287
291288 /*
....@@ -428,11 +425,11 @@
428425 struct evdev_client *client;
429426
430427 spin_lock(&evdev->client_lock);
431
- list_for_each_entry(client, &evdev->client_list, node)
428
+ list_for_each_entry(client, &evdev->client_list, node) {
432429 kill_fasync(&client->fasync, SIGIO, POLL_HUP);
430
+ wake_up_interruptible_poll(&client->wait, EPOLLHUP | EPOLLERR);
431
+ }
433432 spin_unlock(&evdev->client_lock);
434
-
435
- wake_up_interruptible(&evdev->wait);
436433 }
437434
438435 static int evdev_release(struct inode *inode, struct file *file)
....@@ -474,17 +471,14 @@
474471 {
475472 struct evdev *evdev = container_of(inode->i_cdev, struct evdev, cdev);
476473 unsigned int bufsize = evdev_compute_buffer_size(evdev->handle.dev);
477
- unsigned int size = sizeof(struct evdev_client) +
478
- bufsize * sizeof(struct input_event);
479474 struct evdev_client *client;
480475 int error;
481476
482
- client = kzalloc(size, GFP_KERNEL | __GFP_NOWARN);
483
- if (!client)
484
- client = vzalloc(size);
477
+ client = kvzalloc(struct_size(client, buffer, bufsize), GFP_KERNEL);
485478 if (!client)
486479 return -ENOMEM;
487480
481
+ init_waitqueue_head(&client->wait);
488482 client->bufsize = bufsize;
489483 spin_lock_init(&client->buffer_lock);
490484 client->evdev = evdev;
....@@ -495,7 +489,7 @@
495489 goto err_free_client;
496490
497491 file->private_data = client;
498
- nonseekable_open(inode, file);
492
+ stream_open(inode, file);
499493
500494 return 0;
501495
....@@ -601,7 +595,7 @@
601595 break;
602596
603597 if (!(file->f_flags & O_NONBLOCK)) {
604
- error = wait_event_interruptible(evdev->wait,
598
+ error = wait_event_interruptible(client->wait,
605599 client->packet_head != client->tail ||
606600 !evdev->exist || client->revoked);
607601 if (error)
....@@ -619,7 +613,7 @@
619613 struct evdev *evdev = client->evdev;
620614 __poll_t mask;
621615
622
- poll_wait(file, &evdev->wait, wait);
616
+ poll_wait(file, &client->wait, wait);
623617
624618 if (evdev->exist && !client->revoked)
625619 mask = EPOLLOUT | EPOLLWRNORM;
....@@ -952,7 +946,7 @@
952946 client->revoked = true;
953947 evdev_ungrab(evdev, client);
954948 input_flush_device(&evdev->handle, file);
955
- wake_up_interruptible(&evdev->wait);
949
+ wake_up_interruptible_poll(&client->wait, EPOLLHUP | EPOLLERR);
956950
957951 return 0;
958952 }
....@@ -1364,7 +1358,6 @@
13641358 INIT_LIST_HEAD(&evdev->client_list);
13651359 spin_lock_init(&evdev->client_lock);
13661360 mutex_init(&evdev->mutex);
1367
- init_waitqueue_head(&evdev->wait);
13681361 evdev->exist = true;
13691362
13701363 dev_no = minor;