drivers/block/rnbd/rnbd-clt.c:1460 init_dev() error: Calling ida_alloc_max() with a 'max' argument which is a power of 2. -1 missing?
From: Dan Carpenter
Date: Thu Dec 29 2022 - 04:04:01 EST
tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: 1b929c02afd37871d5afb9d498426f83432e71c2
commit: 24afc15dbe218f860994f627b4ba1fb09225a298 block/rnbd: Remove a useless mutex
config: powerpc-randconfig-m031-20221226
compiler: powerpc-linux-gcc (GCC) 12.1.0
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@xxxxxxxxx>
| Reported-by: Dan Carpenter <error27@xxxxxxxxx>
smatch warnings:
drivers/block/rnbd/rnbd-clt.c:1460 init_dev() error: Calling ida_alloc_max() with a 'max' argument which is a power of 2. -1 missing?
vim +/max +1460 drivers/block/rnbd/rnbd-clt.c
f7a7a5c228d45e Jack Wang 2020-05-11 1436 static struct rnbd_clt_dev *init_dev(struct rnbd_clt_session *sess,
f7a7a5c228d45e Jack Wang 2020-05-11 1437 enum rnbd_access_mode access_mode,
2958a995edc946 Gioh Kim 2021-04-19 1438 const char *pathname,
2958a995edc946 Gioh Kim 2021-04-19 1439 u32 nr_poll_queues)
f7a7a5c228d45e Jack Wang 2020-05-11 1440 {
f7a7a5c228d45e Jack Wang 2020-05-11 1441 struct rnbd_clt_dev *dev;
f7a7a5c228d45e Jack Wang 2020-05-11 1442 int ret;
f7a7a5c228d45e Jack Wang 2020-05-11 1443
f7a7a5c228d45e Jack Wang 2020-05-11 1444 dev = kzalloc_node(sizeof(*dev), GFP_KERNEL, NUMA_NO_NODE);
f7a7a5c228d45e Jack Wang 2020-05-11 1445 if (!dev)
f7a7a5c228d45e Jack Wang 2020-05-11 1446 return ERR_PTR(-ENOMEM);
f7a7a5c228d45e Jack Wang 2020-05-11 1447
2958a995edc946 Gioh Kim 2021-04-19 1448 /*
2958a995edc946 Gioh Kim 2021-04-19 1449 * nr_cpu_ids: the number of softirq queues
2958a995edc946 Gioh Kim 2021-04-19 1450 * nr_poll_queues: the number of polling queues
2958a995edc946 Gioh Kim 2021-04-19 1451 */
2958a995edc946 Gioh Kim 2021-04-19 1452 dev->hw_queues = kcalloc(nr_cpu_ids + nr_poll_queues,
2958a995edc946 Gioh Kim 2021-04-19 1453 sizeof(*dev->hw_queues),
f7a7a5c228d45e Jack Wang 2020-05-11 1454 GFP_KERNEL);
f7a7a5c228d45e Jack Wang 2020-05-11 1455 if (!dev->hw_queues) {
f7a7a5c228d45e Jack Wang 2020-05-11 1456 ret = -ENOMEM;
f7a7a5c228d45e Jack Wang 2020-05-11 1457 goto out_alloc;
f7a7a5c228d45e Jack Wang 2020-05-11 1458 }
f7a7a5c228d45e Jack Wang 2020-05-11 1459
24afc15dbe218f Christophe JAILLET 2022-02-07 @1460 ret = ida_alloc_max(&index_ida, 1 << (MINORBITS - RNBD_PART_BITS),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
You wrote this Smatch check... But, this should probably be
(1 << (MINORBITS - RNBD_PART_BITS)) - 1, yeah?
f7a7a5c228d45e Jack Wang 2020-05-11 1461 GFP_KERNEL);
f7a7a5c228d45e Jack Wang 2020-05-11 1462 if (ret < 0) {
f7a7a5c228d45e Jack Wang 2020-05-11 1463 pr_err("Failed to initialize device '%s' from session %s, allocating idr failed, err: %d\n",
f7a7a5c228d45e Jack Wang 2020-05-11 1464 pathname, sess->sessname, ret);
f7a7a5c228d45e Jack Wang 2020-05-11 1465 goto out_queues;
f7a7a5c228d45e Jack Wang 2020-05-11 1466 }
64e8a6ece1a5b1 Md Haris Iqbal 2020-11-26 1467
e7508d48565060 Md Haris Iqbal 2020-12-10 1468 dev->pathname = kstrdup(pathname, GFP_KERNEL);
64e8a6ece1a5b1 Md Haris Iqbal 2020-11-26 1469 if (!dev->pathname) {
64e8a6ece1a5b1 Md Haris Iqbal 2020-11-26 1470 ret = -ENOMEM;
64e8a6ece1a5b1 Md Haris Iqbal 2020-11-26 1471 goto out_queues;
64e8a6ece1a5b1 Md Haris Iqbal 2020-11-26 1472 }
64e8a6ece1a5b1 Md Haris Iqbal 2020-11-26 1473
f7a7a5c228d45e Jack Wang 2020-05-11 1474 dev->clt_device_id = ret;
f7a7a5c228d45e Jack Wang 2020-05-11 1475 dev->sess = sess;
f7a7a5c228d45e Jack Wang 2020-05-11 1476 dev->access_mode = access_mode;
2958a995edc946 Gioh Kim 2021-04-19 1477 dev->nr_poll_queues = nr_poll_queues;
f7a7a5c228d45e Jack Wang 2020-05-11 1478 mutex_init(&dev->lock);
f7a7a5c228d45e Jack Wang 2020-05-11 1479 refcount_set(&dev->refcount, 1);
f7a7a5c228d45e Jack Wang 2020-05-11 1480 dev->dev_state = DEV_STATE_INIT;
f7a7a5c228d45e Jack Wang 2020-05-11 1481
f7a7a5c228d45e Jack Wang 2020-05-11 1482 /*
f7a7a5c228d45e Jack Wang 2020-05-11 1483 * Here we called from sysfs entry, thus clt-sysfs is
f7a7a5c228d45e Jack Wang 2020-05-11 1484 * responsible that session will not disappear.
f7a7a5c228d45e Jack Wang 2020-05-11 1485 */
f7a7a5c228d45e Jack Wang 2020-05-11 1486 WARN_ON(!rnbd_clt_get_sess(sess));
f7a7a5c228d45e Jack Wang 2020-05-11 1487
f7a7a5c228d45e Jack Wang 2020-05-11 1488 return dev;
f7a7a5c228d45e Jack Wang 2020-05-11 1489
f7a7a5c228d45e Jack Wang 2020-05-11 1490 out_queues:
f7a7a5c228d45e Jack Wang 2020-05-11 1491 kfree(dev->hw_queues);
f7a7a5c228d45e Jack Wang 2020-05-11 1492 out_alloc:
f7a7a5c228d45e Jack Wang 2020-05-11 1493 kfree(dev);
f7a7a5c228d45e Jack Wang 2020-05-11 1494 return ERR_PTR(ret);
f7a7a5c228d45e Jack Wang 2020-05-11 1495 }
--
0-DAY CI Kernel Test Service
https://01.org/lkp