From: sashiko-bot@kernel.org
To: "Sean Young" <sean@mess.org>
Cc: media-ci@linuxtv.org, neil.armstrong@linaro.org,
linux-amlogic@lists.infradead.org
Subject: Re: [PATCH v4 19/19] media: meson-ir-tx: Validate carrier and duty_cycle
Date: Tue, 08 Sep 2026 16:26:57 +0000 [thread overview]
Message-ID: <20260908162657.BC1391F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <528055c59611d6711e15b05c5ab150d4d3d338af.1788882189.git.sean@mess.org>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The patch claims to fix a divide-by-zero error for carrier frequencies larger than USEC_PER_SEC, but the implemented bounds check mathematically fails to prevent it.
--
commit e3f11b02aad6109d1dcf403fdfe01c4cc2db70e1
Author: Sean Young <sean@mess.org>
media: meson-ir-tx: Validate carrier and duty_cycle
It is possible to set a combination of carrier and duty cycle that do
not produce a correct signal. In addition, setting a carrier larger
than USEC_PER_SEC will result in a divide by zero in
meson_irtx_prepare_pulse() during transmit.
> diff --git a/drivers/media/rc/meson-ir-tx.c b/drivers/media/rc/meson-ir-tx.c
> index 1ab898069e67f..a410464ede224 100644
> --- a/drivers/media/rc/meson-ir-tx.c
> +++ b/drivers/media/rc/meson-ir-tx.c
[ ... ]
> @@ -76,11 +76,24 @@ struct meson_irtx {
> unsigned long clk_rate;
> };
>
> -static void meson_irtx_set_mod(struct meson_irtx *ir)
> +static bool meson_irtx_calc_mod(unsigned long clk_rate, u32 carrier,
> + u32 duty_cycle, unsigned int *pulse_cnt,
> + unsigned int *space_cnt)
> {
> - 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;
> + unsigned int cnt;
> +
> + cnt = DIV_ROUND_CLOSEST(clk_rate, carrier);
> + *pulse_cnt = DIV_ROUND_CLOSEST(cnt * duty_cycle, 100);
> + *space_cnt = cnt - *pulse_cnt;
> +
> + return *pulse_cnt >= 1 && *pulse_cnt <= 65536 &&
> + *space_cnt >= 1 && *space_cnt <= 65536;
> +}
[Severity: Medium]
Does this validation check adequately prevent the divide-by-zero condition
mentioned in the commit message?
For example, if the carrier frequency is set to 3,000,000 Hz and the clock
rate is 8,000,000 Hz, cnt evaluates to 3. Depending on the duty cycle,
pulse_cnt and space_cnt could be valid (e.g., 2 and 1), allowing this
function to return true despite the carrier being larger than USEC_PER_SEC.
Because of this, callers like meson_irtx_set_carrier() can still accept
these excessively high carrier frequencies, allowing tb_us to drop to 0
in meson_irtx_prepare_pulse():
unsigned int tb_us = DIV_ROUND_CLOSEST(USEC_PER_SEC, ir->carrier);
delay = (DIV_ROUND_CLOSEST(time, tb_us) - 1) & IRB_DELAY_MASK;
While a pre-existing bounds check in meson_irtx_check_buf() seems to
coincidentally reject transmissions when carrier > USEC_PER_SEC (since its
calculated max_tb_us becomes 0), should this new logic also explicitly
check for carrier <= USEC_PER_SEC to fully enforce the constraint stated
in the commit message?
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1788882189.git.sean@mess.org?part=19
_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic
prev parent reply other threads:[~2026-09-08 16:27 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-08 15:51 [PATCH v4 00/19] media: Fix locking issues in rc core Sean Young
2026-09-08 15:51 ` [PATCH v4 01/19] media: rc: Ensure registered is cleared in error path Sean Young
2026-09-11 7:53 ` Hans Verkuil
2026-09-11 8:45 ` Sean Young
2026-09-08 15:51 ` [PATCH v4 02/19] media: rc: Ensure that rc_unregister_device() does not free input device Sean Young
2026-09-08 15:51 ` [PATCH v4 03/19] media: rc: Fix ABBA deadlock by making locks more fine grained Sean Young
2026-09-08 15:51 ` [PATCH v4 04/19] media: rc: Add missing locking for keymap Sean Young
2026-09-11 8:08 ` Hans Verkuil
2026-09-11 8:47 ` Sean Young
2026-09-08 15:51 ` [PATCH v4 05/19] media: rc: Fix race between bpf(BPG_PROG_ATTACH) and device unregister Sean Young
2026-09-08 15:51 ` [PATCH v4 06/19] media: rc: mce_kbd: Fix inconsistent locking of keylock Sean Young
2026-09-08 15:51 ` [PATCH v4 07/19] media: ene_ir: Ensure teardown is done in the correct order Sean Young
2026-09-08 15:51 ` [PATCH v4 08/19] media: rc: Use binary search for adding or updating a scancode Sean Young
2026-09-11 8:10 ` Hans Verkuil
2026-09-11 8:42 ` Sean Young
2026-09-08 15:51 ` [PATCH v4 09/19] media: rc: imon: Bind both interfaces via usb_driver_claim_interface() Sean Young
2026-09-08 15:51 ` [PATCH v4 10/19] media: ir_toy: Remove unused struct field Sean Young
2026-09-08 15:51 ` [PATCH v4 11/19] media: nuvoton-cir: " Sean Young
2026-09-08 15:52 ` [PATCH v4 12/19] media: ite-cir: Removed " Sean Young
2026-09-08 15:52 ` [PATCH v4 13/19] media: fintek-cir: Remove unused fields Sean Young
2026-09-08 15:52 ` [PATCH v4 14/19] media: mceusb: Remove unused field Sean Young
2026-09-08 15:52 ` [PATCH v4 15/19] media: serial_ir: Fix race condition where timer can be re-armed Sean Young
2026-09-08 15:52 ` [PATCH v4 16/19] media: rc: After rc_unregister_device() timers " Sean Young
2026-09-08 15:52 ` [PATCH v4 17/19] media: rc: Validate carrier range in LIRC_SET_REC_CARRIER ioctl Sean Young
2026-09-08 15:52 ` [PATCH v4 18/19] media: ir_toy: Validate the maximum tx carrier Sean Young
2026-09-08 15:52 ` [PATCH v4 19/19] media: meson-ir-tx: Validate carrier and duty_cycle Sean Young
2026-09-08 15:52 ` Sean Young
2026-09-08 16:26 ` sashiko-bot [this message]
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=20260908162657.BC1391F00A3A@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.