Linux kernel and device drivers for NXP i.MX platforms
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Stepan Ionichev" <sozdayvek@gmail.com>
Cc: Frank.Li@kernel.org, imx@lists.linux.dev
Subject: Re: [PATCH v2] firmware: imx: scu-irq: drop wakeup_src sysfs file, log via dev_dbg()
Date: Mon, 18 May 2026 10:08:15 +0000	[thread overview]
Message-ID: <20260518100816.38FBCC2BCB7@smtp.kernel.org> (raw)
In-Reply-To: <20260518093934.1910-1-sozdayvek@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] The global device pointer `imx_sc_irq_dev` is cached without acquiring a reference, risking a Use-After-Free.
- [Medium] Race condition in `imx_sc_irq_dev` initialization exposes an uninitialized pointer to the work handler.
--

commit 3ac9bd2a1c44ca3562cddf96e23e9b5c60b0feea
Author: Stepan Ionichev <sozdayvek@gmail.com>

firmware: imx: scu-irq: drop wakeup_src sysfs file, log via dev_dbg()

This commit removes the undocumented sysfs attribute for waking up sources,
along with its supporting variables and kobject. It replaces the sysfs
interface with dynamic debug logging of the wakeup information via
dev_dbg() in the work handler.

Link: https://lore.kernel.org/all/2026051656-corral-edgy-290c@gregkh/

> diff --git a/drivers/firmware/imx/imx-scu-irq.c b/drivers/firmware/imx/imx-scu-irq.c
> --- a/drivers/firmware/imx/imx-scu-irq.c
> +++ b/drivers/firmware/imx/imx-scu-irq.c

[ ... ]

> @@ -233,29 +199,11 @@ int imx_scu_enable_general_irq_channel(struct device *dev)
>  	if (IS_ERR(ch)) {
>  		ret = PTR_ERR(ch);
>  		dev_err(dev, "failed to request mbox chan gip3, ret %d\n", ret);
> -		goto free_cl;
> -	}
> -
> -	/* Create directory under /sysfs/firmware */
> -	wakeup_obj = kobject_create_and_add("scu_wakeup_source", firmware_kobj);
> -	if (!wakeup_obj) {
> -		ret = -ENOMEM;
> -		goto free_ch;
> +		devm_kfree(dev, cl);
> +		return ret;
>  	}
>  
> -	ret = sysfs_create_file(wakeup_obj, &wakeup_source_attr.attr);
> -	if (ret) {
> -		dev_err(dev, "Cannot create wakeup source src file......\n");
> -		kobject_put(wakeup_obj);
> -		goto free_ch;
> -	}
> +	imx_sc_irq_dev = dev;

Can the work handler execute before imx_sc_irq_dev is initialized?

If mbox_request_channel_byname() successfully enables the channel right
before this block, an interrupt could fire immediately, invoke
imx_scu_irq_callback() and schedule the work.

If the work handler imx_scu_irq_work_handler() executes before the
assignment to imx_sc_irq_dev completes, dev_dbg() will receive a NULL
pointer. While __dev_printk() handles NULL gracefully by printing
"(NULL device *)", it would mask the intended debug output.

Should imx_sc_irq_dev be assigned before requesting the mailbox channel?

Does caching the global device pointer here also risk a use-after-free?

The dev pointer is stored in imx_sc_irq_dev without acquiring a reference.
Since the workqueue and mailbox channel aren't explicitly torn down on
failure or unbind, the pending asynchronous work might still run after the
device is removed.

If the device is freed, accessing it in imx_scu_irq_work_handler() via
dev_dbg() could lead to a use-after-free.

Would it be safer to take a reference with get_device() to guarantee the
device's lifetime during asynchronous execution?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260518093934.1910-1-sozdayvek@gmail.com?part=1

  reply	other threads:[~2026-05-18 10:08 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-15 17:50 [PATCH] firmware: imx: scu-irq: accumulate wakeup sources via sysfs_emit_at() Stepan Ionichev
2026-05-16  7:15 ` Greg KH
2026-05-16  9:07   ` Stepan Ionichev
2026-05-16  9:20     ` Greg KH
2026-05-18  1:29     ` Peng Fan
2026-05-18  9:39 ` [PATCH v2] firmware: imx: scu-irq: drop wakeup_src sysfs file, log via dev_dbg() Stepan Ionichev
2026-05-18 10:08   ` sashiko-bot [this message]
2026-06-01 18:05     ` Frank Li

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=20260518100816.38FBCC2BCB7@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Frank.Li@kernel.org \
    --cc=imx@lists.linux.dev \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=sozdayvek@gmail.com \
    /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