From mboxrd@z Thu Jan 1 00:00:00 1970 Content-Type: multipart/mixed; boundary="===============6543071403118177112==" MIME-Version: 1.0 From: kernel test robot To: kbuild-all@lists.01.org Subject: [freescale-fslc:pr/511 5349/9999] drivers/video/backlight/pwm_bl.c:261:17: warning: 'strncpy' specified bound 16 equals destination size Date: Wed, 05 Jan 2022 05:50:48 +0800 Message-ID: <202201050515.cFaWkJle-lkp@intel.com> List-Id: --===============6543071403118177112== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Hi Sandor, FYI, the error/warning still remains. tree: https://github.com/Freescale/linux-fslc pr/511 head: 8ef27ae9f200b93f85da9dfd1d258ecaa86cf102 commit: 92123fc24af3d55dc3db2d862754fc2da1bccc8a [5349/9999] LF-3541: video= /backligh: fix Coverity Issue: 9551473 Copy into fixed size buffer config: nds32-buildonly-randconfig-r004-20220104 (https://download.01.org/0= day-ci/archive/20220105/202201050515.cFaWkJle-lkp(a)intel.com/config) compiler: nds32le-linux-gcc (GCC) 11.2.0 reproduce (this is a W=3D1 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/92123fc24af3d55dc3= db2d862754fc2da1bccc8a git remote add freescale-fslc https://github.com/Freescale/linux-fs= lc git fetch --no-tags freescale-fslc pr/511 git checkout 92123fc24af3d55dc3db2d862754fc2da1bccc8a # save the config file to linux build tree mkdir build_dir COMPILER_INSTALL_PATH=3D$HOME/0day COMPILER=3Dgcc-11.2.0 make.cross= O=3Dbuild_dir ARCH=3Dnds32 SHELL=3D/bin/bash drivers/video/backlight/ If you fix the issue, kindly add following tag as appropriate Reported-by: kernel test robot 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 bo= und 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 =3D dev->of_node; 245 unsigned int num_levels =3D 0; 246 unsigned int levels_count; 247 unsigned int num_steps =3D 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 =3D &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 n= ot 275 * set a default table of brightness levels will be used. 276 */ 277 prop =3D of_find_property(node, "brightness-levels", &length); 278 if (!prop) 279 return 0; 280 = 281 data->max_brightness =3D length / sizeof(u32); 282 = 283 /* read brightness levels from DT property */ 284 if (data->max_brightness > 0) { 285 size_t size =3D sizeof(*data->levels) * data->max_brightness; 286 unsigned int i, j, n =3D 0; 287 = 288 data->levels =3D devm_kzalloc(dev, size, GFP_KERNEL); 289 if (!data->levels) 290 return -ENOMEM; 291 = 292 ret =3D 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 =3D of_property_read_u32(node, "default-brightness-level", 299 &value); 300 if (ret < 0) 301 return ret; 302 = 303 data->dft_brightness =3D 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 =3D 0; i < data->max_brightness - 1; i++) { 330 if ((data->levels[i + 1] - data->levels[i]) / 331 num_steps) 332 num_levels +=3D 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 =3D sizeof(*table) * num_levels; 345 table =3D devm_kzalloc(dev, size, GFP_KERNEL); 346 if (!table) 347 return -ENOMEM; 348 = 349 /* Fill the interpolated table. */ 350 levels_count =3D 0; 351 for (i =3D 0; i < data->max_brightness - 1; i++) { 352 value =3D data->levels[i]; 353 n =3D (data->levels[i + 1] - value) / num_steps; 354 if (n > 0) { 355 for (j =3D 0; j < num_steps; j++) { 356 table[levels_count] =3D value; 357 value +=3D n; 358 levels_count++; 359 } 360 } else { 361 table[levels_count] =3D data->levels[i]; 362 levels_count++; 363 } 364 } 365 table[levels_count] =3D 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 =3D table; 374 = 375 /* 376 * Reassign max_brightness value to the new total number 377 * of brightness levels. 378 */ 379 data->max_brightness =3D 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 --===============6543071403118177112==--