drivers/gpu/drm/drm_property.c:103:3: warning: 'strncpy' specified bound 32 equals destination size

From: kbuild test robot
Date: Mon May 28 2018 - 21:54:40 EST


Hi Josh,

First bad commit (maybe != root cause):

tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: 786b71f5b754273ccef6d9462e52062b3e1f9877
commit: 854e55ad289ef8888e7991f0ada85d5846f5afb9 objtool, perf: Fix GCC 8 -Wrestrict error
date: 2 months ago
config: x86_64-randconfig-a0-05290809 (attached as .config)
compiler: gcc-8 (Debian 8.1.0-3) 8.1.0
reproduce:
git checkout 854e55ad289ef8888e7991f0ada85d5846f5afb9
# save the attached .config to linux build tree
make ARCH=x86_64

All warnings (new ones prefixed by >>):

drivers/gpu/drm/drm_property.c: In function 'drm_property_create':
>> drivers/gpu/drm/drm_property.c:103:3: warning: 'strncpy' specified bound 32 equals destination size [-Wstringop-truncation]
strncpy(property->name, name, DRM_PROP_NAME_LEN);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--
drivers/iio/pressure/st_pressure_i2c.c: In function 'st_press_i2c_probe':
>> drivers/iio/pressure/st_pressure_i2c.c:97:3: warning: 'strncpy' specified bound 20 equals destination size [-Wstringop-truncation]
strncpy(client->name, st_press_id_table[ret].name,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sizeof(client->name));
~~~~~~~~~~~~~~~~~~~~~

vim +/strncpy +103 drivers/gpu/drm/drm_property.c

59e71ee7 Daniel Vetter 2016-08-29 59
59e71ee7 Daniel Vetter 2016-08-29 60 /**
59e71ee7 Daniel Vetter 2016-08-29 61 * drm_property_create - create a new property type
59e71ee7 Daniel Vetter 2016-08-29 62 * @dev: drm device
59e71ee7 Daniel Vetter 2016-08-29 63 * @flags: flags specifying the property type
59e71ee7 Daniel Vetter 2016-08-29 64 * @name: name of the property
59e71ee7 Daniel Vetter 2016-08-29 65 * @num_values: number of pre-defined values
59e71ee7 Daniel Vetter 2016-08-29 66 *
59e71ee7 Daniel Vetter 2016-08-29 67 * This creates a new generic drm property which can then be attached to a drm
6a8a66ed Daniel Vetter 2016-11-23 68 * object with drm_object_attach_property(). The returned property object must
6a8a66ed Daniel Vetter 2016-11-23 69 * be freed with drm_property_destroy(), which is done automatically when
6a8a66ed Daniel Vetter 2016-11-23 70 * calling drm_mode_config_cleanup().
59e71ee7 Daniel Vetter 2016-08-29 71 *
59e71ee7 Daniel Vetter 2016-08-29 72 * Returns:
59e71ee7 Daniel Vetter 2016-08-29 73 * A pointer to the newly created property on success, NULL on failure.
59e71ee7 Daniel Vetter 2016-08-29 74 */
59e71ee7 Daniel Vetter 2016-08-29 75 struct drm_property *drm_property_create(struct drm_device *dev, int flags,
59e71ee7 Daniel Vetter 2016-08-29 76 const char *name, int num_values)
59e71ee7 Daniel Vetter 2016-08-29 77 {
59e71ee7 Daniel Vetter 2016-08-29 78 struct drm_property *property = NULL;
59e71ee7 Daniel Vetter 2016-08-29 79 int ret;
59e71ee7 Daniel Vetter 2016-08-29 80
59e71ee7 Daniel Vetter 2016-08-29 81 property = kzalloc(sizeof(struct drm_property), GFP_KERNEL);
59e71ee7 Daniel Vetter 2016-08-29 82 if (!property)
59e71ee7 Daniel Vetter 2016-08-29 83 return NULL;
59e71ee7 Daniel Vetter 2016-08-29 84
59e71ee7 Daniel Vetter 2016-08-29 85 property->dev = dev;
59e71ee7 Daniel Vetter 2016-08-29 86
59e71ee7 Daniel Vetter 2016-08-29 87 if (num_values) {
59e71ee7 Daniel Vetter 2016-08-29 88 property->values = kcalloc(num_values, sizeof(uint64_t),
59e71ee7 Daniel Vetter 2016-08-29 89 GFP_KERNEL);
59e71ee7 Daniel Vetter 2016-08-29 90 if (!property->values)
59e71ee7 Daniel Vetter 2016-08-29 91 goto fail;
59e71ee7 Daniel Vetter 2016-08-29 92 }
59e71ee7 Daniel Vetter 2016-08-29 93
2135ea7a Thierry Reding 2017-02-28 94 ret = drm_mode_object_add(dev, &property->base, DRM_MODE_OBJECT_PROPERTY);
59e71ee7 Daniel Vetter 2016-08-29 95 if (ret)
59e71ee7 Daniel Vetter 2016-08-29 96 goto fail;
59e71ee7 Daniel Vetter 2016-08-29 97
59e71ee7 Daniel Vetter 2016-08-29 98 property->flags = flags;
59e71ee7 Daniel Vetter 2016-08-29 99 property->num_values = num_values;
59e71ee7 Daniel Vetter 2016-08-29 100 INIT_LIST_HEAD(&property->enum_list);
59e71ee7 Daniel Vetter 2016-08-29 101
59e71ee7 Daniel Vetter 2016-08-29 102 if (name) {
59e71ee7 Daniel Vetter 2016-08-29 @103 strncpy(property->name, name, DRM_PROP_NAME_LEN);
59e71ee7 Daniel Vetter 2016-08-29 104 property->name[DRM_PROP_NAME_LEN-1] = '\0';
59e71ee7 Daniel Vetter 2016-08-29 105 }
59e71ee7 Daniel Vetter 2016-08-29 106
59e71ee7 Daniel Vetter 2016-08-29 107 list_add_tail(&property->head, &dev->mode_config.property_list);
59e71ee7 Daniel Vetter 2016-08-29 108
59e71ee7 Daniel Vetter 2016-08-29 109 WARN_ON(!drm_property_type_valid(property));
59e71ee7 Daniel Vetter 2016-08-29 110
59e71ee7 Daniel Vetter 2016-08-29 111 return property;
59e71ee7 Daniel Vetter 2016-08-29 112 fail:
59e71ee7 Daniel Vetter 2016-08-29 113 kfree(property->values);
59e71ee7 Daniel Vetter 2016-08-29 114 kfree(property);
59e71ee7 Daniel Vetter 2016-08-29 115 return NULL;
59e71ee7 Daniel Vetter 2016-08-29 116 }
59e71ee7 Daniel Vetter 2016-08-29 117 EXPORT_SYMBOL(drm_property_create);
59e71ee7 Daniel Vetter 2016-08-29 118

:::::: The code at line 103 was first introduced by commit
:::::: 59e71ee746a37fe077b73cecf189de1d27efd6eb drm: Extract drm_property.[hc]

:::::: TO: Daniel Vetter <daniel.vetter@xxxxxxxx>
:::::: CC: Daniel Vetter <daniel.vetter@xxxxxxxx>

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

Attachment: .config.gz
Description: application/gzip