Skip to content

Commit

Permalink
Input: reset name, phys and uniq when unregistering
Browse files Browse the repository at this point in the history
Name, phys and uniq are quite often constant strings in moules implementing
particular input device. If a module unregisters input device and then gets
unloaded, the device could still be present in memory (pinned via sysfs),
but aforementioned members would point to some random memory. Set them all
to NULL when unregistering so sysfs handlers won't try dereferencing them.

Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
  • Loading branch information
Dmitry Torokhov committed Jun 26, 2006
1 parent 8a3cf45 commit f60d2b1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
19 changes: 18 additions & 1 deletion drivers/input/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ MODULE_DESCRIPTION("Input core");
MODULE_LICENSE("GPL");

EXPORT_SYMBOL(input_allocate_device);
EXPORT_SYMBOL(input_free_device);
EXPORT_SYMBOL(input_register_device);
EXPORT_SYMBOL(input_unregister_device);
EXPORT_SYMBOL(input_register_handler);
Expand Down Expand Up @@ -872,13 +873,26 @@ struct input_dev *input_allocate_device(void)
dev->dynalloc = 1;
dev->cdev.class = &input_class;
class_device_initialize(&dev->cdev);
mutex_init(&dev->mutex);
INIT_LIST_HEAD(&dev->h_list);
INIT_LIST_HEAD(&dev->node);
}

return dev;
}

void input_free_device(struct input_dev *dev)
{
if (dev) {

mutex_lock(&dev->mutex);
dev->name = dev->phys = dev->uniq = NULL;
mutex_unlock(&dev->mutex);

input_put_device(dev);
}
}

int input_register_device(struct input_dev *dev)
{
static atomic_t input_no = ATOMIC_INIT(0);
Expand All @@ -895,7 +909,6 @@ int input_register_device(struct input_dev *dev)
return -EINVAL;
}

mutex_init(&dev->mutex);
set_bit(EV_SYN, dev->evbit);

/*
Expand Down Expand Up @@ -979,6 +992,10 @@ void input_unregister_device(struct input_dev *dev)
sysfs_remove_group(&dev->cdev.kobj, &input_dev_attr_group);
class_device_unregister(&dev->cdev);

mutex_lock(&dev->mutex);
dev->name = dev->phys = dev->uniq = NULL;
mutex_unlock(&dev->mutex);

input_wakeup_procfs_readers();
}

Expand Down
7 changes: 1 addition & 6 deletions include/linux/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -1005,6 +1005,7 @@ static inline void init_input_dev(struct input_dev *dev)
}

struct input_dev *input_allocate_device(void);
void input_free_device(struct input_dev *dev);

static inline struct input_dev *input_get_device(struct input_dev *dev)
{
Expand All @@ -1016,12 +1017,6 @@ static inline void input_put_device(struct input_dev *dev)
class_device_put(&dev->cdev);
}

static inline void input_free_device(struct input_dev *dev)
{
if (dev)
input_put_device(dev);
}

int input_register_device(struct input_dev *);
void input_unregister_device(struct input_dev *);

Expand Down

0 comments on commit f60d2b1

Please sign in to comment.