All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sebastian Reichel <sebastian.reichel@collabora.com>
To: Tian Xuechen <202300460064@mail.sdu.edu.cn>
Cc: nikita.shubin@maquefel.me, arnd@arndb.de, vkoul@kernel.org,
	 linux@roeck-us.net, alexandre.belloni@bootlin.com, fkan@apm.com,
	 linux-pm@vger.kernel.org, liguangshuo@mail.sdu.edu.cn
Subject: Re: [PATCH 2/4] power: reset: hisi: Unregister the restart handler on unbind
Date: Sat, 5 Dec 2026 23:56:39 +0100	[thread overview]
Message-ID: <axSWHZzwVZnNAvQq@venus> (raw)
In-Reply-To: <20261129094744.1691778-3-202300460064@mail.sdu.edu.cn>

[-- Attachment #1: Type: text/plain, Size: 3786 bytes --]

Hi,

On Sun, Nov 29, 2026 at 05:47:42PM +0800, Tian Xuechen wrote:
> From: Tian Xuechen <202300460064@mail.sdu.edu.cn>
> 
> Removing the driver leaves its restart handler registered and the
> register mapping in use. Keep both in per-device data, unregister the
> handler on removal, then unmap its registers.
> 
> This issue was found by our static analysis tool under development.
> 
> Fixes: 6724534c79ea ("power/reset: hisi: Register with kernel restart handler")
> Signed-off-by: Tian Xuechen <202300460064@mail.sdu.edu.cn>
> ---
>  drivers/power/reset/hisi-reboot.c | 46 +++++++++++++++++++++----------
>  1 file changed, 32 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/power/reset/hisi-reboot.c b/drivers/power/reset/hisi-reboot.c
> index 34409340528f..e106e9f0acaf 100644
> --- a/drivers/power/reset/hisi-reboot.c
> +++ b/drivers/power/reset/hisi-reboot.c
> @@ -15,16 +15,22 @@
>  #include <linux/of_address.h>
>  #include <linux/platform_device.h>
>  #include <linux/reboot.h>
> +#include <linux/slab.h>
>  
>  #include <asm/proc-fns.h>
>  
> -static void __iomem *base;
> -static u32 reboot_offset;
> +struct hisi_reboot {
> +	struct notifier_block nb;
> +	void __iomem *base;
> +	u32 offset;
> +};
>  
>  static int hisi_restart_handler(struct notifier_block *this,
>  				unsigned long mode, void *cmd)
>  {
> -	writel_relaxed(0xdeadbeef, base + reboot_offset);
> +	struct hisi_reboot *reboot = container_of(this, struct hisi_reboot, nb);
> +
> +	writel_relaxed(0xdeadbeef, reboot->base + reboot->offset);
>  
>  	while (1)
>  		cpu_do_idle();
> @@ -32,38 +38,49 @@ static int hisi_restart_handler(struct notifier_block *this,
>  	return NOTIFY_DONE;
>  }
>  
> -static struct notifier_block hisi_restart_nb = {
> -	.notifier_call = hisi_restart_handler,
> -	.priority = 128,
> -};
> -
>  static int hisi_reboot_probe(struct platform_device *pdev)
>  {
>  	struct device_node *np = pdev->dev.of_node;
> +	struct hisi_reboot *reboot;
>  	int err;
>  
> -	base = of_iomap(np, 0);
> -	if (!base) {
> +	reboot = devm_kzalloc(&pdev->dev, sizeof(*reboot), GFP_KERNEL);
> +	if (!reboot)
> +		return -ENOMEM;
> +
> +	reboot->base = of_iomap(np, 0);

devm_platform_ioremap_resource()

> +	if (!reboot->base) {
>  		WARN(1, "failed to map base address");
>  		return -ENODEV;
>  	}
>  
> -	if (of_property_read_u32(np, "reboot-offset", &reboot_offset) < 0) {
> +	if (of_property_read_u32(np, "reboot-offset", &reboot->offset) < 0) {
>  		pr_err("failed to find reboot-offset property\n");
> -		iounmap(base);
> +		iounmap(reboot->base);
>  		return -EINVAL;
>  	}
>  
> -	err = register_restart_handler(&hisi_restart_nb);
> +	platform_set_drvdata(pdev, reboot);
> +	reboot->nb.notifier_call = hisi_restart_handler;
> +	reboot->nb.priority = 128;
> +	err = register_restart_handler(&reboot->nb);

devm_register_sys_off_handler()

>  	if (err) {
>  		dev_err(&pdev->dev, "cannot register restart handler (err=%d)\n",
>  			err);
> -		iounmap(base);
> +		iounmap(reboot->base);
>  	}
>  
>  	return err;
>  }
>  
> +static void hisi_reboot_remove(struct platform_device *pdev)
> +{
> +	struct hisi_reboot *reboot = platform_get_drvdata(pdev);
> +
> +	unregister_restart_handler(&reboot->nb);
> +	iounmap(reboot->base);
> +}
> +
>  static const struct of_device_id hisi_reboot_of_match[] = {
>  	{ .compatible = "hisilicon,sysctrl" },
>  	{}
> @@ -72,6 +89,7 @@ MODULE_DEVICE_TABLE(of, hisi_reboot_of_match);
>  
>  static struct platform_driver hisi_reboot_driver = {
>  	.probe = hisi_reboot_probe,
> +	.remove = hisi_reboot_remove,
>  	.driver = {
>  		.name = "hisi-reboot",
>  		.of_match_table = hisi_reboot_of_match,

Greetings,

-- Sebastian

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2026-12-05 22:57 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-29  9:47 [PATCH 0/4] power: reset: Unregister restart handlers on removal Tian Xuechen
2026-11-29  9:47 ` [PATCH 1/4] power: reset: ep93xx: Unregister the restart handler " Tian Xuechen
2026-12-05 22:57   ` Sebastian Reichel
2026-11-29  9:47 ` [PATCH 2/4] power: reset: hisi: Unregister the restart handler on unbind Tian Xuechen
2026-12-05 22:56   ` Sebastian Reichel [this message]
2026-11-29  9:47 ` [PATCH 3/4] power: reset: ocelot: Unregister the restart handler on removal Tian Xuechen
2026-12-05 22:57   ` Sebastian Reichel
2026-11-29  9:47 ` [PATCH 4/4] power: reset: syscon-reboot: " Tian Xuechen
2026-12-05 22:58   ` Sebastian Reichel

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=axSWHZzwVZnNAvQq@venus \
    --to=sebastian.reichel@collabora.com \
    --cc=202300460064@mail.sdu.edu.cn \
    --cc=alexandre.belloni@bootlin.com \
    --cc=arnd@arndb.de \
    --cc=fkan@apm.com \
    --cc=liguangshuo@mail.sdu.edu.cn \
    --cc=linux-pm@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=nikita.shubin@maquefel.me \
    --cc=vkoul@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 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.