Skip to contentSkip to conversation

spi: use kstrtoul() and snprintf()

PATCH In review Aayush Kumar 2 participants 5 messages Oct 10 – Oct 13

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v2 cover spi: use kstrtoul() and snprintf()

From: Aayush Kumar <[email protected]>

Replace simple_strtoul() with kstrtoul() and sprintf() with snprintf() in three SPI drivers.

---
Changes in v2:
- Drop the two strcpy() -> strscpy() patches (David Laight).
---

Aayush Kumar (3):
spi: tle62x0: Use kstrtoul() instead of simple_strtoul()
spi: omap2-mcspi: Use snprintf() instead of sprintf()
spi: s3c64xx: Use snprintf() instead of sprintf()

 drivers/spi/spi-omap2-mcspi.c | 6 ++++--
 drivers/spi/spi-s3c64xx.c     | 3 ++-
 drivers/spi/spi-tle62x0.c     | 6 +++---
 3 files changed, 9 insertions(+), 6 deletions(-)
Signature · 1 line
2.56.0
#1 lore raw

PATCH v2 1/3 spi: tle62x0: Use kstrtoul() instead of simple_strtoul()

From: Aayush Kumar <[email protected]>

Use the recommended kstrtoul() instead of the deprecated simple_strtoul(). Check the return value and reject invalid values.

---
 drivers/spi/spi-tle62x0.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/spi/spi-tle62x0.c +3 -3
index dd8bfb3f3..986d78ab4 100644
@@ -151,10 +151,10 @@ static ssize_t tle62x0_gpio_store(struct device *dev,
 	struct tle62x0_state *st = dev_get_drvdata(dev);
 	int gpio_num = to_gpio_num(attr);
 	unsigned long val;
-	char *endp;
+	int ret;
 
-	val = simple_strtoul(buf, &endp, 0);
-	if (buf == endp)
+	ret = kstrtoul(buf, 0, &val);
+	if (ret)
 		return -EINVAL;
 
 	dev_dbg(dev, "setting gpio %d to %ld\n", gpio_num, val);
Signature · 1 line
2.56.0
#2 lore raw

PATCH v2 2/3 spi: omap2-mcspi: Use snprintf() instead of sprintf()

In reply to Aayush Kumar

From: Aayush Kumar <[email protected]>

Use snprintf() instead of sprintf() to avoid potential buffer overflows when formatting DMA channel names.

---
 drivers/spi/spi-omap2-mcspi.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/spi/spi-omap2-mcspi.c +4 -2
index a3355147f..311ee0ca9 100644
@@ -1544,8 +1544,10 @@ static int omap2_mcspi_probe(struct platform_device *pdev)
 		return -ENOMEM;
 
 	for (i = 0; i < ctlr->num_chipselect; i++) {
-		sprintf(mcspi->dma_channels[i].dma_rx_ch_name, "rx%d", i);
-		sprintf(mcspi->dma_channels[i].dma_tx_ch_name, "tx%d", i);
+		snprintf(mcspi->dma_channels[i].dma_rx_ch_name,
+			 sizeof(mcspi->dma_channels[i].dma_rx_ch_name), "rx%d", i);
+		snprintf(mcspi->dma_channels[i].dma_tx_ch_name,
+			 sizeof(mcspi->dma_channels[i].dma_tx_ch_name), "tx%d", i);
 
 		status = omap2_mcspi_request_dma(mcspi,
 						 &mcspi->dma_channels[i]);
Signature · 1 line
2.56.0
#3 lore raw

PATCH v2 3/3 spi: s3c64xx: Use snprintf() instead of sprintf()

In reply to Aayush Kumar

From: Aayush Kumar <[email protected]>

Use snprintf() instead of sprintf() to avoid potential buffer overflows when formatting the clock name.

---
 drivers/spi/spi-s3c64xx.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/spi/spi-s3c64xx.c +2 -1
index 8d4120cf9..8195bf376 100644
@@ -1331,7 +1331,8 @@ static int s3c64xx_spi_probe(struct platform_device *pdev)
 		return dev_err_probe(&pdev->dev, PTR_ERR(sdd->clk),
 				     "Unable to acquire clock 'spi'\n");
 
-	sprintf(clk_name, "spi_busclk%d", sci->src_clk_nr);
+	snprintf(clk_name, sizeof(clk_name), "spi_busclk%d",
+		 sci->src_clk_nr);
 	sdd->src_clk = devm_clk_get_enabled(&pdev->dev, clk_name);
 	if (IS_ERR(sdd->src_clk))
 		return dev_err_probe(&pdev->dev, PTR_ERR(sdd->src_clk),
Signature · 1 line
2.56.0
maintainer
#4 lore raw
In reply to Aayush Kumar
Quoted 8 lines · Aayush Kumar

spi: use kstrtoul() and snprintf()

From: Aayush Kumar <[email protected]>

Replace simple_strtoul() with kstrtoul() and sprintf() with snprintf() in three SPI drivers.

[...]

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-7.4

Thanks!

[1/3] spi: tle62x0: Use kstrtoul() instead of simple_strtoul()

      https://git.kernel.org/broonie/misc/c/54f4db17f9d3
[2/3] spi: omap2-mcspi: Use snprintf() instead of sprintf()
      https://git.kernel.org/broonie/misc/c/9efc388655e4
[3/3] spi: s3c64xx: Use snprintf() instead of sprintf()
      https://git.kernel.org/broonie/misc/c/506fbac9274c

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