From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.gmx.net (mail.gmx.net [213.165.64.20]) by ozlabs.org (Postfix) with SMTP id A0BB7DE11A for ; Thu, 16 Aug 2007 05:15:06 +1000 (EST) Date: Wed, 15 Aug 2007 21:15:03 +0200 (CEST) From: Guennadi Liakhovetski To: Paul Mackerras Subject: Re: [PATCH] powerpc: fix i2c device string format In-Reply-To: <18114.39893.913684.592560@cargo.ozlabs.ibm.com> Message-ID: References: <2055bb54b9816faaf5b2ceedc9cfa039@kernel.crashing.org> <87DC7695-382B-4641-B9D9-75ACB49D41A4@kernel.crashing.org> <719AE7E4-FE6D-4973-8887-F787EC8ABC85@kernel.crashing.org> <235e0ff22961e25016727c0e74fd0c0f@kernel.crashing.org> <19a13f8700d078abc4cab0064a7d0183@kernel.crashing.org> <46B0F030.9030007@freescale.com> <3368b27f860fafb35d10f6352e9055bf@kernel.crashing.org> <18114.39893.913684.592560@cargo.ozlabs.ibm.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Cc: linuxppc-dev@ozlabs.org List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Use strlcpy() to guarantee strings in i2c device type and driver_name fields are 0-terminated. Signed-off-by: Guennadi Liakhovetski --- On Wed, 15 Aug 2007, Paul Mackerras wrote: > That's not a commit message I can use. Please repost with an > informative commit message that says what the motivation for the > change is, plus anything other information that would be useful for > someone looking at this in a couple of years' time. Sure, sorry. This should be fine - below "---" I may write whatever I want:-) Thanks Guennadi diff --git a/arch/powerpc/sysdev/fsl_soc.c b/arch/powerpc/sysdev/fsl_soc.c index 727453d..c0d66df 100644 --- a/arch/powerpc/sysdev/fsl_soc.c +++ b/arch/powerpc/sysdev/fsl_soc.c @@ -320,21 +320,26 @@ static struct i2c_driver_device i2c_devices[] __initdata = { {"ricoh,rv5c387a", "rtc-rs5c372", "rv5c387a",}, }; -static int __init of_find_i2c_driver(struct device_node *node, struct i2c_board_info *info) +static int __init of_find_i2c_driver(struct device_node *node, + struct i2c_board_info *info) { int i; 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); + if (strlcpy(info->driver_name, i2c_devices[i].i2c_driver, + KOBJ_NAME_LEN) >= KOBJ_NAME_LEN || + strlcpy(info->type, i2c_devices[i].i2c_type, + I2C_NAME_SIZE) >= I2C_NAME_SIZE) + return -ENOMEM; return 0; } return -ENODEV; } -static void __init of_register_i2c_devices(struct device_node *adap_node, int bus_num) +static void __init of_register_i2c_devices(struct device_node *adap_node, + int bus_num) { struct device_node *node = NULL;