Skip to content

Commit

Permalink
proc tty: add struct tty_operations::proc_fops
Browse files Browse the repository at this point in the history
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 <[email protected]>
Cc: Alan Cox <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Alexey Dobriyan authored and torvalds committed Apr 1, 2009
1 parent 15f7176 commit ae149b6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
20 changes: 13 additions & 7 deletions fs/proc/proc_tty.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,16 +144,22 @@ void proc_tty_register_driver(struct tty_driver *driver)
{
struct proc_dir_entry *ent;

if (!driver->ops->read_proc || !driver->driver_name ||
driver->proc_entry)
if (!driver->driver_name || driver->proc_entry)
return;

ent = create_proc_entry(driver->driver_name, 0, proc_tty_driver);
if (!ent)
if (driver->ops->proc_fops) {
ent = proc_create_data(driver->driver_name, 0, proc_tty_driver,
driver->ops->proc_fops, driver);
if (!ent)
return;
} else if (driver->ops->read_proc) {
ent = create_proc_entry(driver->driver_name, 0, proc_tty_driver);
if (!ent)
return;
ent->read_proc = driver->ops->read_proc;
ent->data = driver;
} else
return;
ent->read_proc = driver->ops->read_proc;
ent->data = driver;

driver->proc_entry = ent;
}

Expand Down
1 change: 1 addition & 0 deletions include/linux/tty_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ struct tty_operations {
int (*poll_get_char)(struct tty_driver *driver, int line);
void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
#endif
const struct file_operations *proc_fops;
};

struct tty_driver {
Expand Down

0 comments on commit ae149b6

Please sign in to comment.