mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Hugo Villeneuve <hugo@hugovil.com>
To: laixiangwu <laixiangwu@cmss.chinamobile.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Jiri Slaby <jirislaby@kernel.org>,
	linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org
Subject: Re: [PATCH] serial: sc16is7xx: Fix clock leak on invalid clock frequency
Date: Thu, 12 Nov 2026 16:39:16 -0500	[thread overview]
Message-ID: <20261112163916.00d07adafb3caad1d83a2d1c@hugovil.com> (raw)
In-Reply-To: <20261030085508.1882-1-laixiangwu@cmss.chinamobile.com>

Hi,

On Fri, 30 Oct 2026 16:55:07 +0800
laixiangwu <laixiangwu@cmss.chinamobile.com> wrote:

> sc16is7xx_probe() enables the clock with clk_prepare_enable() early in
> the probe path. If the resulting clock frequency cannot be determined
> (neither from the clock itself, nor from the "clock-frequency" property
> or platform data), the driver bails out with -EINVAL, but it does so
> with a plain return, leaving the clock prepared and enabled.
> 
> All the later error paths of the probe already jump to the out_clk
> label to disable the clock. Do the same here.
> 
> Fixes: cb1b206cff46 ("serial: sc16is7xx: Use devm_clk_get_optional()")
> Signed-off-by: laixiangwu <laixiangwu@cmss.chinamobile.com>
> ---
>  drivers/tty/serial/sc16is7xx.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/tty/serial/sc16is7xx.c b/drivers/tty/serial/sc16is7xx.c
> index fba588559..e464c6d72 100644
> --- a/drivers/tty/serial/sc16is7xx.c
> +++ b/drivers/tty/serial/sc16is7xx.c
> @@ -1619,10 +1619,12 @@ int sc16is7xx_probe(struct device *dev, const struct sc16is7xx_devtype *devtype,
>  			freq = uartclk;
>  		if (pfreq)
>  			freq = *pfreq;
> -		if (freq)
> +		if (freq) {
>  			dev_dbg(dev, "Clock frequency: %luHz\n", freq);
> -		else
> -			return -EINVAL;
> +		} else {
> +			ret = -EINVAL;
> +			goto out_clk;
> +		}
>  	}
>  
>  	s->devtype = devtype;
> -- 

You can probably switch to using devm_clk_get_optional_enabled(),
to simplify and completely get rid of the goto and out_clk label?

Something along:


-       s->clk = devm_clk_get_optional(dev, NULL);
+       s->clk = devm_clk_get_optional_enabled(dev, NULL);
        if (IS_ERR(s->clk))
                return PTR_ERR(s->clk);
 
-       ret = clk_prepare_enable(s->clk);
-       if (ret)
-               return ret;
-
        freq = clk_get_rate(s->clk);
        if (freq == 0) {
                if (uartclk)
@@ -1631,10 +1627,8 @@ int sc16is7xx_probe(struct device *dev, const
struct sc16is7xx_devtype *devtype, kthread_init_worker(&s->kworker);
        s->kworker_task = kthread_run(kthread_worker_fn, &s->kworker,
                                      "sc16is7xx");
-       if (IS_ERR(s->kworker_task)) {
-               ret = PTR_ERR(s->kworker_task);
-               goto out_clk;
-       }
+       if (IS_ERR(s->kworker_task))
+               return PTR_ERR(s->kworker_task);
+
        sched_set_fifo(s->kworker_task);
 
        ret = sc16is7xx_reset(dev, regmaps[0]);
@@ -1711,9 +1705,6 @@ int sc16is7xx_probe(struct device *dev, const
struct sc16is7xx_devtype *devtype, out_kthread:
        kthread_stop(s->kworker_task);
 
-out_clk:
-       clk_disable_unprepare(s->clk);
-
        return ret;
 }
 EXPORT_SYMBOL_GPL(sc16is7xx_probe);
@@ -1740,8 +1731,6 @@ void sc16is7xx_remove(struct device *dev)
 
        kthread_flush_worker(&s->kworker);
        kthread_stop(s->kworker_task);
-
-       clk_disable_unprepare(s->clk);
 }
 EXPORT_SYMBOL_GPL(sc16is7xx_remove);
 
-- 
Hugo Villeneuve

  parent reply	other threads:[~2026-11-12 21:39 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-30  8:55 laixiangwu
2026-11-11  9:52 ` Xiangwu Lai
2026-11-11 13:16   ` Greg Kroah-Hartman
2026-11-12  2:13     ` Xiangwu Lai
2026-11-12 21:33       ` Hugo Villeneuve
2026-11-12 21:39 ` Hugo Villeneuve [this message]
2026-11-13 10:37   ` Xiangwu Lai
2026-11-13 16:58     ` Hugo Villeneuve

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=20261112163916.00d07adafb3caad1d83a2d1c@hugovil.com \
    --to=hugo@hugovil.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jirislaby@kernel.org \
    --cc=laixiangwu@cmss.chinamobile.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®