]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
input: remove f_version abuse
authorChristian Brauner <brauner@kernel.org>
Fri, 30 Aug 2024 13:04:53 +0000 (15:04 +0200)
committerChristian Brauner <brauner@kernel.org>
Thu, 12 Sep 2024 09:56:07 +0000 (11:56 +0200)
f_version is removed from struct file. Make input stop abusing f_version
for stashing information for poll. Move the input state counter into
input_seq_state and allocate it via seq_private_open() and free via
seq_release_private().

Link: https://lore.kernel.org/r/20240830-vfs-file-f_version-v1-12-6d3e4816aa7b@kernel.org
Reviewed-by: Jan Kara <jack@suse.cz>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Christian Brauner <brauner@kernel.org>
drivers/input/input.c

index 54c57b267b25f7e2b4fc46b53507588a40226b03..19ea1888da9f85b93805c473cbc4b72b9ab0389f 100644 (file)
@@ -1079,33 +1079,31 @@ static inline void input_wakeup_procfs_readers(void)
        wake_up(&input_devices_poll_wait);
 }
 
+struct input_seq_state {
+       unsigned short pos;
+       bool mutex_acquired;
+       int input_devices_state;
+};
+
 static __poll_t input_proc_devices_poll(struct file *file, poll_table *wait)
 {
+       struct seq_file *seq = file->private_data;
+       struct input_seq_state *state = seq->private;
+
        poll_wait(file, &input_devices_poll_wait, wait);
-       if (file->f_version != input_devices_state) {
-               file->f_version = input_devices_state;
+       if (state->input_devices_state != input_devices_state) {
+               state->input_devices_state = input_devices_state;
                return EPOLLIN | EPOLLRDNORM;
        }
 
        return 0;
 }
 
-union input_seq_state {
-       struct {
-               unsigned short pos;
-               bool mutex_acquired;
-       };
-       void *p;
-};
-
 static void *input_devices_seq_start(struct seq_file *seq, loff_t *pos)
 {
-       union input_seq_state *state = (union input_seq_state *)&seq->private;
+       struct input_seq_state *state = seq->private;
        int error;
 
-       /* We need to fit into seq->private pointer */
-       BUILD_BUG_ON(sizeof(union input_seq_state) != sizeof(seq->private));
-
        error = mutex_lock_interruptible(&input_mutex);
        if (error) {
                state->mutex_acquired = false;
@@ -1124,7 +1122,7 @@ static void *input_devices_seq_next(struct seq_file *seq, void *v, loff_t *pos)
 
 static void input_seq_stop(struct seq_file *seq, void *v)
 {
-       union input_seq_state *state = (union input_seq_state *)&seq->private;
+       struct input_seq_state *state = seq->private;
 
        if (state->mutex_acquired)
                mutex_unlock(&input_mutex);
@@ -1210,7 +1208,8 @@ static const struct seq_operations input_devices_seq_ops = {
 
 static int input_proc_devices_open(struct inode *inode, struct file *file)
 {
-       return seq_open(file, &input_devices_seq_ops);
+       return seq_open_private(file, &input_devices_seq_ops,
+                               sizeof(struct input_seq_state));
 }
 
 static const struct proc_ops input_devices_proc_ops = {
@@ -1218,17 +1217,14 @@ static const struct proc_ops input_devices_proc_ops = {
        .proc_poll      = input_proc_devices_poll,
        .proc_read      = seq_read,
        .proc_lseek     = seq_lseek,
-       .proc_release   = seq_release,
+       .proc_release   = seq_release_private,
 };
 
 static void *input_handlers_seq_start(struct seq_file *seq, loff_t *pos)
 {
-       union input_seq_state *state = (union input_seq_state *)&seq->private;
+       struct input_seq_state *state = seq->private;
        int error;
 
-       /* We need to fit into seq->private pointer */
-       BUILD_BUG_ON(sizeof(union input_seq_state) != sizeof(seq->private));
-
        error = mutex_lock_interruptible(&input_mutex);
        if (error) {
                state->mutex_acquired = false;
@@ -1243,7 +1239,7 @@ static void *input_handlers_seq_start(struct seq_file *seq, loff_t *pos)
 
 static void *input_handlers_seq_next(struct seq_file *seq, void *v, loff_t *pos)
 {
-       union input_seq_state *state = (union input_seq_state *)&seq->private;
+       struct input_seq_state *state = seq->private;
 
        state->pos = *pos + 1;
        return seq_list_next(v, &input_handler_list, pos);
@@ -1252,7 +1248,7 @@ static void *input_handlers_seq_next(struct seq_file *seq, void *v, loff_t *pos)
 static int input_handlers_seq_show(struct seq_file *seq, void *v)
 {
        struct input_handler *handler = container_of(v, struct input_handler, node);
-       union input_seq_state *state = (union input_seq_state *)&seq->private;
+       struct input_seq_state *state = seq->private;
 
        seq_printf(seq, "N: Number=%u Name=%s", state->pos, handler->name);
        if (handler->filter)
@@ -1273,14 +1269,15 @@ static const struct seq_operations input_handlers_seq_ops = {
 
 static int input_proc_handlers_open(struct inode *inode, struct file *file)
 {
-       return seq_open(file, &input_handlers_seq_ops);
+       return seq_open_private(file, &input_handlers_seq_ops,
+                               sizeof(struct input_seq_state));
 }
 
 static const struct proc_ops input_handlers_proc_ops = {
        .proc_open      = input_proc_handlers_open,
        .proc_read      = seq_read,
        .proc_lseek     = seq_lseek,
-       .proc_release   = seq_release,
+       .proc_release   = seq_release_private,
 };
 
 static int __init input_proc_init(void)