All of lore.kernel.org
 help / color / mirror / Atom feed
From: Maxwell Doose <m32285159@gmail.com>
To: peda@lysator.liu.se
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] mux: core: Replace manual put_device() with __free(put_device)
Date: Tue, 2 Jun 2026 11:39:45 -0500	[thread overview]
Message-ID: <20260602113945.6713960e@linuxescape> (raw)
In-Reply-To: <20260602162833.339562-1-m32285159@gmail.com>

On Tue,  2 Jun 2026 11:28:33 -0500
Maxwell Doose <m32285159@gmail.com> wrote:

> The current code for returning on failure in mux_get() uses manual
> put_device() calls. Refactor and replace them with a new variable for
> the pointer to the underlying device and __free(put_device).
> 
> Signed-off-by: Maxwell Doose <m32285159@gmail.com>
> ---
>  drivers/mux/core.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
>  v2:
>  - Add explicit cleanup.h header.
>  - Add no_free_ptr() at the end of the happy path to prevent
>    accidentially calling put_device() where it shouldn't.
> 
> diff --git a/drivers/mux/core.c b/drivers/mux/core.c
> index 23538de2c91b..7c9180dfaff6 100644
> --- a/drivers/mux/core.c
> +++ b/drivers/mux/core.c
> @@ -9,6 +9,7 @@
>  
>  #define pr_fmt(fmt) "mux-core: " fmt
>  
> +#include <linux/cleanup.h>
>  #include <linux/delay.h>
>  #include <linux/device.h>
>  #include <linux/err.h>
> @@ -586,13 +587,13 @@ static struct mux_control *mux_get(struct device *dev, const char *mux_name,
>  	if (!mux_chip)
>  		return ERR_PTR(-EPROBE_DEFER);
>  
> +	struct device *mux_dev __free(put_device) = &mux_chip->dev;
>  	controller = 0;
>  	if (state) {
>  		if (args.args_count > 2 || args.args_count == 0 ||
>  		    (args.args_count < 2 && mux_chip->controllers > 1)) {
>  			dev_err(dev, "%pOF: wrong #mux-state-cells for %pOF\n",
>  				np, args.np);
> -			put_device(&mux_chip->dev);
>  			return ERR_PTR(-EINVAL);
>  		}
>  
> @@ -608,7 +609,6 @@ static struct mux_control *mux_get(struct device *dev, const char *mux_name,
>  		    (!args.args_count && mux_chip->controllers > 1)) {
>  			dev_err(dev, "%pOF: wrong #mux-control-cells for %pOF\n",
>  				np, args.np);
> -			put_device(&mux_chip->dev);
>  			return ERR_PTR(-EINVAL);
>  		}
>  
> @@ -619,10 +619,11 @@ static struct mux_control *mux_get(struct device *dev, const char *mux_name,
>  	if (controller >= mux_chip->controllers) {
>  		dev_err(dev, "%pOF: bad mux controller %u specified in %pOF\n",
>  			np, controller, args.np);
> -		put_device(&mux_chip->dev);
>  		return ERR_PTR(-EINVAL);
>  	}
>  
> +	no_free_ptr(mux_dev);
> +
>  	return &mux_chip->mux[controller];
>  }
>  

Disregard, I accidentally forgot to build and now GCC is screaming at
me with "ignoring return value of..." errors.

-- 
best regards,
max

      reply	other threads:[~2026-06-02 16:39 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-02 16:28 [PATCH v2] mux: core: Replace manual put_device() with __free(put_device) Maxwell Doose
2026-06-02 16:39 ` Maxwell Doose [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260602113945.6713960e@linuxescape \
    --to=m32285159@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peda@lysator.liu.se \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.