Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c453615f authored by Hans de Goede's avatar Hans de Goede Committed by Jean Delvare
Browse files

hwmon: (fschmd) Fix a memleak on multiple opens of /dev/watchdog



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: default avatarHans de Goede <hdegoede@redhat.com>
Signed-off-by: default avatarJean Delvare <khali@linux-fr.org>
Cc: stable@kernel.org
parent 5542482b
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -768,6 +768,7 @@ static int watchdog_stop(struct fschmd_data *data)
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
@@ -782,10 +783,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 */
	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 */