From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796225593; b=Oi4DyKCSlV1xBBkTaX8UFnhMenU5BDjorA8sncvzSrGC7zKWQzMq1RN7pOOh6RYXtE0M uvybGYYuDeMGPuiX6oolB5XM5/ywW2Abz0xCMMsJsE5trPJCh5r3jjddzOszkY0/fdXBc H4KB9mylazNnUkuDwUO6s7L2MIG6wARo1ql4qa378As+zadJpvEERRHiaHvD5ei9lX7DL 169KVJRk/LZHMlEDcN9+4eP4lt+dkvdnKj+4Rrpjo6P/Oahe5YhLUf4edkEQWTc1tqnUu q9UfxRqqhIJ0knkCTqIa2fruykzwNuGhfHzzk0T0uVV0i4NTo9nq+j7jcrLyPrRlXnw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796225593; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition: Content-Transfer-Encoding:In-Reply-To; bh=G/Ghhl1sS4hi7O/zcayxHX65xSTn6xS0RQmnaJOltpM=; b=Ks13xZ3arfGeppJXkKCZt2ZS/Zmb2Fk7aQgNbLyy2MxmXPGalgiaz0NqFdBJ9F7dg5Oe mxuIzzmd2EUsbJKelCRHXK4YlwgxuhsrCnd9MSK87dLlMbmfp5i9mRcOIvnT9KMG78AYR Ih1UXQ1TdtZe0O7X6Fhg0/1he7BbjMrZXZStxBxszBM1NyjLJZdjel9zdnLCN7d19I8Ie Qe9GrgsP6ozkDAh8XXPl6+m6tPTlT7pIH3jTYjfUJC6h4CotbfYBEHZFjVRxGNn8bISip RE3lei1q4XXuqhh848lEtitN3cpDsgrcPKesvPSPMiYKBWuEiJ30+/I8VbtrZSKPsdw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=E+Fl5XDw; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C6BA4606A325; Wed, 2 Dec 2026 15:33:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=E+Fl5XDw Received: by smtp.kernel.org (Postfix) with ESMTPSA id D89A91F00896; Wed, 2 Dec 2026 15:33:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796225593; bh=G/Ghhl1sS4hi7O/zcayxHX65xSTn6xS0RQmnaJOltpM=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=E+Fl5XDwCZYCSBwfiKFKRPwYndBEqX1m1XZ60OGi69PxuGspXu5tTNbeD7nV1l+N7 SNf8ryPPmo0x2vGuBK1t8g+Ap2/Me/ygjaVyMRwQDwaTk0TCvGZITwLwSN5Q0dv8TP ZfuQroeIU1IVhIGsZeD8oxQ0LUI3u0A2+zCSW/rxYxcp8/EUvOJCObsUK949JHxJW/ xs+FuaSB7BnRHSTU5CrfzHo8CmaEPi44l/IaBcGwhryByMYarbdnRUBvZ+hkVvUccY S47/cTRtY8B/6kKsitLYj+kW6S01gomtGJWaghwZmknOAGU+zOVEQchmAGDVMz5OAV Tl6Rbf6UM9qxQ== Date: Wed, 2 Dec 2026 15:33:09 +0000 From: Lee Jones To: Svyatoslav Ryhel Cc: Pavel Machek , Griffin Kroah-Hartman , linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v1 1/2] leds: lm3533: Clean up probe and use managed helpers Message-ID: <20261202153309.GF43081@kernel.org> References: <20261115084347.70592-1-clamor95@gmail.com> <20261115084347.70592-2-clamor95@gmail.com> <179510287166.63755.11402400428284590628@kernel.org> X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Thu, 26 Nov 2026, Svyatoslav Ryhel wrote: > чт, 26 лист. 2026 р. о 13:41 Lee Jones пише: > > > > On Sun, 15 Nov 2026, Svyatoslav Ryhel wrote: > > > > > Clean up the lm3533 LED driver probe and remove routines by adopting > > > managed device helpers and modernizing error handling: > > > > > > - Introduce a local `struct device *dev` variable to clean up repeated > > > `&pdev->dev` references. > > > - Use `dev_err_probe()` for cleaner error handling on invalid IDs and > > > LED class registration failures. > > > - Switch to `devm_led_classdev_register()` to automatically handle LED > > > class device unregistration, removing the need for manual cleanup in > > > error paths and the `remove` hook. > > > - Remove redundant `dev_dbg()` statements and cleanup unused cleanup > > > labels. > > > > > > Signed-off-by: Svyatoslav Ryhel > > > --- > > > drivers/leds/leds-lm3533.c | 48 +++++++++++--------------------------- > > > 1 file changed, 14 insertions(+), 34 deletions(-) > > > > > > diff --git a/drivers/leds/leds-lm3533.c b/drivers/leds/leds-lm3533.c > > > index d5997cbd88dfc..7db1105bee5c2 100644 > > > --- a/drivers/leds/leds-lm3533.c > > > +++ b/drivers/leds/leds-lm3533.c > > > @@ -633,22 +633,19 @@ static int lm3533_led_setup(struct lm3533_led *led) > > > > > > static int lm3533_led_probe(struct platform_device *pdev) > > > { > > > + struct device *dev = &pdev->dev; > > > struct lm3533 *lm3533; > > > struct lm3533_led *led; > > > int ret; > > > > > > - dev_dbg(&pdev->dev, "%s\n", __func__); > > > - > > > - lm3533 = dev_get_drvdata(pdev->dev.parent); > > > + lm3533 = dev_get_drvdata(dev->parent); > > > if (!lm3533) > > > return -EINVAL; > > > > > > - if (pdev->id < 0 || pdev->id >= LM3533_LVCTRLBANK_COUNT) { > > > - dev_err(&pdev->dev, "illegal LED id %d\n", pdev->id); > > > - return -EINVAL; > > > - } > > > + if (pdev->id < 0 || pdev->id >= LM3533_LVCTRLBANK_COUNT) > > > + return dev_err_probe(dev, -EINVAL, "Illegal LED id %d\n", pdev->id); > > > > > > - led = devm_kzalloc_obj(&pdev->dev, *led); > > > + led = devm_kzalloc_obj(dev, *led); > > > if (!led) > > > return -ENOMEM; > > > > > > @@ -662,14 +659,12 @@ static int lm3533_led_probe(struct platform_device *pdev) > > > led->cdev.groups = lm3533_led_attribute_groups; > > > led->id = pdev->id; > > > > > > - led->cdev.name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "%s-%d", > > > - pdev->name, led->id); > > > + led->cdev.name = devm_kasprintf(dev, GFP_KERNEL, "%s-%d", pdev->name, led->id); > > > if (!led->cdev.name) > > > return -ENOMEM; > > > > > > led->cdev.default_trigger = "none"; > > > - device_property_read_string(&pdev->dev, "linux,default-trigger", > > > - &led->cdev.default_trigger); > > > + device_property_read_string(dev, "linux,default-trigger", &led->cdev.default_trigger); > > > > > > mutex_init(&led->mutex); > > > > > > @@ -683,45 +678,30 @@ static int lm3533_led_probe(struct platform_device *pdev) > > > > > > platform_set_drvdata(pdev, led); > > > > > > - ret = led_classdev_register(&pdev->dev, &led->cdev); > > > - if (ret) { > > > - dev_err(&pdev->dev, "failed to register LED %d\n", pdev->id); > > > - return ret; > > > - } > > > + ret = devm_led_classdev_register(dev, &led->cdev); > > > + if (ret) > > > + return dev_err_probe(dev, ret, "Failed to register LED %d\n", pdev->id); > > > > Using devm_led_classdev_register() here while keeping lm3533_ctrlbank_disable() > > in remove() reverses the teardown order: on unbind, the control bank will now be > > disabled before the LED class device and its active triggers/sysfs attributes > > are unregistered. > > > > This is exactly the order which originally was: disable bank > > unregister dev. I did not change it with this adjustment. Yes, it was already that way in lm3533_led_remove(). However, mixing manual teardown in remove() with devm_led_classdev_register() makes the lifecycle harder to follow and leaves the LED class device exposed after the bank has been disabled. Generally mixing managed and manual resource handling is a bad idea. > > Also, shouldn't the hardware setup and lm3533_ctrlbank_enable() happen > > before registering the LED class device (or be wrapped with > > devm_add_action_or_reset() prior to registration) so that the teardown > > order remains symmetric and the LED is ready as soon as it is exposed to > > userspace? > > > > lm3533_ctrlbank_enable() requires led device to be passed to it so no. 'led->cb.dev' is only used for dev_dbg() and dev_err() inside the ctrlbank helpers, and notice the comment and assignment just above led_classdev_register(): /* The class framework makes a callback to get brightness during * registration so use parent device (for error reporting) until * registered. */ led->cb.regmap = lm3533->regmap; led->cb.id = lm3533_led_get_ctrlbank_id(led); led->cb.dev = lm3533->dev; So 'led->cb.dev' is already populated with a valid 'struct device *' (or could simply be set to 'dev') before registration. There is no reason lm3533_led_setup() and lm3533_ctrlbank_enable() cannot run before devm_led_classdev_register(). -- Lee Jones