[PATCH] powerpc: fix i2c device string format

Guennadi Liakhovetski g.liakhovetski at gmx.de
Wed Aug 8 08:32:58 EST 2007


On Wed, 1 Aug 2007, Segher Boessenkool wrote:

> strncpy() won't put a terminating zero on there, is everything
> that uses the resulting string okay with that?  Also, if the
> name gets cut short, it might match some _other_ expected name.

On Wed, 1 Aug 2007, Scott Wood wrote:

> You could use strlcpy() instead, which always leaves a zero terminator.

The patch below does exactly this - uses strlcpy() to guarantee strings in 
i2c device type and driver_name fields are 0-terminated.

Signed-off-by: G. Liakhovetski <g.liakhovetski at gmx.de>

---

Trying to follow the "canonical" patch format: Paul, please queue this 
patch for 2.6.24. It is not critical, as there no strings at the moment in 
fsl_soc.c, that exceed i2c limits. So, it's just a precaution measure.

Thanks
Guennadi

diff --git a/arch/powerpc/sysdev/fsl_soc.c b/arch/powerpc/sysdev/fsl_soc.c
index 727453d..2ef7036 100644
--- a/arch/powerpc/sysdev/fsl_soc.c
+++ b/arch/powerpc/sysdev/fsl_soc.c
@@ -327,8 +327,8 @@ static int __init of_find_i2c_driver(struct device_node *node, struct i2c_board_
 	for (i = 0; i < ARRAY_SIZE(i2c_devices); i++) {
 		if (!of_device_is_compatible(node, i2c_devices[i].of_device))
 			continue;
-		strncpy(info->driver_name, i2c_devices[i].i2c_driver, KOBJ_NAME_LEN);
-		strncpy(info->type, i2c_devices[i].i2c_type, I2C_NAME_SIZE);
+		strlcpy(info->driver_name, i2c_devices[i].i2c_driver, KOBJ_NAME_LEN);
+		strlcpy(info->type, i2c_devices[i].i2c_type, I2C_NAME_SIZE);
 		return 0;
 	}
 	return -ENODEV;



More information about the Linuxppc-dev mailing list