* [PATCH 0/5] spi: replace strcpy(), sprintf() and simple_strtoul() with strscpy(), snprintf() and kstrtoul()
@ 2026-10-09 13:36 Aayush Kumar
2026-10-09 13:36 ` [PATCH 1/5] spi: butterfly: Use strscpy() instead of strcpy() Aayush Kumar
` (4 more replies)
0 siblings, 5 replies; 8+ messages in thread
From: Aayush Kumar @ 2026-10-09 13:36 UTC (permalink / raw)
To: broonie; +Cc: linux-spi, linux-kernel, Aayush Kumar
Replace strcpy(), sprintf() and simple_strtoul() with their safer
modern equivalents (strscpy, snprintf, kstrtoul).
Aayush Kumar (5):
spi: butterfly: Use strscpy() instead of strcpy()
spi: lm70llp: Use strscpy() instead of strcpy()
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-butterfly.c | 3 ++-
drivers/spi/spi-lm70llp.c | 2 +-
drivers/spi/spi-omap2-mcspi.c | 6 ++++--
drivers/spi/spi-s3c64xx.c | 3 ++-
drivers/spi/spi-tle62x0.c | 6 +++---
5 files changed, 12 insertions(+), 8 deletions(-)
--
2.56.0
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 1/5] spi: butterfly: Use strscpy() instead of strcpy()
2026-10-09 13:36 [PATCH 0/5] spi: replace strcpy(), sprintf() and simple_strtoul() with strscpy(), snprintf() and kstrtoul() Aayush Kumar
@ 2026-10-09 13:36 ` Aayush Kumar
2026-10-09 13:36 ` [PATCH 2/5] spi: lm70llp: " Aayush Kumar
` (3 subsequent siblings)
4 siblings, 0 replies; 8+ messages in thread
From: Aayush Kumar @ 2026-10-09 13:36 UTC (permalink / raw)
To: broonie; +Cc: linux-spi, linux-kernel, Aayush Kumar
Use a safer function strscpy() instead of strcpy() for copying to
arrays. Only idiomatic code replacement, and no functional changes.
Signed-off-by: Aayush Kumar <code@aayushk.dev>
---
drivers/spi/spi-butterfly.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/spi/spi-butterfly.c b/drivers/spi/spi-butterfly.c
index 84eb454ed..5e1e205bb 100644
--- a/drivers/spi/spi-butterfly.c
+++ b/drivers/spi/spi-butterfly.c
@@ -259,7 +259,8 @@ static void butterfly_attach(struct parport *p)
*/
pp->info[0].max_speed_hz = 15 * 1000 * 1000;
- strcpy(pp->info[0].modalias, "mtd_dataflash");
+ strscpy(pp->info[0].modalias, "mtd_dataflash",
+ sizeof(pp->info[0].modalias));
pp->info[0].platform_data = &flash;
pp->info[0].chip_select = 1;
pp->info[0].controller_data = pp;
--
2.56.0
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 2/5] spi: lm70llp: Use strscpy() instead of strcpy()
2026-10-09 13:36 [PATCH 0/5] spi: replace strcpy(), sprintf() and simple_strtoul() with strscpy(), snprintf() and kstrtoul() Aayush Kumar
2026-10-09 13:36 ` [PATCH 1/5] spi: butterfly: Use strscpy() instead of strcpy() Aayush Kumar
@ 2026-10-09 13:36 ` Aayush Kumar
2026-10-09 14:28 ` David Laight
2026-10-09 13:36 ` [PATCH 3/5] spi: tle62x0: Use kstrtoul() instead of simple_strtoul() Aayush Kumar
` (2 subsequent siblings)
4 siblings, 1 reply; 8+ messages in thread
From: Aayush Kumar @ 2026-10-09 13:36 UTC (permalink / raw)
To: broonie; +Cc: linux-spi, linux-kernel, Aayush Kumar
Use a safer function strscpy() instead of strcpy() for copying to
arrays. Only idiomatic code replacement, and no functional changes.
Signed-off-by: Aayush Kumar <code@aayushk.dev>
---
drivers/spi/spi-lm70llp.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/spi/spi-lm70llp.c b/drivers/spi/spi-lm70llp.c
index e61e89b41..bd8028892 100644
--- a/drivers/spi/spi-lm70llp.c
+++ b/drivers/spi/spi-lm70llp.c
@@ -252,7 +252,7 @@ static void spi_lm70llp_attach(struct parport *p)
* We are binding to the generic drivers/hwmon/lm70.c device
* driver.
*/
- strcpy(pp->info.modalias, "lm70");
+ strscpy(pp->info.modalias, "lm70", sizeof(pp->info.modalias));
pp->info.max_speed_hz = 6 * 1000 * 1000;
pp->info.chip_select = 0;
pp->info.mode = SPI_3WIRE | SPI_MODE_0;
--
2.56.0
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 3/5] spi: tle62x0: Use kstrtoul() instead of simple_strtoul()
2026-10-09 13:36 [PATCH 0/5] spi: replace strcpy(), sprintf() and simple_strtoul() with strscpy(), snprintf() and kstrtoul() Aayush Kumar
2026-10-09 13:36 ` [PATCH 1/5] spi: butterfly: Use strscpy() instead of strcpy() Aayush Kumar
2026-10-09 13:36 ` [PATCH 2/5] spi: lm70llp: " Aayush Kumar
@ 2026-10-09 13:36 ` Aayush Kumar
2026-10-09 13:36 ` [PATCH 4/5] spi: omap2-mcspi: Use snprintf() instead of sprintf() Aayush Kumar
2026-10-09 13:36 ` [PATCH 5/5] spi: s3c64xx: " Aayush Kumar
4 siblings, 0 replies; 8+ messages in thread
From: Aayush Kumar @ 2026-10-09 13:36 UTC (permalink / raw)
To: broonie; +Cc: linux-spi, linux-kernel, Aayush Kumar
Use the recommended kstrtoul() instead of the deprecated
simple_strtoul(). Check the return value and reject invalid values.
Signed-off-by: Aayush Kumar <code@aayushk.dev>
---
drivers/spi/spi-tle62x0.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/spi/spi-tle62x0.c b/drivers/spi/spi-tle62x0.c
index dd8bfb3f3..986d78ab4 100644
--- a/drivers/spi/spi-tle62x0.c
+++ b/drivers/spi/spi-tle62x0.c
@@ -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);
--
2.56.0
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 4/5] spi: omap2-mcspi: Use snprintf() instead of sprintf()
2026-10-09 13:36 [PATCH 0/5] spi: replace strcpy(), sprintf() and simple_strtoul() with strscpy(), snprintf() and kstrtoul() Aayush Kumar
` (2 preceding siblings ...)
2026-10-09 13:36 ` [PATCH 3/5] spi: tle62x0: Use kstrtoul() instead of simple_strtoul() Aayush Kumar
@ 2026-10-09 13:36 ` Aayush Kumar
2026-10-09 13:36 ` [PATCH 5/5] spi: s3c64xx: " Aayush Kumar
4 siblings, 0 replies; 8+ messages in thread
From: Aayush Kumar @ 2026-10-09 13:36 UTC (permalink / raw)
To: broonie; +Cc: linux-spi, linux-kernel, Aayush Kumar
Use snprintf() instead of sprintf() to avoid potential buffer
overflows when formatting DMA channel names.
Signed-off-by: Aayush Kumar <code@aayushk.dev>
---
drivers/spi/spi-omap2-mcspi.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/spi/spi-omap2-mcspi.c b/drivers/spi/spi-omap2-mcspi.c
index a3355147f..311ee0ca9 100644
--- a/drivers/spi/spi-omap2-mcspi.c
+++ b/drivers/spi/spi-omap2-mcspi.c
@@ -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]);
--
2.56.0
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 5/5] spi: s3c64xx: Use snprintf() instead of sprintf()
2026-10-09 13:36 [PATCH 0/5] spi: replace strcpy(), sprintf() and simple_strtoul() with strscpy(), snprintf() and kstrtoul() Aayush Kumar
` (3 preceding siblings ...)
2026-10-09 13:36 ` [PATCH 4/5] spi: omap2-mcspi: Use snprintf() instead of sprintf() Aayush Kumar
@ 2026-10-09 13:36 ` Aayush Kumar
4 siblings, 0 replies; 8+ messages in thread
From: Aayush Kumar @ 2026-10-09 13:36 UTC (permalink / raw)
To: broonie; +Cc: linux-spi, linux-kernel, Aayush Kumar
Use snprintf() instead of sprintf() to avoid potential buffer
overflows when formatting the clock name.
Signed-off-by: Aayush Kumar <code@aayushk.dev>
---
drivers/spi/spi-s3c64xx.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/spi/spi-s3c64xx.c b/drivers/spi/spi-s3c64xx.c
index 8d4120cf9..8195bf376 100644
--- a/drivers/spi/spi-s3c64xx.c
+++ b/drivers/spi/spi-s3c64xx.c
@@ -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),
--
2.56.0
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/5] spi: lm70llp: Use strscpy() instead of strcpy()
2026-10-09 13:36 ` [PATCH 2/5] spi: lm70llp: " Aayush Kumar
@ 2026-10-09 14:28 ` David Laight
2026-10-09 17:13 ` Aayush Kumar
0 siblings, 1 reply; 8+ messages in thread
From: David Laight @ 2026-10-09 14:28 UTC (permalink / raw)
To: Aayush Kumar; +Cc: broonie, linux-spi, linux-kernel
On Fri, 9 Oct 2026 19:06:06 +0530
Aayush Kumar <code@aayushk.dev> wrote:
> Use a safer function strscpy() instead of strcpy() for copying to
> arrays. Only idiomatic code replacement, and no functional changes.
>
> Signed-off-by: Aayush Kumar <code@aayushk.dev>
> ---
> drivers/spi/spi-lm70llp.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/spi/spi-lm70llp.c b/drivers/spi/spi-lm70llp.c
> index e61e89b41..bd8028892 100644
> --- a/drivers/spi/spi-lm70llp.c
> +++ b/drivers/spi/spi-lm70llp.c
> @@ -252,7 +252,7 @@ static void spi_lm70llp_attach(struct parport *p)
> * We are binding to the generic drivers/hwmon/lm70.c device
> * driver.
> */
> - strcpy(pp->info.modalias, "lm70");
> + strscpy(pp->info.modalias, "lm70", sizeof(pp->info.modalias));
Come on, if you are going to do that use the two argument form.
Or just don't bother at all.
Do the test compiles - if the literal string is too long you'll
get a compile error for strcpy(), but strscpy() truncates and returns
an error.
So strcpy() is arguably better.
David
> pp->info.max_speed_hz = 6 * 1000 * 1000;
> pp->info.chip_select = 0;
> pp->info.mode = SPI_3WIRE | SPI_MODE_0;
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/5] spi: lm70llp: Use strscpy() instead of strcpy()
2026-10-09 14:28 ` David Laight
@ 2026-10-09 17:13 ` Aayush Kumar
0 siblings, 0 replies; 8+ messages in thread
From: Aayush Kumar @ 2026-10-09 17:13 UTC (permalink / raw)
To: David Laight; +Cc: broonie, linux-spi, linux-kernel
On Fri, Oct 9, 2026 at 7:58 PM David Laight
<david.laight.linux@gmail.com> wrote:
> So strcpy() is arguably better.
Fair point, I'll drop both the strscpy patches in v2. Thanks
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2026-10-09 17:13 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-09 13:36 [PATCH 0/5] spi: replace strcpy(), sprintf() and simple_strtoul() with strscpy(), snprintf() and kstrtoul() Aayush Kumar
2026-10-09 13:36 ` [PATCH 1/5] spi: butterfly: Use strscpy() instead of strcpy() Aayush Kumar
2026-10-09 13:36 ` [PATCH 2/5] spi: lm70llp: " Aayush Kumar
2026-10-09 14:28 ` David Laight
2026-10-09 17:13 ` Aayush Kumar
2026-10-09 13:36 ` [PATCH 3/5] spi: tle62x0: Use kstrtoul() instead of simple_strtoul() Aayush Kumar
2026-10-09 13:36 ` [PATCH 4/5] spi: omap2-mcspi: Use snprintf() instead of sprintf() Aayush Kumar
2026-10-09 13:36 ` [PATCH 5/5] spi: s3c64xx: " Aayush Kumar
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®