Re: [PATCH 2/2] nvmem: core: Expose cells through sysfs

Dan Carpenter
2023-05-29T04:52:15Z

Hi Miquel,

kernel test robot noticed the following build warnings:

https://git-scm.com/docs/git-format-patch#_base_tree_information]

url: https://github.com/intel-lab-lkp/linux/commits/Miquel-Raynal/ABI-sysfs-nvmem-cells-Expose-cells-through-sysfs/20230523-203042
base: char-misc/char-misc-testing
patch link: https://lore.kernel.org/r/20230523100239.307574-3-miquel.raynal%40bootlin.com
patch subject: [PATCH 2/2] nvmem: core: Expose cells through sysfs
config: i386-randconfig-m021-20230525 (https://download.01.org/0day-ci/archive/20230528/202305280054.NloN5RLk-lkp@intel.com/config)
compiler: gcc-11 (Debian 11.3.0-12) 11.3.0

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>
| Reported-by: Dan Carpenter <error27@gmail.com>
| Closes: https://lore.kernel.org/r/202305280054.NloN5RLk-lkp@intel.com/

smatch warnings:
drivers/nvmem/core.c:380 nvmem_cell_attr_read() error: uninitialized symbol 'read_len'.

vim +/read_len +380 drivers/nvmem/core.c

22c370b2163e59 Miquel Raynal 2023-05-23 328 static struct nvmem_cell *nvmem_create_cell(struct nvmem_cell_entry *entry,
22c370b2163e59 Miquel Raynal 2023-05-23 329 const char *id, int index);
22c370b2163e59 Miquel Raynal 2023-05-23 330
22c370b2163e59 Miquel Raynal 2023-05-23 331 static ssize_t nvmem_cell_attr_read(struct file *filp, struct kobject *kobj,
22c370b2163e59 Miquel Raynal 2023-05-23 332 struct bin_attribute *attr, char *buf,
22c370b2163e59 Miquel Raynal 2023-05-23 333 loff_t pos, size_t count)
22c370b2163e59 Miquel Raynal 2023-05-23 334 {
22c370b2163e59 Miquel Raynal 2023-05-23 335 struct nvmem_cell_entry *entry;
22c370b2163e59 Miquel Raynal 2023-05-23 336 struct nvmem_cell *cell = NULL;
22c370b2163e59 Miquel Raynal 2023-05-23 337 struct nvmem_device *nvmem;
22c370b2163e59 Miquel Raynal 2023-05-23 338 size_t cell_sz, read_len;
22c370b2163e59 Miquel Raynal 2023-05-23 339 struct device *dev;
22c370b2163e59 Miquel Raynal 2023-05-23 340 void *content;
22c370b2163e59 Miquel Raynal 2023-05-23 341
22c370b2163e59 Miquel Raynal 2023-05-23 342 if (attr->private)
22c370b2163e59 Miquel Raynal 2023-05-23 343 dev = attr->private;
22c370b2163e59 Miquel Raynal 2023-05-23 344 else
22c370b2163e59 Miquel Raynal 2023-05-23 345 dev = kobj_to_dev(kobj);
22c370b2163e59 Miquel Raynal 2023-05-23 346 nvmem = to_nvmem_device(dev);
22c370b2163e59 Miquel Raynal 2023-05-23 347
22c370b2163e59 Miquel Raynal 2023-05-23 348 mutex_lock(&nvmem_mutex);
22c370b2163e59 Miquel Raynal 2023-05-23 349 list_for_each_entry(entry, &nvmem->cells, node) {
22c370b2163e59 Miquel Raynal 2023-05-23 350 if (strncmp(entry->name, attr->attr.name, XATTR_NAME_MAX))
22c370b2163e59 Miquel Raynal 2023-05-23 351 continue;
22c370b2163e59 Miquel Raynal 2023-05-23 352
22c370b2163e59 Miquel Raynal 2023-05-23 353 cell = nvmem_create_cell(entry, entry->name, 0);
22c370b2163e59 Miquel Raynal 2023-05-23 354 if (IS_ERR(cell)) {
22c370b2163e59 Miquel Raynal 2023-05-23 355 mutex_unlock(&nvmem_mutex);
22c370b2163e59 Miquel Raynal 2023-05-23 356 return PTR_ERR(cell);
22c370b2163e59 Miquel Raynal 2023-05-23 357 }
22c370b2163e59 Miquel Raynal 2023-05-23 358
22c370b2163e59 Miquel Raynal 2023-05-23 359 break;
22c370b2163e59 Miquel Raynal 2023-05-23 360 }
22c370b2163e59 Miquel Raynal 2023-05-23 361 mutex_unlock(&nvmem_mutex);
22c370b2163e59 Miquel Raynal 2023-05-23 362
22c370b2163e59 Miquel Raynal 2023-05-23 363 if (!cell)
22c370b2163e59 Miquel Raynal 2023-05-23 364 return -EINVAL;
22c370b2163e59 Miquel Raynal 2023-05-23 365
22c370b2163e59 Miquel Raynal 2023-05-23 366 content = nvmem_cell_read(cell, &cell_sz);
22c370b2163e59 Miquel Raynal 2023-05-23 367 if (IS_ERR(content)) {
22c370b2163e59 Miquel Raynal 2023-05-23 368 count = PTR_ERR(content);
22c370b2163e59 Miquel Raynal 2023-05-23 369 goto destroy_cell;

read_len not initialized on this goto path.

22c370b2163e59 Miquel Raynal 2023-05-23 370 }
22c370b2163e59 Miquel Raynal 2023-05-23 371
22c370b2163e59 Miquel Raynal 2023-05-23 372 read_len = min_t(unsigned int, cell_sz - pos, count);
22c370b2163e59 Miquel Raynal 2023-05-23 373 memcpy(buf, content + pos, read_len);
22c370b2163e59 Miquel Raynal 2023-05-23 374 kfree(content);
22c370b2163e59 Miquel Raynal 2023-05-23 375
22c370b2163e59 Miquel Raynal 2023-05-23 376 destroy_cell:
22c370b2163e59 Miquel Raynal 2023-05-23 377 kfree_const(cell->id);
22c370b2163e59 Miquel Raynal 2023-05-23 378 kfree(cell);
22c370b2163e59 Miquel Raynal 2023-05-23 379
22c370b2163e59 Miquel Raynal 2023-05-23 @380 return read_len;
^^^^^^^^^^^^^^^

22c370b2163e59 Miquel Raynal 2023-05-23 381 }

--
0-DAY CI Kernel Test Service