Commit 69e4e136 authored by Kent Gibson's avatar Kent Gibson Committed by Bartosz Golaszewski

gpiolib: cdev: replace strncpy() with strscpy()

Replace usage of strncpy() with strscpy() to remove -Wstringop-truncation
warnings.

The structures being populated are zeroed, to prevent stack leakage as
they are returned to userspace, so strscpy() performs the equivalent
function without the warnings.
Reported-by: default avatarkernel test robot <lkp@intel.com>
Signed-off-by: default avatarKent Gibson <warthog618@gmail.com>
Reviewed-by: default avatarAndy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: default avatarBartosz Golaszewski <bgolaszewski@baylibre.com>
parent 0dc11e3a
...@@ -752,6 +752,7 @@ static void gpio_desc_to_lineinfo(struct gpio_desc *desc, ...@@ -752,6 +752,7 @@ static void gpio_desc_to_lineinfo(struct gpio_desc *desc,
bool ok_for_pinctrl; bool ok_for_pinctrl;
unsigned long flags; unsigned long flags;
memset(info, 0, sizeof(*info));
info->line_offset = gpio_chip_hwgpio(desc); info->line_offset = gpio_chip_hwgpio(desc);
/* /*
...@@ -766,19 +767,11 @@ static void gpio_desc_to_lineinfo(struct gpio_desc *desc, ...@@ -766,19 +767,11 @@ static void gpio_desc_to_lineinfo(struct gpio_desc *desc,
spin_lock_irqsave(&gpio_lock, flags); spin_lock_irqsave(&gpio_lock, flags);
if (desc->name) { if (desc->name)
strncpy(info->name, desc->name, sizeof(info->name)); strscpy(info->name, desc->name, sizeof(info->name));
info->name[sizeof(info->name) - 1] = '\0';
} else {
info->name[0] = '\0';
}
if (desc->label) { if (desc->label)
strncpy(info->consumer, desc->label, sizeof(info->consumer)); strscpy(info->consumer, desc->label, sizeof(info->consumer));
info->consumer[sizeof(info->consumer) - 1] = '\0';
} else {
info->consumer[0] = '\0';
}
/* /*
* Userspace only need to know that the kernel is using this GPIO so * Userspace only need to know that the kernel is using this GPIO so
...@@ -842,12 +835,10 @@ static long gpio_ioctl(struct file *file, unsigned int cmd, unsigned long arg) ...@@ -842,12 +835,10 @@ static long gpio_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
memset(&chipinfo, 0, sizeof(chipinfo)); memset(&chipinfo, 0, sizeof(chipinfo));
strncpy(chipinfo.name, dev_name(&gdev->dev), strscpy(chipinfo.name, dev_name(&gdev->dev),
sizeof(chipinfo.name)); sizeof(chipinfo.name));
chipinfo.name[sizeof(chipinfo.name)-1] = '\0'; strscpy(chipinfo.label, gdev->label,
strncpy(chipinfo.label, gdev->label,
sizeof(chipinfo.label)); sizeof(chipinfo.label));
chipinfo.label[sizeof(chipinfo.label)-1] = '\0';
chipinfo.lines = gdev->ngpio; chipinfo.lines = gdev->ngpio;
if (copy_to_user(ip, &chipinfo, sizeof(chipinfo))) if (copy_to_user(ip, &chipinfo, sizeof(chipinfo)))
return -EFAULT; return -EFAULT;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment