The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH AUTOSEL 6.6 01/16] spi: spi-fsl-lpspi: Adjust type of scldiv
@ 2024-11-24 12:52 Sasha Levin
  2024-11-24 12:52 ` [PATCH AUTOSEL 6.6 02/16] HID: add per device quirk to force bind to hid-generic Sasha Levin
                   ` (14 more replies)
  0 siblings, 15 replies; 16+ messages in thread
From: Sasha Levin @ 2024-11-24 12:52 UTC (permalink / raw)
  To: linux-kernel, stable
  Cc: Stefan Wahren, Frank Li, Mark Brown, Sasha Levin, linux-spi, imx

From: Stefan Wahren <wahrenst@gmx.net>

[ Upstream commit fa8ecda9876ac1e7b29257aa82af1fd0695496e2 ]

The target value of scldiv is just a byte, but its calculation in
fsl_lpspi_set_bitrate could be negative. So use an adequate type to store
the result and avoid overflows. After that this needs range check
adjustments, but this should make the code less opaque.

Signed-off-by: Stefan Wahren <wahrenst@gmx.net>
Reviewed-by: Frank Li <Frank.Li@nxp.com>
Link: https://patch.msgid.link/20240930093056.93418-2-wahrenst@gmx.net
Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 drivers/spi/spi-fsl-lpspi.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/spi/spi-fsl-lpspi.c b/drivers/spi/spi-fsl-lpspi.c
index 13313f07839b6..84881983d5d9f 100644
--- a/drivers/spi/spi-fsl-lpspi.c
+++ b/drivers/spi/spi-fsl-lpspi.c
@@ -315,9 +315,10 @@ static void fsl_lpspi_set_watermark(struct fsl_lpspi_data *fsl_lpspi)
 static int fsl_lpspi_set_bitrate(struct fsl_lpspi_data *fsl_lpspi)
 {
 	struct lpspi_config config = fsl_lpspi->config;
-	unsigned int perclk_rate, scldiv, div;
+	unsigned int perclk_rate, div;
 	u8 prescale_max;
 	u8 prescale;
+	int scldiv;
 
 	perclk_rate = clk_get_rate(fsl_lpspi->clk_per);
 	prescale_max = fsl_lpspi->devtype_data->prescale_max;
@@ -338,13 +339,13 @@ static int fsl_lpspi_set_bitrate(struct fsl_lpspi_data *fsl_lpspi)
 
 	for (prescale = 0; prescale <= prescale_max; prescale++) {
 		scldiv = div / (1 << prescale) - 2;
-		if (scldiv < 256) {
+		if (scldiv >= 0 && scldiv < 256) {
 			fsl_lpspi->config.prescale = prescale;
 			break;
 		}
 	}
 
-	if (scldiv >= 256)
+	if (scldiv < 0 || scldiv >= 256)
 		return -EINVAL;
 
 	writel(scldiv | (scldiv << 8) | ((scldiv >> 1) << 16),
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2024-11-24 12:54 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-24 12:52 [PATCH AUTOSEL 6.6 01/16] spi: spi-fsl-lpspi: Adjust type of scldiv Sasha Levin
2024-11-24 12:52 ` [PATCH AUTOSEL 6.6 02/16] HID: add per device quirk to force bind to hid-generic Sasha Levin
2024-11-24 12:52 ` [PATCH AUTOSEL 6.6 03/16] media: v4l: Add luma 16-bit interlaced pixel format Sasha Levin
2024-11-24 12:52 ` [PATCH AUTOSEL 6.6 04/16] media: uvcvideo: " Sasha Levin
2024-11-24 12:52 ` [PATCH AUTOSEL 6.6 05/16] media: uvcvideo: RealSense D421 Depth module metadata Sasha Levin
2024-11-24 12:52 ` [PATCH AUTOSEL 6.6 06/16] media: uvcvideo: Add a quirk for the Kaiweets KTI-W02 infrared camera Sasha Levin
2024-11-24 12:52 ` [PATCH AUTOSEL 6.6 07/16] media: vb2: use lock if wait_prepare/finish are NULL Sasha Levin
2024-11-24 12:52 ` [PATCH AUTOSEL 6.6 08/16] media: cx231xx: Add support for Dexatek USB Video Grabber 1d19:6108 Sasha Levin
2024-11-24 12:52 ` [PATCH AUTOSEL 6.6 09/16] mmc: core: Add SD card quirk for broken poweroff notification Sasha Levin
2024-11-24 12:52 ` [PATCH AUTOSEL 6.6 10/16] mmc: sdhci-esdhc-imx: enable quirks SDHCI_QUIRK_NO_LED Sasha Levin
2024-11-24 12:52 ` [PATCH AUTOSEL 6.6 11/16] soc: imx8m: Probe the SoC driver as platform driver Sasha Levin
2024-11-24 12:52 ` [PATCH AUTOSEL 6.6 12/16] HID: bpf: Fix NKRO on Mistel MD770 Sasha Levin
2024-11-24 12:52 ` [PATCH AUTOSEL 6.6 13/16] regmap: maple: Provide lockdep (sub)class for maple tree's internal lock Sasha Levin
2024-11-24 12:52 ` [PATCH AUTOSEL 6.6 14/16] selftests/resctrl: Protect against array overflow when reading strings Sasha Levin
2024-11-24 12:52 ` [PATCH AUTOSEL 6.6 15/16] USB: gadget: pxa27x_udc: Avoid using GPIOF_ACTIVE_LOW Sasha Levin
2024-11-24 12:52 ` [PATCH AUTOSEL 6.6 16/16] HID: magicmouse: Apple Magic Trackpad 2 USB-C driver support Sasha Levin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox