* [PATCH] mux: core: Replace manual put_device() with __free(put_device)
@ 2026-06-02 4:36 Maxwell Doose
2026-06-02 9:03 ` Peter Rosin
0 siblings, 1 reply; 3+ messages in thread
From: Maxwell Doose @ 2026-06-02 4:36 UTC (permalink / raw)
To: peda; +Cc: open list
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 | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/drivers/mux/core.c b/drivers/mux/core.c
index 23538de2c91b..a31e06388588 100644
--- a/drivers/mux/core.c
+++ b/drivers/mux/core.c
@@ -586,13 +586,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 +608,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,7 +618,6 @@ 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);
}
--
2.54.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] mux: core: Replace manual put_device() with __free(put_device)
2026-06-02 4:36 [PATCH] mux: core: Replace manual put_device() with __free(put_device) Maxwell Doose
@ 2026-06-02 9:03 ` Peter Rosin
2026-06-02 16:17 ` Maxwell Doose
0 siblings, 1 reply; 3+ messages in thread
From: Peter Rosin @ 2026-06-02 9:03 UTC (permalink / raw)
To: Maxwell Doose; +Cc: open list
Hi!
On 2026-06-02 06:36, Maxwell Doose 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 | 4 +---
> 1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/drivers/mux/core.c b/drivers/mux/core.c
> index 23538de2c91b..a31e06388588 100644
> --- a/drivers/mux/core.c
> +++ b/drivers/mux/core.c
> @@ -586,13 +586,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;
This will also run put_device() on success, which IIUC is broken.
I'm not sure it makes sense to use __free() when the exit behavior
is conditional like this?
Cheers,
Peter
> 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 +608,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,7 +618,6 @@ 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);
> }
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] mux: core: Replace manual put_device() with __free(put_device)
2026-06-02 9:03 ` Peter Rosin
@ 2026-06-02 16:17 ` Maxwell Doose
0 siblings, 0 replies; 3+ messages in thread
From: Maxwell Doose @ 2026-06-02 16:17 UTC (permalink / raw)
To: Peter Rosin; +Cc: open list
On Tue, 2 Jun 2026 11:03:45 +0200
Peter Rosin <peda@lysator.liu.se> wrote:
> Hi!
>
> On 2026-06-02 06:36, Maxwell Doose 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 | 4 +---
> > 1 file changed, 1 insertion(+), 3 deletions(-)
> >
> > diff --git a/drivers/mux/core.c b/drivers/mux/core.c
> > index 23538de2c91b..a31e06388588 100644
> > --- a/drivers/mux/core.c
> > +++ b/drivers/mux/core.c
> > @@ -586,13 +586,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;
>
> This will also run put_device() on success, which IIUC is broken.
Shoot, I must've missed the no_free_ptr() at the end. Nice catch.
> I'm not sure it makes sense to use __free() when the exit behavior
> is conditional like this?
I guess once we do no_free_ptr() then it should be fine, since
that should prevent the put_device() from firing on the happy path.
--
best regards,
max
ps:
I hope I'm not wasting your time, I was just looking at random
subsystems and I thought mux would be rather interesting given how
small it is (I do stuff in iio, and the contrast is crazy to me!)
Regarding why I sent this patch, it's mostly because this subsystem
interested me but I quite literally couldn't find anything to fix
(except one single const-correctness issue that checkpatch pointed
out)!
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-06-02 16:17 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-02 4:36 [PATCH] mux: core: Replace manual put_device() with __free(put_device) Maxwell Doose
2026-06-02 9:03 ` Peter Rosin
2026-06-02 16:17 ` Maxwell Doose
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.