iio: change strncpy+truncation to strlcpy
authorDominique Martinet <asmadeus@codewreck.org>
Fri, 13 Jul 2018 01:25:34 +0000 (03:25 +0200)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Sun, 15 Jul 2018 10:38:06 +0000 (11:38 +0100)
Generated by scripts/coccinelle/misc/strncpy_truncation.cocci

Signed-off-by: Dominique Martinet <asmadeus@codewreck.org>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/common/st_sensors/st_sensors_core.c
drivers/iio/pressure/st_pressure_i2c.c

index 57db191..26fbd1b 100644 (file)
@@ -380,8 +380,7 @@ void st_sensors_of_name_probe(struct device *dev,
                return;
 
        /* The name from the OF match takes precedence if present */
-       strncpy(name, of_id->data, len);
-       name[len - 1] = '\0';
+       strlcpy(name, of_id->data, len);
 }
 EXPORT_SYMBOL(st_sensors_of_name_probe);
 #else
index fbb5905..2026a10 100644 (file)
@@ -94,9 +94,8 @@ static int st_press_i2c_probe(struct i2c_client *client,
                if ((ret < 0) || (ret >= ST_PRESS_MAX))
                        return -ENODEV;
 
-               strncpy(client->name, st_press_id_table[ret].name,
+               strlcpy(client->name, st_press_id_table[ret].name,
                                sizeof(client->name));
-               client->name[sizeof(client->name) - 1] = '\0';
        } else if (!id)
                return -ENODEV;