All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Sean Young" <sean@mess.org>
Cc: neil.armstrong@linaro.org, linux-amlogic@lists.infradead.org,
	media-ci@linuxtv.org
Subject: Re: [PATCH v4 07/15] media: meson-ir-tx: Ensure clock is disabled on unbind
Date: Mon, 27 Jul 2026 14:51:56 +0000	[thread overview]
Message-ID: <20260727145156.A3F5A1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <ea91c3a9dcfbc146f676e2cc3b5f769b2ab8c088.1785158244.git.sean@mess.org>

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

Pre-existing issues:
- [High] Memory leak of the rc_dev struct on driver unbind due to mixing unmanaged allocation with managed registration.
- [High] Integer underflow and division by zero when configuring high carrier frequencies.
- [High] Lockless check of completion_done in the IRQ handler exposes a race that can overflow the hardware FIFO.
- [Medium] Error codes from core kernel APIs are hardcoded to -ENODEV, breaking probe deferral.
--

--- Patch [7]: [PATCH v4 07/15] media: meson-ir-tx: Ensure clock is disabled on unbind ---
commit b425f7e336876fa07197476c4560b56dec0eb33d
Author: Sean Young <sean@mess.org>

media: meson-ir-tx: Ensure clock is disabled on unbind
    
clk_prepare_enable() needs a call to clk_disable_unprepare() on
driver unbind. Make it devm managed.

> diff --git a/drivers/media/rc/meson-ir-tx.c b/drivers/media/rc/meson-ir-tx.c
> index fded2c256f2a6..e7bb107e6a843 100644
> --- a/drivers/media/rc/meson-ir-tx.c
> +++ b/drivers/media/rc/meson-ir-tx.c
> @@ -288,8 +288,8 @@ static int meson_irtx_mod_clock_probe(struct meson_irtx *ir,
>  	if (!np)
>  		return -ENODEV;
>  
> -	clock = devm_clk_get(ir->dev, "xtal");
> -	if (IS_ERR(clock) || clk_prepare_enable(clock))
> +	clock = devm_clk_get_enabled(ir->dev, "xtal");
> +	if (IS_ERR(clock))
>  		return -ENODEV;
>  
>  	*clk_nr = IRB_MOD_XTAL3_CLK;

[Severity: Medium]
This isn't a bug introduced by this patch, but returning -ENODEV here prevents
proper probe deferral. If the clock is not yet ready and devm_clk_get_enabled()
returns -EPROBE_DEFER, the initialization will permanently fail instead of
trying again later.

Also in meson_irtx_probe(), the same pattern exists for the IRQ:

drivers/media/rc/meson-ir-tx.c:meson_irtx_probe() {
    ...
	irq = platform_get_irq(pdev, 0);
	if (irq < 0)
		return -ENODEV;
    ...
}

Should these functions return the exact error pointer (e.g. PTR_ERR(clock))
or error code rather than hardcoding -ENODEV?

[Severity: High]
This is a pre-existing issue, but does this code cause an integer underflow
and division by zero when configuring high carrier frequencies?

drivers/media/rc/meson-ir-tx.c:meson_irtx_set_mod() {
    ...
	unsigned int cnt = DIV_ROUND_CLOSEST(ir->clk_rate, ir->carrier);
	unsigned int pulse_cnt = DIV_ROUND_CLOSEST(cnt * ir->duty_cycle, 100);
	unsigned int space_cnt = cnt - pulse_cnt;

	dev_dbg(ir->dev, "F_mod = %uHz, T_mod = %luns, duty_cycle = %u%%\n",
		ir->carrier, NSEC_PER_SEC / ir->clk_rate * cnt,
		100 * pulse_cnt / cnt);
    ...
}

If a user space process provides a carrier frequency greater than twice the
modulator clock rate (ir->clk_rate), cnt will be 0. This results in pulse_cnt
being 0, which triggers a division by zero in the dev_dbg() statement. 

Could this also cause an underflow when writing to the hardware register via
IRB_MOD_COUNT(pulse_cnt, space_cnt)?

[Severity: High]
This is a pre-existing issue, but does the lockless check of completion_done()
in the IRQ handler expose a race condition?

drivers/media/rc/meson-ir-tx.c:meson_irtx_irqhandler() {
    ...
	if (completion_done(&ir->completion))
		return IRQ_HANDLED;

	spin_lock_irqsave(&ir->lock, flags);
	if (ir->buf_head < ir->buf_len)
		meson_irtx_send_buffer(ir);
	else
		complete(&ir->completion);
	spin_unlock_irqrestore(&ir->lock, flags);
    ...
}

If an edge interrupt for the FIFO threshold is delayed, and a new transmission
begins by acquiring the lock and reinitializing the completion, could the
delayed IRQ handler evaluate completion_done() outside the lock, see it as
false, and then blindly write up to 96 more words, overflowing the hardware
FIFO?

[Severity: High]
This is a pre-existing issue, but does this code leak the rc_dev structure on
driver unbind?

drivers/media/rc/meson-ir-tx.c:meson_irtx_probe() {
    ...
	rc = rc_allocate_device(RC_DRIVER_IR_RAW_TX);
	if (!rc)
		return -ENOMEM;
    ...
	ret = devm_rc_register_device(dev, rc);
	if (ret < 0) {
		rc_free_device(rc);
		return dev_err_probe(dev, ret, "rc_dev registration failed\n");
	}
    ...
}

Because rc is allocated with rc_allocate_device() instead of a managed
variant like devm_rc_allocate_device(), when the driver is unbound,
devm_rc_register_device() will automatically unregister the device, but the
memory for the rc_dev structure is never freed since there is no remove
callback.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1785158244.git.sean@mess.org?part=7

_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic

  reply	other threads:[~2026-07-27 14:52 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-27 13:18 [PATCH v4 00/15] Fix leaks in rc core Sean Young
2026-07-27 13:18 ` [PATCH v4 01/15] media: streamzap: Add missing rc_unregister_device() Sean Young
2026-07-27 13:18 ` [PATCH v4 02/15] media: redrat3: Ensure rc device is freed if enable_detector() fails Sean Young
2026-07-27 13:18 ` [PATCH v4 03/15] media: redrat3: Ensure we don't read beyond the end of the packet Sean Young
2026-07-27 13:18 ` [PATCH v4 04/15] media: redrat3: Ensure all urbs are suspended Sean Young
2026-07-27 13:18 ` [PATCH v4 05/15] media: redrat3: Error path leaves device in transmitting state Sean Young
2026-07-27 15:57   ` Markus Elfring
2026-07-27 13:18 ` [PATCH v4 06/15] media: sunxi-cir: Ensure no more interrupts can occur before free Sean Young
2026-07-27 14:40   ` sashiko-bot
2026-07-27 13:18 ` [PATCH v4 07/15] media: meson-ir-tx: Ensure clock is disabled on unbind Sean Young
2026-07-27 13:18   ` Sean Young
2026-07-27 14:51   ` sashiko-bot [this message]
2026-07-27 13:18 ` [PATCH v4 08/15] media: meson-ir-tx: Ensure rc_free_device() is called " Sean Young
2026-07-27 13:18   ` Sean Young
2026-07-27 13:18 ` [PATCH v4 09/15] media: meson-ir-tx: Ensure probe error is propagated Sean Young
2026-07-27 13:18   ` Sean Young
2026-07-27 13:18 ` [PATCH v4 10/15] media: ir-hix5hd2: Ensure rdev is setup before interrupts are enabled Sean Young
2026-07-27 13:18 ` [PATCH v4 11/15] media: rc: Use after free in ir_raw_event_handle() Sean Young
2026-07-27 13:18 ` [PATCH v4 12/15] media: rc: Fix use after free in bpf progs Sean Young
2026-07-27 15:44   ` sashiko-bot
2026-07-27 13:18 ` [PATCH v4 13/15] media: cx88: Specify rc type at rc_allocate_type() Sean Young
2026-07-27 13:18 ` [PATCH v4 14/15] media: saa7134: " Sean Young
2026-07-27 13:18 ` [PATCH v4 15/15] media: rc: Fix race condition during rc_register_device() Sean Young

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=20260727145156.A3F5A1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-amlogic@lists.infradead.org \
    --cc=media-ci@linuxtv.org \
    --cc=neil.armstrong@linaro.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=sean@mess.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.