* [PATCH v2 1/1] spi: pxa2xx: use min() instead of min_t()
@ 2026-02-23 15:30 Andy Shevchenko
2026-02-23 17:09 ` David Laight
2026-02-25 19:07 ` Mark Brown
0 siblings, 2 replies; 4+ messages in thread
From: Andy Shevchenko @ 2026-02-23 15:30 UTC (permalink / raw)
To: Andy Shevchenko, linux-arm-kernel, linux-spi, linux-kernel
Cc: Daniel Mack, Haojian Zhuang, Robert Jarzmik, Mark Brown
min_t(int, a, b) casts an 'u32' to 'int'. This might lead to
the cases when big number is wrongly chosen. On the other hand,
the SPI transfer speed rate is unsigned and driver uses signed type
for an unknown reason. Change the type of the SPI transfer speed
to be unsigned and convert to use min() instead of min_t().
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
v2: used u32 instead of unsigned long (David)
drivers/spi/spi-pxa2xx.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/drivers/spi/spi-pxa2xx.c b/drivers/spi/spi-pxa2xx.c
index f7881a31e4cc..6291d7c2e06f 100644
--- a/drivers/spi/spi-pxa2xx.c
+++ b/drivers/spi/spi-pxa2xx.c
@@ -796,7 +796,7 @@ static irqreturn_t ssp_int(int irq, void *dev_id)
* The function calculates parameters for all cases and chooses the one closest
* to the asked baud rate.
*/
-static unsigned int quark_x1000_get_clk_div(int rate, u32 *dds)
+static unsigned int quark_x1000_get_clk_div(u32 rate, u32 *dds)
{
unsigned long xtal = 200000000;
unsigned long fref = xtal / 2; /* mandatory division by 2,
@@ -885,12 +885,12 @@ static unsigned int quark_x1000_get_clk_div(int rate, u32 *dds)
return q - 1;
}
-static unsigned int ssp_get_clk_div(struct driver_data *drv_data, int rate)
+static unsigned int ssp_get_clk_div(struct driver_data *drv_data, u32 rate)
{
- unsigned long ssp_clk = drv_data->controller->max_speed_hz;
+ u32 ssp_clk = drv_data->controller->max_speed_hz;
const struct ssp_device *ssp = drv_data->ssp;
- rate = min_t(int, ssp_clk, rate);
+ rate = min(ssp_clk, rate);
/*
* Calculate the divisor for the SCR (Serial Clock Rate), avoiding
@@ -902,8 +902,7 @@ static unsigned int ssp_get_clk_div(struct driver_data *drv_data, int rate)
return (DIV_ROUND_UP(ssp_clk, rate) - 1) & 0xfff;
}
-static unsigned int pxa2xx_ssp_get_clk_div(struct driver_data *drv_data,
- int rate)
+static unsigned int pxa2xx_ssp_get_clk_div(struct driver_data *drv_data, u32 rate)
{
struct chip_data *chip =
spi_get_ctldata(drv_data->controller->cur_msg->spi);
--
2.50.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2 1/1] spi: pxa2xx: use min() instead of min_t()
2026-02-23 15:30 [PATCH v2 1/1] spi: pxa2xx: use min() instead of min_t() Andy Shevchenko
@ 2026-02-23 17:09 ` David Laight
2026-02-23 17:35 ` Andy Shevchenko
2026-02-25 19:07 ` Mark Brown
1 sibling, 1 reply; 4+ messages in thread
From: David Laight @ 2026-02-23 17:09 UTC (permalink / raw)
To: Andy Shevchenko
Cc: linux-arm-kernel, linux-spi, linux-kernel, Daniel Mack,
Haojian Zhuang, Robert Jarzmik, Mark Brown
On Mon, 23 Feb 2026 16:30:54 +0100
Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
> min_t(int, a, b) casts an 'u32' to 'int'. This might lead to
> the cases when big number is wrongly chosen. On the other hand,
> the SPI transfer speed rate is unsigned and driver uses signed type
> for an unknown reason. Change the type of the SPI transfer speed
> to be unsigned and convert to use min() instead of min_t().
>
Reviewed-by: David Laight <david.laight.linux@gmail.com>
(but see below...)
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>
> v2: used u32 instead of unsigned long (David)
>
> drivers/spi/spi-pxa2xx.c | 11 +++++------
> 1 file changed, 5 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/spi/spi-pxa2xx.c b/drivers/spi/spi-pxa2xx.c
> index f7881a31e4cc..6291d7c2e06f 100644
> --- a/drivers/spi/spi-pxa2xx.c
> +++ b/drivers/spi/spi-pxa2xx.c
> @@ -796,7 +796,7 @@ static irqreturn_t ssp_int(int irq, void *dev_id)
> * The function calculates parameters for all cases and chooses the one closest
> * to the asked baud rate.
> */
> -static unsigned int quark_x1000_get_clk_div(int rate, u32 *dds)
> +static unsigned int quark_x1000_get_clk_div(u32 rate, u32 *dds)
> {
> unsigned long xtal = 200000000;
> unsigned long fref = xtal / 2; /* mandatory division by 2,
I've looked at the file...
I think all the 'long' in that function can be 32bit.
Especially if the code actually works on 32bit.
There is also the stunning:
do_div(fssp, 1 << 24);
in the only bit that that does need u64.
David
> @@ -885,12 +885,12 @@ static unsigned int quark_x1000_get_clk_div(int rate, u32 *dds)
> return q - 1;
> }
>
> -static unsigned int ssp_get_clk_div(struct driver_data *drv_data, int rate)
> +static unsigned int ssp_get_clk_div(struct driver_data *drv_data, u32 rate)
> {
> - unsigned long ssp_clk = drv_data->controller->max_speed_hz;
> + u32 ssp_clk = drv_data->controller->max_speed_hz;
> const struct ssp_device *ssp = drv_data->ssp;
>
> - rate = min_t(int, ssp_clk, rate);
> + rate = min(ssp_clk, rate);
>
> /*
> * Calculate the divisor for the SCR (Serial Clock Rate), avoiding
> @@ -902,8 +902,7 @@ static unsigned int ssp_get_clk_div(struct driver_data *drv_data, int rate)
> return (DIV_ROUND_UP(ssp_clk, rate) - 1) & 0xfff;
> }
>
> -static unsigned int pxa2xx_ssp_get_clk_div(struct driver_data *drv_data,
> - int rate)
> +static unsigned int pxa2xx_ssp_get_clk_div(struct driver_data *drv_data, u32 rate)
> {
> struct chip_data *chip =
> spi_get_ctldata(drv_data->controller->cur_msg->spi);
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2 1/1] spi: pxa2xx: use min() instead of min_t()
2026-02-23 17:09 ` David Laight
@ 2026-02-23 17:35 ` Andy Shevchenko
0 siblings, 0 replies; 4+ messages in thread
From: Andy Shevchenko @ 2026-02-23 17:35 UTC (permalink / raw)
To: David Laight
Cc: linux-arm-kernel, linux-spi, linux-kernel, Daniel Mack,
Haojian Zhuang, Robert Jarzmik, Mark Brown
On Mon, Feb 23, 2026 at 05:09:03PM +0000, David Laight wrote:
> On Mon, 23 Feb 2026 16:30:54 +0100
> Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
>
> > min_t(int, a, b) casts an 'u32' to 'int'. This might lead to
> > the cases when big number is wrongly chosen. On the other hand,
> > the SPI transfer speed rate is unsigned and driver uses signed type
> > for an unknown reason. Change the type of the SPI transfer speed
> > to be unsigned and convert to use min() instead of min_t().
>
> Reviewed-by: David Laight <david.laight.linux@gmail.com>
Thanks!
...
> > -static unsigned int quark_x1000_get_clk_div(int rate, u32 *dds)
> > +static unsigned int quark_x1000_get_clk_div(u32 rate, u32 *dds)
> I've looked at the file...
> I think all the 'long' in that function can be 32bit.
> Especially if the code actually works on 32bit.
> There is also the stunning:
> do_div(fssp, 1 << 24);
> in the only bit that that does need u64.
I know, but it's unrelated to this patch aim.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2 1/1] spi: pxa2xx: use min() instead of min_t()
2026-02-23 15:30 [PATCH v2 1/1] spi: pxa2xx: use min() instead of min_t() Andy Shevchenko
2026-02-23 17:09 ` David Laight
@ 2026-02-25 19:07 ` Mark Brown
1 sibling, 0 replies; 4+ messages in thread
From: Mark Brown @ 2026-02-25 19:07 UTC (permalink / raw)
To: linux-arm-kernel, linux-spi, linux-kernel, Andy Shevchenko
Cc: Daniel Mack, Haojian Zhuang, Robert Jarzmik
On Mon, 23 Feb 2026 16:30:54 +0100, Andy Shevchenko wrote:
> min_t(int, a, b) casts an 'u32' to 'int'. This might lead to
> the cases when big number is wrongly chosen. On the other hand,
> the SPI transfer speed rate is unsigned and driver uses signed type
> for an unknown reason. Change the type of the SPI transfer speed
> to be unsigned and convert to use min() instead of min_t().
>
>
> [...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next
Thanks!
[1/1] spi: pxa2xx: use min() instead of min_t()
commit: 507a071d9868cb60e4e76f8a06fc8eb014f59ae4
All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying
to this mail.
Thanks,
Mark
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-02-25 19:07 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-23 15:30 [PATCH v2 1/1] spi: pxa2xx: use min() instead of min_t() Andy Shevchenko
2026-02-23 17:09 ` David Laight
2026-02-23 17:35 ` Andy Shevchenko
2026-02-25 19:07 ` Mark Brown
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox