leds: trigger: Fix error path to not unlock the unlocked mutex
authorUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Fri, 19 Feb 2021 13:33:06 +0000 (14:33 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 10 Mar 2021 08:27:55 +0000 (09:27 +0100)
ttyname is allocated before the mutex is taken, so it must not be
unlocked in the error path.

Fixes: fd4a641ac88f ("leds: trigger: implement a tty trigger")
Reported-by: Pavel Machek <pavel@ucw.cz>
Acked-by: Pavel Machek <pavel@ucw.cz>
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Link: https://lore.kernel.org/r/20210219133307.4840-2-u.kleine-koenig@pengutronix.de
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/leds/trigger/ledtrig-tty.c

index d2ab6ab..af61281 100644 (file)
@@ -51,10 +51,8 @@ static ssize_t ttyname_store(struct device *dev,
 
        if (size) {
                ttyname = kmemdup_nul(buf, size, GFP_KERNEL);
-               if (!ttyname) {
-                       ret = -ENOMEM;
-                       goto out_unlock;
-               }
+               if (!ttyname)
+                       return -ENOMEM;
        } else {
                ttyname = NULL;
        }
@@ -69,7 +67,6 @@ static ssize_t ttyname_store(struct device *dev,
 
        trigger_data->ttyname = ttyname;
 
-out_unlock:
        mutex_unlock(&trigger_data->mutex);
 
        if (ttyname && !running)