All of lore.kernel.org
 help / color / mirror / Atom feed
* [freescale-fslc:5.10-2.1.x-imx 11497/15242] drivers/video/backlight/pwm_bl.c:261:17: warning: 'strncpy' specified bound 16 equals destination size
@ 2021-11-12 21:01 kernel test robot
  0 siblings, 0 replies; only message in thread
From: kernel test robot @ 2021-11-12 21:01 UTC (permalink / raw)
  To: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 6639 bytes --]

Hi Sandor,

FYI, the error/warning still remains.

tree:   https://github.com/Freescale/linux-fslc 5.10-2.1.x-imx
head:   3b81a70be1099d44fdafaa6766bf75a2bd9e297e
commit: 92123fc24af3d55dc3db2d862754fc2da1bccc8a [11497/15242] LF-3541: video/backligh: fix Coverity Issue: 9551473 Copy into fixed size buffer
config: sparc64-randconfig-p001-20210927 (attached as .config)
compiler: sparc64-linux-gcc (GCC) 11.2.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
        # https://github.com/Freescale/linux-fslc/commit/92123fc24af3d55dc3db2d862754fc2da1bccc8a
        git remote add freescale-fslc https://github.com/Freescale/linux-fslc
        git fetch --no-tags freescale-fslc 5.10-2.1.x-imx
        git checkout 92123fc24af3d55dc3db2d862754fc2da1bccc8a
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross ARCH=sparc64 

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

All warnings (new ones prefixed by >>):

   drivers/video/backlight/pwm_bl.c: In function 'pwm_backlight_parse_dt':
>> drivers/video/backlight/pwm_bl.c:261:17: warning: 'strncpy' specified bound 16 equals destination size [-Wstringop-truncation]
     261 |                 strncpy(data->fb_id, names, sizeof(data->fb_id));
         |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


vim +/strncpy +261 drivers/video/backlight/pwm_bl.c

   240	
   241	static int pwm_backlight_parse_dt(struct device *dev,
   242					  struct platform_pwm_backlight_data *data)
   243	{
   244		struct device_node *node = dev->of_node;
   245		unsigned int num_levels = 0;
   246		unsigned int levels_count;
   247		unsigned int num_steps = 0;
   248		struct property *prop;
   249		unsigned int *table;
   250		int length;
   251		u32 value;
   252		int ret;
   253		const char *names;
   254	
   255		if (!node)
   256			return -ENODEV;
   257	
   258		memset(data, 0, sizeof(*data));
   259	
   260		if (!of_property_read_string(node, "fb-names", &names)) {
 > 261			strncpy(data->fb_id, names, sizeof(data->fb_id));
   262			data->check_fb = &pwm_backlight_check_fb_name;
   263		}
   264	
   265		/*
   266		 * These values are optional and set as 0 by default, the out values
   267		 * are modified only if a valid u32 value can be decoded.
   268		 */
   269		of_property_read_u32(node, "post-pwm-on-delay-ms",
   270				     &data->post_pwm_on_delay);
   271		of_property_read_u32(node, "pwm-off-delay-ms", &data->pwm_off_delay);
   272	
   273		/*
   274		 * Determine the number of brightness levels, if this property is not
   275		 * set a default table of brightness levels will be used.
   276		 */
   277		prop = of_find_property(node, "brightness-levels", &length);
   278		if (!prop)
   279			return 0;
   280	
   281		data->max_brightness = length / sizeof(u32);
   282	
   283		/* read brightness levels from DT property */
   284		if (data->max_brightness > 0) {
   285			size_t size = sizeof(*data->levels) * data->max_brightness;
   286			unsigned int i, j, n = 0;
   287	
   288			data->levels = devm_kzalloc(dev, size, GFP_KERNEL);
   289			if (!data->levels)
   290				return -ENOMEM;
   291	
   292			ret = of_property_read_u32_array(node, "brightness-levels",
   293							 data->levels,
   294							 data->max_brightness);
   295			if (ret < 0)
   296				return ret;
   297	
   298			ret = of_property_read_u32(node, "default-brightness-level",
   299						   &value);
   300			if (ret < 0)
   301				return ret;
   302	
   303			data->dft_brightness = value;
   304	
   305			/*
   306			 * This property is optional, if is set enables linear
   307			 * interpolation between each of the values of brightness levels
   308			 * and creates a new pre-computed table.
   309			 */
   310			of_property_read_u32(node, "num-interpolated-steps",
   311					     &num_steps);
   312	
   313			/*
   314			 * Make sure that there is at least two entries in the
   315			 * brightness-levels table, otherwise we can't interpolate
   316			 * between two points.
   317			 */
   318			if (num_steps) {
   319				if (data->max_brightness < 2) {
   320					dev_err(dev, "can't interpolate\n");
   321					return -EINVAL;
   322				}
   323	
   324				/*
   325				 * Recalculate the number of brightness levels, now
   326				 * taking in consideration the number of interpolated
   327				 * steps between two levels.
   328				 */
   329				for (i = 0; i < data->max_brightness - 1; i++) {
   330					if ((data->levels[i + 1] - data->levels[i]) /
   331					   num_steps)
   332						num_levels += num_steps;
   333					else
   334						num_levels++;
   335				}
   336				num_levels++;
   337				dev_dbg(dev, "new number of brightness levels: %d\n",
   338					num_levels);
   339	
   340				/*
   341				 * Create a new table of brightness levels with all the
   342				 * interpolated steps.
   343				 */
   344				size = sizeof(*table) * num_levels;
   345				table = devm_kzalloc(dev, size, GFP_KERNEL);
   346				if (!table)
   347					return -ENOMEM;
   348	
   349				/* Fill the interpolated table. */
   350				levels_count = 0;
   351				for (i = 0; i < data->max_brightness - 1; i++) {
   352					value = data->levels[i];
   353					n = (data->levels[i + 1] - value) / num_steps;
   354					if (n > 0) {
   355						for (j = 0; j < num_steps; j++) {
   356							table[levels_count] = value;
   357							value += n;
   358							levels_count++;
   359						}
   360					} else {
   361						table[levels_count] = data->levels[i];
   362						levels_count++;
   363					}
   364				}
   365				table[levels_count] = data->levels[i];
   366	
   367				/*
   368				 * As we use interpolation lets remove current
   369				 * brightness levels table and replace for the
   370				 * new interpolated table.
   371				 */
   372				devm_kfree(dev, data->levels);
   373				data->levels = table;
   374	
   375				/*
   376				 * Reassign max_brightness value to the new total number
   377				 * of brightness levels.
   378				 */
   379				data->max_brightness = num_levels;
   380			}
   381	
   382			data->max_brightness--;
   383		}
   384		return 0;
   385	}
   386	

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

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 31228 bytes --]

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-11-12 21:01 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-12 21:01 [freescale-fslc:5.10-2.1.x-imx 11497/15242] drivers/video/backlight/pwm_bl.c:261:17: warning: 'strncpy' specified bound 16 equals destination size kernel test robot

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.