Skip to contentSkip to conversation

drivers/misc/dlb2/dlb2_main.c:200 dlb2_add_domain_device_file() warn: passing zero to 'PTR_ERR'

PATCH New Dan Carpenter 1 participant 1 message Jun 19, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 7691/9999 drivers/misc/dlb2/dlb2_main.c:200 dlb2_add_domain_device_file() warn: passing zero to 'PTR_ERR'

tree:   https://github.com/changbae/Linux-kernel adl-po-presilicon
head:   6173b90dca1633db3ad2ddb01b0825969c0aa8e3
commit: 1d6b51b4af4c2b7e3ae9837d3dc076e99bd8ad92 [7691/9999] dlb2: driver for Intel Dynamic Load Balancer 2.0
config: x86_64-randconfig-m001-20200619 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-13) 9.3.0

If you fix the issue, kindly add following tag as appropriate

New smatch warnings:
drivers/misc/dlb2/dlb2_main.c:200 dlb2_add_domain_device_file() warn: passing zero to 'PTR_ERR' drivers/misc/dlb2/dlb2_main.c:1643 dlb2_init_module() warn: passing zero to 'PTR_ERR' drivers/misc/dlb2/dlb2_pf_ops.c:1743 dlb2_pf_device_create() warn: passing zero to 'PTR_ERR' drivers/misc/dlb2/dlb2_vf_ops.c:1064 dlb2_vf_device_create() warn: passing zero to 'PTR_ERR' drivers/misc/dlb2/base/dlb2_resource.c:9097 dlb2_hw_enable_wd_timer() error: buffer overflow 'wd_config' 3 <= 3 drivers/misc/dlb2/dlb2_dp.c:189 dlb2_open() error: we previously assumed 'dev' could be null (see line 160)

# https://github.com/changbae/Linux-kernel/commit/1d6b51b4af4c2b7e3ae9837d3dc076e99bd8ad92
git remote add fsgsbase https://github.com/changbae/Linux-kernel
git remote update fsgsbase
git checkout 1d6b51b4af4c2b7e3ae9837d3dc076e99bd8ad92
vim +/PTR_ERR +200 drivers/misc/dlb2/dlb2_main.c

1d6b51b4af4c2b7 Gage Eads 2020-04-27  170  int dlb2_add_domain_device_file(struct dlb2_dev *dlb2_dev, u32 domain_id)
1d6b51b4af4c2b7 Gage Eads 2020-04-27  171  {
1d6b51b4af4c2b7 Gage Eads 2020-04-27  172  	struct dlb2_status *status;
1d6b51b4af4c2b7 Gage Eads 2020-04-27  173  	struct device *dev;
1d6b51b4af4c2b7 Gage Eads 2020-04-27  174  
1d6b51b4af4c2b7 Gage Eads 2020-04-27  175  	dev_dbg(dlb2_dev->dlb2_device,
1d6b51b4af4c2b7 Gage Eads 2020-04-27  176  		"Creating domain %d's device file\n", domain_id);
1d6b51b4af4c2b7 Gage Eads 2020-04-27  177  
1d6b51b4af4c2b7 Gage Eads 2020-04-27  178  	status = devm_kzalloc(dlb2_dev->dlb2_device,
1d6b51b4af4c2b7 Gage Eads 2020-04-27  179  			      sizeof(*status),
1d6b51b4af4c2b7 Gage Eads 2020-04-27  180  			      GFP_KERNEL);
1d6b51b4af4c2b7 Gage Eads 2020-04-27  181  	if (!status)
1d6b51b4af4c2b7 Gage Eads 2020-04-27  182  		return -ENOMEM;
1d6b51b4af4c2b7 Gage Eads 2020-04-27  183  
1d6b51b4af4c2b7 Gage Eads 2020-04-27  184  	status->valid = true;
1d6b51b4af4c2b7 Gage Eads 2020-04-27  185  	status->refcnt = 0;
1d6b51b4af4c2b7 Gage Eads 2020-04-27  186  
1d6b51b4af4c2b7 Gage Eads 2020-04-27  187  	/* Create a new device in order to create a /dev/ domain node. This
1d6b51b4af4c2b7 Gage Eads 2020-04-27  188  	 * device is a child of the DLB PCI device.
1d6b51b4af4c2b7 Gage Eads 2020-04-27  189  	 */
1d6b51b4af4c2b7 Gage Eads 2020-04-27  190  	dev = device_create(dlb2_class,
1d6b51b4af4c2b7 Gage Eads 2020-04-27  191  			    dlb2_dev->dlb2_device->parent,
1d6b51b4af4c2b7 Gage Eads 2020-04-27  192  			    MKDEV(MAJOR(dlb2_dev->dev_number),
1d6b51b4af4c2b7 Gage Eads 2020-04-27  193  				  MINOR(dlb2_dev->dev_number) + domain_id),
1d6b51b4af4c2b7 Gage Eads 2020-04-27  194  			    dlb2_dev,
1d6b51b4af4c2b7 Gage Eads 2020-04-27  195  			    "dlb%d/domain%d",
1d6b51b4af4c2b7 Gage Eads 2020-04-27  196  			    DLB2_DEV_ID_FROM_DEV_T(dlb2_dev_number_base,
1d6b51b4af4c2b7 Gage Eads 2020-04-27  197  						   dlb2_dev->dev_number),
1d6b51b4af4c2b7 Gage Eads 2020-04-27  198  			    domain_id);
1d6b51b4af4c2b7 Gage Eads 2020-04-27  199  

1d6b51b4af4c2b7 Gage Eads 2020-04-27 @200 if (IS_ERR_VALUE(PTR_ERR(dev))) {

Smatch doesn't like this formation at all. :P It works but I have never seen it before. Just say:

	if (IS_ERR(dev)) {
1d6b51b4af4c2b7 Gage Eads 2020-04-27  201  		dev_err(dlb2_dev->dlb2_device,
1d6b51b4af4c2b7 Gage Eads 2020-04-27  202  			"%s: device_create() returned %ld\n",
1d6b51b4af4c2b7 Gage Eads 2020-04-27  203  			dlb2_driver_name, PTR_ERR(dev));
1d6b51b4af4c2b7 Gage Eads 2020-04-27  204  
1d6b51b4af4c2b7 Gage Eads 2020-04-27  205  		devm_kfree(dlb2_dev->dlb2_device, status);
1d6b51b4af4c2b7 Gage Eads 2020-04-27  206  		return PTR_ERR(dev);
1d6b51b4af4c2b7 Gage Eads 2020-04-27  207  	}
1d6b51b4af4c2b7 Gage Eads 2020-04-27  208  
1d6b51b4af4c2b7 Gage Eads 2020-04-27  209  	dlb2_dev->sched_domains[domain_id].status = status;
1d6b51b4af4c2b7 Gage Eads 2020-04-27  210  
1d6b51b4af4c2b7 Gage Eads 2020-04-27  211  	return 0;
1d6b51b4af4c2b7 Gage Eads 2020-04-27  212  }

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