ARM Sunxi Platform Development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Aamir Ahmed" <elb12345@hotmail.co.uk>
Cc: linux-sunxi@lists.linux.dev,
	"Alexandre Belloni" <alexandre.belloni@bootlin.com>,
	linux-rtc@vger.kernel.org
Subject: Re: [PATCH] rtc: ac100: Assign .num before accessing .hws
Date: Sat, 05 Sep 2026 18:49:35 +0000	[thread overview]
Message-ID: <20260905184936.155E11F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <AS8P251MB00013E724A77A355668B6CCEC8B42@AS8P251MB0001.EURP251.PROD.OUTLOOK.COM>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Missing cleanup of OF clock provider and fixed-rate clock on probe failure causes a Use-After-Free and resource leak.
--

commit a37d5a060e39167e75415bce4b97e44f0383fe08
Author: Aamir Ahmed <elb12345@hotmail.co.uk>

rtc: ac100: Assign .num before accessing .hws

This commit assigns .num in struct clk_hw_onecell_data before accessing
its .hws[] elements in ac100_rtc_register_clks(). This fixes a bounds
sanitizer warning triggered by the __counted_by annotation introduced
in a previous commit.

> diff --git a/drivers/rtc/rtc-ac100.c b/drivers/rtc/rtc-ac100.c
> index bba7115ff3ad0..a2f465438fd05 100644
> --- a/drivers/rtc/rtc-ac100.c
> +++ b/drivers/rtc/rtc-ac100.c
[ ... ]
> @@ -360,7 +362,6 @@ static int ac100_rtc_register_clks(struct ac100_rtc_dev *chip)
>  		chip->clk_data->hws[i] = &clk->hw;
>  	}
>  
> -	chip->clk_data->num = i;
>  	ret = of_clk_add_hw_provider(np, of_clk_hw_onecell_get, chip->clk_data);
>  	if (ret)
>  		goto err_unregister_rtc_32k;

[Severity: High]
This isn't a bug introduced by this patch, but does the lack of cleanup
in ac100_rtc_probe() lead to a use-after-free and resource leak?

In ac100_rtc_probe(), ac100_rtc_register_clks() manually registers a
clock provider and a fixed-rate clock which are not devm-managed:

drivers/rtc/rtc-ac100.c:ac100_rtc_probe() {
    ...
	ret = ac100_rtc_register_clks(chip);
	if (ret)
		return ret;

	return devm_rtc_register_device(chip->rtc);
}

If devm_rtc_register_device() fails, the probe function exits and devm
cleans up chip->clk_data. However, since the clock provider is not
unregistered on this error path, it remains active in the Common Clock
Framework with a dangling pointer to the freed chip->clk_data.

Can any subsequent attempt to query a clock via device tree traverse the
provider list, dereference the freed pointer, and trigger a crash?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/AS8P251MB00013E724A77A355668B6CCEC8B42@AS8P251MB0001.EURP251.PROD.OUTLOOK.COM?part=1

  reply	other threads:[~2026-09-05 18:49 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-05 18:38 [PATCH] rtc: ac100: Assign .num before accessing .hws Aamir Ahmed
2026-09-05 18:49 ` sashiko-bot [this message]
2026-09-13 15:45 ` Chen-Yu Tsai

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=20260905184936.155E11F00A3A@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=alexandre.belloni@bootlin.com \
    --cc=elb12345@hotmail.co.uk \
    --cc=linux-rtc@vger.kernel.org \
    --cc=linux-sunxi@lists.linux.dev \
    --cc=sashiko-reviews@lists.linux.dev \
    /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