All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] iio: accel: use strlcpy() instead of strncpy()
@ 2018-01-12  7:45 Xiongfeng Wang
  2018-01-14 12:02 ` Jonathan Cameron
  0 siblings, 1 reply; 2+ messages in thread
From: Xiongfeng Wang @ 2018-01-12  7:45 UTC (permalink / raw)
  To: lars, pmeerw, linux-iio; +Cc: linux-kernel, arnd, wangxiongfeng2

From: Xiongfeng Wang <xiongfeng.wang@linaro.org>

gcc-8 reports

drivers/iio/accel/st_accel_i2c.c: In function 'st_accel_i2c_probe':
./include/linux/string.h:245:9: warning: '__builtin_strncpy' specified
bound 20 equals destination size [-Wstringop-truncation]

The compiler require that the length of the dest string is greater than
the length we want to copy to make sure the dest string is
nul-terminated. We can just use strlcpy() to avoid this warning.

Signed-off-by: Xiongfeng Wang <xiongfeng.wang@linaro.org>
---
 drivers/iio/accel/st_accel_i2c.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/iio/accel/st_accel_i2c.c b/drivers/iio/accel/st_accel_i2c.c
index 363429b..6bdec8c 100644
--- a/drivers/iio/accel/st_accel_i2c.c
+++ b/drivers/iio/accel/st_accel_i2c.c
@@ -159,9 +159,8 @@ static int st_accel_i2c_probe(struct i2c_client *client,
 		if ((ret < 0) || (ret >= ST_ACCEL_MAX))
 			return -ENODEV;
 
-		strncpy(client->name, st_accel_id_table[ret].name,
+		strlcpy(client->name, st_accel_id_table[ret].name,
 				sizeof(client->name));
-		client->name[sizeof(client->name) - 1] = '\0';
 	} else if (!id)
 		return -ENODEV;
 
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] iio: accel: use strlcpy() instead of strncpy()
  2018-01-12  7:45 [PATCH] iio: accel: use strlcpy() instead of strncpy() Xiongfeng Wang
@ 2018-01-14 12:02 ` Jonathan Cameron
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Cameron @ 2018-01-14 12:02 UTC (permalink / raw)
  To: Xiongfeng Wang; +Cc: lars, pmeerw, linux-iio, linux-kernel, arnd

On Fri, 12 Jan 2018 15:45:38 +0800
Xiongfeng Wang <wangxiongfeng2@huawei.com> wrote:

> From: Xiongfeng Wang <xiongfeng.wang@linaro.org>
> 
> gcc-8 reports
> 
> drivers/iio/accel/st_accel_i2c.c: In function 'st_accel_i2c_probe':
> ./include/linux/string.h:245:9: warning: '__builtin_strncpy' specified
> bound 20 equals destination size [-Wstringop-truncation]
> 
> The compiler require that the length of the dest string is greater than
> the length we want to copy to make sure the dest string is
> nul-terminated. We can just use strlcpy() to avoid this warning.
> 
> Signed-off-by: Xiongfeng Wang <xiongfeng.wang@linaro.org>
Hmm. As this is just warning suppression I'm not taking it as a fix
but rather via the slow path.

Applied to the togreg branch of iio.git and pushed out as testing for
the autobuilders to play with it.

Jonathan
> ---
>  drivers/iio/accel/st_accel_i2c.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/iio/accel/st_accel_i2c.c b/drivers/iio/accel/st_accel_i2c.c
> index 363429b..6bdec8c 100644
> --- a/drivers/iio/accel/st_accel_i2c.c
> +++ b/drivers/iio/accel/st_accel_i2c.c
> @@ -159,9 +159,8 @@ static int st_accel_i2c_probe(struct i2c_client *client,
>  		if ((ret < 0) || (ret >= ST_ACCEL_MAX))
>  			return -ENODEV;
>  
> -		strncpy(client->name, st_accel_id_table[ret].name,
> +		strlcpy(client->name, st_accel_id_table[ret].name,
>  				sizeof(client->name));
> -		client->name[sizeof(client->name) - 1] = '\0';
>  	} else if (!id)
>  		return -ENODEV;
>  

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-01-14 12:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-12  7:45 [PATCH] iio: accel: use strlcpy() instead of strncpy() Xiongfeng Wang
2018-01-14 12:02 ` Jonathan Cameron

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.