mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Wang Haoran <wanghr2026@mail.zgclab.edu.cn>
To: sboyd@kernel.org, bmasney+clk@redhat.com, jbrunet+clk@baylibre.com
Cc: linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org,
	wanghr2026@mail.zgclab.edu.cn
Subject: [PATCH] clk: max9485: Disable vdd on probe failure
Date: Thu, 19 Nov 2026 16:14:49 +0800	[thread overview]
Message-ID: <1795076089649-2-ff3d027f@mail.zgclab.edu.cn> (raw)

max9485_i2c_probe() enables the vdd regulator but never disables it: the
driver has no remove callback and no failure-path unwind, so the rail
stays enabled after a failed probe (including -EPROBE_DEFER retries, which
re-enable it each round) and after unbind, and _regulator_put() then warns
on the leaked enable.

Use devm_regulator_get_enable() instead of the manual get and enable, so
the core registers an automatic disable that runs on probe failure and on
removal without adding a new error path.

Signed-off-by: Wang Haoran <wanghr2026@mail.zgclab.edu.cn>
Fixes: 33f5104624b9 ("clk: Add driver for MAX9485")
---

diff --git a/drivers/clk/clk-max9485.c b/drivers/clk/clk-max9485.c
index 9c48c0c3a998..68df62ac148c 100644
--- a/drivers/clk/clk-max9485.c
+++ b/drivers/clk/clk-max9485.c
@@ -78,7 +78,6 @@ struct max9485_driver_data {
 	struct clk *xclk;
 	struct i2c_client *client;
 	u8 reg_value;
-	struct regulator *supply;
 	struct gpio_desc *reset_gpio;
 	struct max9485_clk_hw hw[MAX9485_NUM_CLKS];
 };
@@ -278,12 +277,8 @@ static int max9485_i2c_probe(struct i2c_client *client)
 
 	xclk_name = __clk_get_name(drvdata->xclk);
 
-	drvdata->supply = devm_regulator_get(dev, "vdd");
-	if (IS_ERR(drvdata->supply))
-		return PTR_ERR(drvdata->supply);
-
-	ret = regulator_enable(drvdata->supply);
-	if (ret < 0)
+	ret = devm_regulator_get_enable(dev, "vdd");
+	if (ret)
 		return ret;
 
 	drvdata->reset_gpio =

---

PoC reproduction (7.4.0-rc2, arm64 QEMU virt, unmodified kernel):

Device tree injection, spliced into the QEMU virt machine DT:

    xclk: clock-0 { compatible = "fixed-clock"; #clock-cells = <0>;
        clock-frequency = <12288000>; };

    reg_vdd: regulator-0 { compatible = "regulator-fixed";
        regulator-name = "max9485-vdd"; regulator-min-microvolt = <3300000>;
        regulator-max-microvolt = <3300000>; };

    i2c@0 { compatible = "i2c-gpio";
        sda-gpios = <&gpio0 0 0>; scl-gpios = <&gpio0 1 0>;
        i2c-gpio,delay-us = <2>; #address-cells = <1>; #size-cells = <0>;
        max9485@63 { compatible = "maxim,max9485"; reg = <0x63>;
            clocks = <&xclk>; clock-names = "xclk"; vdd-supply = <&reg_vdd>; }; };

The i2c register read fails on the unanswered bus, so the probe enables vdd
and then returns without disabling it.

Trigger:

    modprobe i2c-gpio
    modprobe clk-max9485

Result:

    max9485 0-0063: Unable to read device register: -6
    WARNING: drivers/regulator/core.c:2678 at _regulator_put

The regulator summary shows max9485-vdd with a use count of 2 after the
failed probe.

Note: the PoC was generated with AI assistance and the vulnerability was
found by static analysis. The device tree is trusted input (a bad DT
requires root or physical access), so this is not a security fix, but it
prevents a potential resource leak or system failure on a failed probe or
an old or malformed DT.


                 reply	other threads:[~2026-11-19  8:14 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=1795076089649-2-ff3d027f@mail.zgclab.edu.cn \
    --to=wanghr2026@mail.zgclab.edu.cn \
    --cc=bmasney+clk@redhat.com \
    --cc=jbrunet+clk@baylibre.com \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sboyd@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®