diff options
author | Hans de Goede <hdegoede@redhat.com> | 2010-04-01 15:55:48 -0700 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2010-04-01 15:55:48 -0700 |
commit | 04bd6922cb0f89cd3d2e6ac86792ef59d77c2b9f (patch) | |
tree | 859c7ed913f06e35fe2741340c2a46a35184691f | |
parent | 659cba5bf3d94e8e95b4d474e31886c1451cb9be (diff) | |
download | lwn-04bd6922cb0f89cd3d2e6ac86792ef59d77c2b9f.tar.gz lwn-04bd6922cb0f89cd3d2e6ac86792ef59d77c2b9f.zip |
hwmon: (fschmd) Fix a memleak on multiple opens of /dev/watchdog
commit c453615f77aa51593c1c9c9031b4278797d3fd19 upstream.
When /dev/watchdog gets opened a second time we return -EBUSY, but
we already have got a kref then, so we end up leaking our data struct.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Acked-by: Jean Delvare <jdelvare@suse.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
-rw-r--r-- | drivers/hwmon/fschmd.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/drivers/hwmon/fschmd.c b/drivers/hwmon/fschmd.c index 37ea6a45d25f..3e51d54b60f4 100644 --- a/drivers/hwmon/fschmd.c +++ b/drivers/hwmon/fschmd.c @@ -767,6 +767,7 @@ leave: static int watchdog_open(struct inode *inode, struct file *filp) { struct fschmd_data *pos, *data = NULL; + int watchdog_is_open; /* We get called from drivers/char/misc.c with misc_mtx hold, and we call misc_register() from fschmd_probe() with watchdog_data_mutex @@ -781,10 +782,12 @@ static int watchdog_open(struct inode *inode, struct file *filp) } } /* Note we can never not have found data, so we don't check for this */ - kref_get(&data->kref); + watchdog_is_open = test_and_set_bit(0, &data->watchdog_is_open); + if (!watchdog_is_open) + kref_get(&data->kref); mutex_unlock(&watchdog_data_mutex); - if (test_and_set_bit(0, &data->watchdog_is_open)) + if (watchdog_is_open) return -EBUSY; /* Start the watchdog */ |