Skip to contentSkip to conversation

powerpc: fsl_rio: Use snprintf() in fsl_rio_setup()

PATCH In review Thorsten Blum 3 participants 4 messages Jun 30 – Sep 16 PowerPC

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 powerpc: fsl_rio: Use snprintf() in fsl_rio_setup()

While the current code works correctly, replace the unbounded sprintf() with the safer snprintf() in fsl_rio_setup() to follow secure coding best practices.

---
 arch/powerpc/sysdev/fsl_rio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/sysdev/fsl_rio.c +1 -1
index eb55dabb4748..077c03cd93e4 100644
@@ -612,7 +612,7 @@ static int fsl_rio_setup(struct platform_device *dev)
 				kfree(port);
 				continue;
 		}
-		sprintf(port->name, "RIO mport %d", i);
+		snprintf(port->name, sizeof(port->name), "RIO mport %d", i);
 
 		priv->dev = &dev->dev;
 		port->dev.parent = &dev->dev;
#1 lore raw

Le 30/06/2026 à 16:49, Thorsten Blum a écrit :

Quoted 14 lines

While the current code works correctly, replace the unbounded sprintf() with the safer snprintf() in fsl_rio_setup() to follow secure coding best practices.

---
  arch/powerpc/sysdev/fsl_rio.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/sysdev/fsl_rio.c +0 -0
index eb55dabb4748..077c03cd93e4 100644

arch/powerpc/sysdev/fsl_rio.c static int fsl_rio_setup(struct platform_device *dev) · line 615

Quoted 5 lines
arch/powerpc/sysdev/fsl_rio.c +1 -1
@@ -612,7 +612,7 @@ static int fsl_rio_setup(struct platform_device *dev)
  				kfree(port);
  				continue;
  		}
-		sprintf(port->name, "RIO mport %d", i);
+		snprintf(port->name, sizeof(port->name), "RIO mport %d", i);

Are you sure it is correct ?

Shouldn't it be sizeof(port->name) - 1 ?

Quoted 3 lines
arch/powerpc/sysdev/fsl_rio.c +0 -0
  		priv->dev = &dev->dev;
  		port->dev.parent = &dev->dev;
#2 lore raw
Quoted 23 lines · Christophe Leroy (CS GROUP)

Le 30/06/2026 à 16:49, Thorsten Blum a écrit :

Quoted 14 lines

While the current code works correctly, replace the unbounded sprintf() with the safer snprintf() in fsl_rio_setup() to follow secure coding best practices.

---
  arch/powerpc/sysdev/fsl_rio.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/sysdev/fsl_rio.c +0 -0
index eb55dabb4748..077c03cd93e4 100644

arch/powerpc/sysdev/fsl_rio.c static int fsl_rio_setup(struct platform_device *dev) · line 615

Quoted 5 lines
arch/powerpc/sysdev/fsl_rio.c +1 -1
@@ -612,7 +612,7 @@ static int fsl_rio_setup(struct platform_device *dev)
  				kfree(port);
  				continue;
  		}
-		sprintf(port->name, "RIO mport %d", i);
+		snprintf(port->name, sizeof(port->name), "RIO mport %d", i);

Are you sure it is correct ?

Quoted 1 line

Shouldn't it be sizeof(port->name) - 1 ?

snprintf() takes the destination buffer size (including the NUL) as its second argument, so sizeof(port->name) should be correct.

#3 lore raw
In reply to Thorsten Blum
Quoted 8 lines · Thorsten Blum

While the current code works correctly, replace the unbounded sprintf() with the safer snprintf() in fsl_rio_setup() to follow secure coding best practices.

---
 arch/powerpc/sysdev/fsl_rio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Gentle ping?

Quoted 13 lines
arch/powerpc/sysdev/fsl_rio.c +1 -1
index eb55dabb4748..077c03cd93e4 100644
@@ -612,7 +612,7 @@ static int fsl_rio_setup(struct platform_device *dev)
 				kfree(port);
 				continue;
 		}
-		sprintf(port->name, "RIO mport %d", i);
+		snprintf(port->name, sizeof(port->name), "RIO mport %d", i);
 
 		priv->dev = &dev->dev;
 		port->dev.parent = &dev->dev;