Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

clk: nxp: Fix pll0 rate check condition in LPC18xx CGU driver

The conditional check for the PLL0 multiplier 'm' used a logical AND
instead of OR, making the range check ineffective. This patch replaces
&& with || to correctly reject invalid values of 'm' that are either
less than or equal to 0 or greater than LPC18XX_PLL0_MSEL_MAX.

This ensures proper bounds checking during clk rate setting and rounding.

Fixes: b04e0b8fd544 ("clk: add lpc18xx cgu clk driver")
Signed-off-by: Alok Tiwari <alok.a.tiwari@oracle.com>
[sboyd@kernel.org: 'm' is unsigned so remove < condition]
Signed-off-by: Stephen Boyd <sboyd@kernel.org>

authored by

Alok Tiwari and committed by
Stephen Boyd
1624dead 91ec7ad7

+2 -2
+2 -2
drivers/clk/nxp/clk-lpc18xx-cgu.c
··· 381 381 } 382 382 383 383 m = DIV_ROUND_UP_ULL(req->best_parent_rate, req->rate * 2); 384 - if (m <= 0 && m > LPC18XX_PLL0_MSEL_MAX) { 384 + if (m == 0 || m > LPC18XX_PLL0_MSEL_MAX) { 385 385 pr_warn("%s: unable to support rate %lu\n", __func__, req->rate); 386 386 return -EINVAL; 387 387 } ··· 404 404 } 405 405 406 406 m = DIV_ROUND_UP_ULL(parent_rate, rate * 2); 407 - if (m <= 0 && m > LPC18XX_PLL0_MSEL_MAX) { 407 + if (m == 0 || m > LPC18XX_PLL0_MSEL_MAX) { 408 408 pr_warn("%s: unable to support rate %lu\n", __func__, rate); 409 409 return -EINVAL; 410 410 }