From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9DF4C8820 for ; Fri, 10 Mar 2023 14:49:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EB594C433EF; Fri, 10 Mar 2023 14:49:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1678459769; bh=yMd6Gymr7HFRqN5mUrhgdIRnMSCW608TjzF4DbGsv6U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=x0KPMHNJUb8DkVRgTFmqUo40F391nmLScREPrfU3IsxC/LK9YwwCnbhAZeYW6eehK N66NJp2RtwLs5UVaoOud47FS+W2iFALiYTSIr4AHhy8sgO28zVHL6NhZA2nGRy8ml5 NayBQat0Zvet8S+oBQX8/HpeY69Vi8UYl+1Tpnq0= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Andy Shevchenko , Linus Walleij , Hans de Goede , Lee Jones , Sasha Levin Subject: [PATCH 5.10 112/529] leds: led-class: Add missing put_device() to led_put() Date: Fri, 10 Mar 2023 14:34:15 +0100 Message-Id: <20230310133810.181558468@linuxfoundation.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230310133804.978589368@linuxfoundation.org> References: <20230310133804.978589368@linuxfoundation.org> User-Agent: quilt/0.67 Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Hans de Goede [ Upstream commit 445110941eb94709216363f9d807d2508e64abd7 ] led_put() is used to "undo" a successful of_led_get() call, of_led_get() uses class_find_device_by_of_node() which returns a reference to the device which must be free-ed with put_device() when the caller is done with it. Add a put_device() call to led_put() to free the reference returned by class_find_device_by_of_node(). And also add a put_device() in the error-exit case of try_module_get() failing. Fixes: 699a8c7c4bd3 ("leds: Add of_led_get() and led_put()") Reviewed-by: Andy Shevchenko Reviewed-by: Linus Walleij Signed-off-by: Hans de Goede Signed-off-by: Lee Jones Link: https://lore.kernel.org/r/20230120114524.408368-2-hdegoede@redhat.com Signed-off-by: Sasha Levin --- drivers/leds/led-class.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c index 4365c1cc4505f..e28a4bb716032 100644 --- a/drivers/leds/led-class.c +++ b/drivers/leds/led-class.c @@ -242,8 +242,10 @@ struct led_classdev *of_led_get(struct device_node *np, int index) led_cdev = dev_get_drvdata(led_dev); - if (!try_module_get(led_cdev->dev->parent->driver->owner)) + if (!try_module_get(led_cdev->dev->parent->driver->owner)) { + put_device(led_cdev->dev); return ERR_PTR(-ENODEV); + } return led_cdev; } @@ -256,6 +258,7 @@ EXPORT_SYMBOL_GPL(of_led_get); void led_put(struct led_classdev *led_cdev) { module_put(led_cdev->dev->parent->driver->owner); + put_device(led_cdev->dev); } EXPORT_SYMBOL_GPL(led_put); -- 2.39.2