drivers/gpio/gpiolib-cdev.c:795:3: warning: 'strncpy' specified bound 32 equals destination size

From: kernel test robot
Date: Tue Aug 11 2020 - 17:18:20 EST


tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: 00e4db51259a5f936fec1424b884f029479d3981
commit: 925ca36913fc7dfee9d0bb7f36d81dd108a7b80f gpiolib: split character device into gpiolib-cdev
date: 7 weeks ago
config: arm64-randconfig-r002-20200811 (attached as .config)
compiler: aarch64-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
git checkout 925ca36913fc7dfee9d0bb7f36d81dd108a7b80f
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=arm64

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@xxxxxxxxx>

All warnings (new ones prefixed by >>):

drivers/gpio/gpiolib-cdev.c: In function 'gpio_desc_to_lineinfo':
>> drivers/gpio/gpiolib-cdev.c:795:3: warning: 'strncpy' specified bound 32 equals destination size [-Wstringop-truncation]
795 | strncpy(info->name, desc->name, sizeof(info->name));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

vim +/strncpy +795 drivers/gpio/gpiolib-cdev.c

774
775 static void gpio_desc_to_lineinfo(struct gpio_desc *desc,
776 struct gpioline_info *info)
777 {
778 struct gpio_chip *gc = desc->gdev->chip;
779 bool ok_for_pinctrl;
780 unsigned long flags;
781
782 /*
783 * This function takes a mutex so we must check this before taking
784 * the spinlock.
785 *
786 * FIXME: find a non-racy way to retrieve this information. Maybe a
787 * lock common to both frameworks?
788 */
789 ok_for_pinctrl =
790 pinctrl_gpio_can_use_line(gc->base + info->line_offset);
791
792 spin_lock_irqsave(&gpio_lock, flags);
793
794 if (desc->name) {
> 795 strncpy(info->name, desc->name, sizeof(info->name));
796 info->name[sizeof(info->name) - 1] = '\0';
797 } else {
798 info->name[0] = '\0';
799 }
800
801 if (desc->label) {
802 strncpy(info->consumer, desc->label, sizeof(info->consumer));
803 info->consumer[sizeof(info->consumer) - 1] = '\0';
804 } else {
805 info->consumer[0] = '\0';
806 }
807
808 /*
809 * Userspace only need to know that the kernel is using this GPIO so
810 * it can't use it.
811 */
812 info->flags = 0;
813 if (test_bit(FLAG_REQUESTED, &desc->flags) ||
814 test_bit(FLAG_IS_HOGGED, &desc->flags) ||
815 test_bit(FLAG_USED_AS_IRQ, &desc->flags) ||
816 test_bit(FLAG_EXPORT, &desc->flags) ||
817 test_bit(FLAG_SYSFS, &desc->flags) ||
818 !ok_for_pinctrl)
819 info->flags |= GPIOLINE_FLAG_KERNEL;
820 if (test_bit(FLAG_IS_OUT, &desc->flags))
821 info->flags |= GPIOLINE_FLAG_IS_OUT;
822 if (test_bit(FLAG_ACTIVE_LOW, &desc->flags))
823 info->flags |= GPIOLINE_FLAG_ACTIVE_LOW;
824 if (test_bit(FLAG_OPEN_DRAIN, &desc->flags))
825 info->flags |= (GPIOLINE_FLAG_OPEN_DRAIN |
826 GPIOLINE_FLAG_IS_OUT);
827 if (test_bit(FLAG_OPEN_SOURCE, &desc->flags))
828 info->flags |= (GPIOLINE_FLAG_OPEN_SOURCE |
829 GPIOLINE_FLAG_IS_OUT);
830 if (test_bit(FLAG_BIAS_DISABLE, &desc->flags))
831 info->flags |= GPIOLINE_FLAG_BIAS_DISABLE;
832 if (test_bit(FLAG_PULL_DOWN, &desc->flags))
833 info->flags |= GPIOLINE_FLAG_BIAS_PULL_DOWN;
834 if (test_bit(FLAG_PULL_UP, &desc->flags))
835 info->flags |= GPIOLINE_FLAG_BIAS_PULL_UP;
836
837 spin_unlock_irqrestore(&gpio_lock, flags);
838 }
839

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@xxxxxxxxxxxx

Attachment: .config.gz
Description: application/gzip