Skip to content

Commit ae149b6

Browse files
Alexey Dobriyantorvalds
authored andcommitted
proc tty: add struct tty_operations::proc_fops
Used for gradual switch of TTY drivers from using ->read_proc which helps with gradual switch from ->read_proc for the whole tree. As side effect, fix possible race condition when ->data initialized after PDE is hooked into proc tree. ->proc_fops takes precedence over ->read_proc. Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com> Cc: Alan Cox <alan@lxorguk.ukuu.org.uk> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 15f7176 commit ae149b6

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

‎fs/proc/proc_tty.c‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -144,16 +144,22 @@ void proc_tty_register_driver(struct tty_driver *driver)
144144
{
145145
struct proc_dir_entry *ent;
146146

147-
if (!driver->ops->read_proc || !driver->driver_name ||
148-
driver->proc_entry)
147+
if (!driver->driver_name || driver->proc_entry)
149148
return;
150149

151-
ent = create_proc_entry(driver->driver_name, 0, proc_tty_driver);
152-
if (!ent)
150+
if (driver->ops->proc_fops) {
151+
ent = proc_create_data(driver->driver_name, 0, proc_tty_driver,
152+
driver->ops->proc_fops, driver);
153+
if (!ent)
154+
return;
155+
} else if (driver->ops->read_proc) {
156+
ent = create_proc_entry(driver->driver_name, 0, proc_tty_driver);
157+
if (!ent)
158+
return;
159+
ent->read_proc = driver->ops->read_proc;
160+
ent->data = driver;
161+
} else
153162
return;
154-
ent->read_proc = driver->ops->read_proc;
155-
ent->data = driver;
156-
157163
driver->proc_entry = ent;
158164
}
159165

‎include/linux/tty_driver.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ struct tty_operations {
264264
int (*poll_get_char)(struct tty_driver *driver, int line);
265265
void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
266266
#endif
267+
const struct file_operations *proc_fops;
267268
};
268269

269270
struct tty_driver {

0 commit comments

Comments
 (0)