[mcgrof-next:20211011-for-axboe-add-disk-error-handling 24/24] block/genhd.c:480 device_add_disk() warn: missing error code 'ret'
From: Dan Carpenter
Date: Wed Nov 03 2021 - 10:00:49 EST
tree: https://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux-next.git 20211011-for-axboe-add-disk-error-handling
head: 53099761729ca16d3bb36db8a8cc526f4eb08f28
commit: 53099761729ca16d3bb36db8a8cc526f4eb08f28 [24/24] block: add __must_check for *add_disk*() callers
config: i386-randconfig-m021-20211019 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@xxxxxxxxx>
Reported-by: Dan Carpenter <dan.carpenter@xxxxxxxxxx>
smatch warnings:
block/genhd.c:480 device_add_disk() warn: missing error code 'ret'
vim +/ret +480 block/genhd.c
53099761729ca1 block/genhd.c Luis Chamberlain 2021-07-15 398 int __must_check device_add_disk(struct device *parent, struct gendisk *disk,
d1254a8749711e block/genhd.c Christoph Hellwig 2021-08-04 399 const struct attribute_group **groups)
d1254a8749711e block/genhd.c Christoph Hellwig 2021-08-04 400
^1da177e4c3f41 drivers/block/genhd.c Linus Torvalds 2005-04-16 401 {
52b85909f85d06 block/genhd.c Christoph Hellwig 2021-08-18 402 struct device *ddev = disk_to_dev(disk);
7c3f828b522b07 block/genhd.c Christoph Hellwig 2021-05-21 403 int ret;
cf0ca9fe5dd9e3 block/genhd.c Peter Zijlstra 2008-04-30 404
737eb78e82d52d block/genhd.c Damien Le Moal 2019-09-05 405 /*
737eb78e82d52d block/genhd.c Damien Le Moal 2019-09-05 406 * The disk queue should now be all set with enough information about
737eb78e82d52d block/genhd.c Damien Le Moal 2019-09-05 407 * the device for the elevator code to pick an adequate default
737eb78e82d52d block/genhd.c Damien Le Moal 2019-09-05 408 * elevator if one is needed, that is, for devices requesting queue
737eb78e82d52d block/genhd.c Damien Le Moal 2019-09-05 409 * registration.
737eb78e82d52d block/genhd.c Damien Le Moal 2019-09-05 410 */
737eb78e82d52d block/genhd.c Damien Le Moal 2019-09-05 411 elevator_init_mq(disk->queue);
737eb78e82d52d block/genhd.c Damien Le Moal 2019-09-05 412
7c3f828b522b07 block/genhd.c Christoph Hellwig 2021-05-21 413 /*
7c3f828b522b07 block/genhd.c Christoph Hellwig 2021-05-21 414 * If the driver provides an explicit major number it also must provide
7c3f828b522b07 block/genhd.c Christoph Hellwig 2021-05-21 415 * the number of minors numbers supported, and those will be used to
7c3f828b522b07 block/genhd.c Christoph Hellwig 2021-05-21 416 * setup the gendisk.
7c3f828b522b07 block/genhd.c Christoph Hellwig 2021-05-21 417 * Otherwise just allocate the device numbers for both the whole device
7c3f828b522b07 block/genhd.c Christoph Hellwig 2021-05-21 418 * and all partitions from the extended dev_t space.
3e1a7ff8a0a7b9 block/genhd.c Tejun Heo 2008-08-25 419 */
7c3f828b522b07 block/genhd.c Christoph Hellwig 2021-05-21 420 if (disk->major) {
83cbce9574462c block/genhd.c Luis Chamberlain 2021-08-18 421 if (WARN_ON(!disk->minors))
83cbce9574462c block/genhd.c Luis Chamberlain 2021-08-18 422 return -EINVAL;
2e3c73fa0c419f block/genhd.c Christoph Hellwig 2021-05-21 423
2e3c73fa0c419f block/genhd.c Christoph Hellwig 2021-05-21 424 if (disk->minors > DISK_MAX_PARTS) {
2e3c73fa0c419f block/genhd.c Christoph Hellwig 2021-05-21 425 pr_err("block: can't allocate more than %d partitions\n",
2e3c73fa0c419f block/genhd.c Christoph Hellwig 2021-05-21 426 DISK_MAX_PARTS);
2e3c73fa0c419f block/genhd.c Christoph Hellwig 2021-05-21 427 disk->minors = DISK_MAX_PARTS;
2e3c73fa0c419f block/genhd.c Christoph Hellwig 2021-05-21 428 }
7c3f828b522b07 block/genhd.c Christoph Hellwig 2021-05-21 429 } else {
83cbce9574462c block/genhd.c Luis Chamberlain 2021-08-18 430 if (WARN_ON(disk->minors))
83cbce9574462c block/genhd.c Luis Chamberlain 2021-08-18 431 return -EINVAL;
3e1a7ff8a0a7b9 block/genhd.c Tejun Heo 2008-08-25 432
7c3f828b522b07 block/genhd.c Christoph Hellwig 2021-05-21 433 ret = blk_alloc_ext_minor();
83cbce9574462c block/genhd.c Luis Chamberlain 2021-08-18 434 if (ret < 0)
83cbce9574462c block/genhd.c Luis Chamberlain 2021-08-18 435 return ret;
7c3f828b522b07 block/genhd.c Christoph Hellwig 2021-05-21 436 disk->major = BLOCK_EXT_MAJOR;
539711d7d6fe38 block/genhd.c Christoph Hellwig 2021-08-24 437 disk->first_minor = ret;
0d1feb72ffd857 block/genhd.c Christoph Hellwig 2021-05-21 438 disk->flags |= GENHD_FL_EXT_DEVT;
7c3f828b522b07 block/genhd.c Christoph Hellwig 2021-05-21 439 }
7c3f828b522b07 block/genhd.c Christoph Hellwig 2021-05-21 440
83cbce9574462c block/genhd.c Luis Chamberlain 2021-08-18 441 ret = disk_alloc_events(disk);
83cbce9574462c block/genhd.c Luis Chamberlain 2021-08-18 442 if (ret)
83cbce9574462c block/genhd.c Luis Chamberlain 2021-08-18 443 goto out_free_ext_minor;
9f53d2fe815b40 block/genhd.c Stanislaw Gruszka 2012-03-02 444
52b85909f85d06 block/genhd.c Christoph Hellwig 2021-08-18 445 /* delay uevents, until we scanned partition table */
52b85909f85d06 block/genhd.c Christoph Hellwig 2021-08-18 446 dev_set_uevent_suppress(ddev, 1);
52b85909f85d06 block/genhd.c Christoph Hellwig 2021-08-18 447
52b85909f85d06 block/genhd.c Christoph Hellwig 2021-08-18 448 ddev->parent = parent;
52b85909f85d06 block/genhd.c Christoph Hellwig 2021-08-18 449 ddev->groups = groups;
52b85909f85d06 block/genhd.c Christoph Hellwig 2021-08-18 450 dev_set_name(ddev, "%s", disk->disk_name);
8235b5c1e8c1c0 block/genhd.c Christoph Hellwig 2021-08-18 451 if (!(disk->flags & GENHD_FL_HIDDEN))
8235b5c1e8c1c0 block/genhd.c Christoph Hellwig 2021-08-18 452 ddev->devt = MKDEV(disk->major, disk->first_minor);
83cbce9574462c block/genhd.c Luis Chamberlain 2021-08-18 453 ret = device_add(ddev);
83cbce9574462c block/genhd.c Luis Chamberlain 2021-08-18 454 if (ret)
83cbce9574462c block/genhd.c Luis Chamberlain 2021-08-18 455 goto out_disk_release_events;
52b85909f85d06 block/genhd.c Christoph Hellwig 2021-08-18 456 if (!sysfs_deprecated) {
52b85909f85d06 block/genhd.c Christoph Hellwig 2021-08-18 457 ret = sysfs_create_link(block_depr, &ddev->kobj,
52b85909f85d06 block/genhd.c Christoph Hellwig 2021-08-18 458 kobject_name(&ddev->kobj));
83cbce9574462c block/genhd.c Luis Chamberlain 2021-08-18 459 if (ret)
83cbce9574462c block/genhd.c Luis Chamberlain 2021-08-18 460 goto out_device_del;
52b85909f85d06 block/genhd.c Christoph Hellwig 2021-08-18 461 }
52b85909f85d06 block/genhd.c Christoph Hellwig 2021-08-18 462
52b85909f85d06 block/genhd.c Christoph Hellwig 2021-08-18 463 /*
52b85909f85d06 block/genhd.c Christoph Hellwig 2021-08-18 464 * avoid probable deadlock caused by allocating memory with
52b85909f85d06 block/genhd.c Christoph Hellwig 2021-08-18 465 * GFP_KERNEL in runtime_resume callback of its all ancestor
52b85909f85d06 block/genhd.c Christoph Hellwig 2021-08-18 466 * devices
52b85909f85d06 block/genhd.c Christoph Hellwig 2021-08-18 467 */
52b85909f85d06 block/genhd.c Christoph Hellwig 2021-08-18 468 pm_runtime_set_memalloc_noio(ddev, true);
52b85909f85d06 block/genhd.c Christoph Hellwig 2021-08-18 469
83cbce9574462c block/genhd.c Luis Chamberlain 2021-08-18 470 ret = blk_integrity_add(disk);
83cbce9574462c block/genhd.c Luis Chamberlain 2021-08-18 471 if (ret)
83cbce9574462c block/genhd.c Luis Chamberlain 2021-08-18 472 goto out_del_block_link;
bab53f6b617d9f block/genhd.c Christoph Hellwig 2021-08-18 473
52b85909f85d06 block/genhd.c Christoph Hellwig 2021-08-18 474 disk->part0->bd_holder_dir =
52b85909f85d06 block/genhd.c Christoph Hellwig 2021-08-18 475 kobject_create_and_add("holders", &ddev->kobj);
83cbce9574462c block/genhd.c Luis Chamberlain 2021-08-18 476 if (!disk->part0->bd_holder_dir)
83cbce9574462c block/genhd.c Luis Chamberlain 2021-08-18 477 goto out_del_integrity;
52b85909f85d06 block/genhd.c Christoph Hellwig 2021-08-18 478 disk->slave_dir = kobject_create_and_add("slaves", &ddev->kobj);
83cbce9574462c block/genhd.c Luis Chamberlain 2021-08-18 479 if (!disk->slave_dir)
83cbce9574462c block/genhd.c Luis Chamberlain 2021-08-18 @480 goto out_put_holder_dir;
^^^^^^^^^^^^^^^^^^^^^^^^
This needs a "ret = -ENOMEM;"
52b85909f85d06 block/genhd.c Christoph Hellwig 2021-08-18 481
83cbce9574462c block/genhd.c Luis Chamberlain 2021-08-18 482 ret = bd_register_pending_holders(disk);
83cbce9574462c block/genhd.c Luis Chamberlain 2021-08-18 483 if (ret < 0)
83cbce9574462c block/genhd.c Luis Chamberlain 2021-08-18 484 goto out_put_slave_dir;
52b85909f85d06 block/genhd.c Christoph Hellwig 2021-08-18 485
83cbce9574462c block/genhd.c Luis Chamberlain 2021-08-18 486 ret = blk_register_queue(disk);
83cbce9574462c block/genhd.c Luis Chamberlain 2021-08-18 487 if (ret)
83cbce9574462c block/genhd.c Luis Chamberlain 2021-08-18 488 goto out_put_slave_dir;
75f4dca59694df block/genhd.c Christoph Hellwig 2021-08-18 489
8235b5c1e8c1c0 block/genhd.c Christoph Hellwig 2021-08-18 490 if (disk->flags & GENHD_FL_HIDDEN) {
8235b5c1e8c1c0 block/genhd.c Christoph Hellwig 2021-08-18 491 /*
8235b5c1e8c1c0 block/genhd.c Christoph Hellwig 2021-08-18 492 * Don't let hidden disks show up in /proc/partitions,
8235b5c1e8c1c0 block/genhd.c Christoph Hellwig 2021-08-18 493 * and don't bother scanning for partitions either.
8235b5c1e8c1c0 block/genhd.c Christoph Hellwig 2021-08-18 494 */
8235b5c1e8c1c0 block/genhd.c Christoph Hellwig 2021-08-18 495 disk->flags |= GENHD_FL_SUPPRESS_PARTITION_INFO;
8235b5c1e8c1c0 block/genhd.c Christoph Hellwig 2021-08-18 496 disk->flags |= GENHD_FL_NO_PART_SCAN;
8235b5c1e8c1c0 block/genhd.c Christoph Hellwig 2021-08-18 497 } else {
8235b5c1e8c1c0 block/genhd.c Christoph Hellwig 2021-08-18 498 ret = bdi_register(disk->bdi, "%u:%u",
8235b5c1e8c1c0 block/genhd.c Christoph Hellwig 2021-08-18 499 disk->major, disk->first_minor);
83cbce9574462c block/genhd.c Luis Chamberlain 2021-08-18 500 if (ret)
83cbce9574462c block/genhd.c Luis Chamberlain 2021-08-18 501 goto out_unregister_queue;
8235b5c1e8c1c0 block/genhd.c Christoph Hellwig 2021-08-18 502 bdi_set_owner(disk->bdi, ddev);
9d5ee6767c8576 block/genhd.c Christoph Hellwig 2021-08-18 503 ret = sysfs_create_link(&ddev->kobj,
9d5ee6767c8576 block/genhd.c Christoph Hellwig 2021-08-18 504 &disk->bdi->dev->kobj, "bdi");
83cbce9574462c block/genhd.c Luis Chamberlain 2021-08-18 505 if (ret)
83cbce9574462c block/genhd.c Luis Chamberlain 2021-08-18 506 goto out_unregister_bdi;
8235b5c1e8c1c0 block/genhd.c Christoph Hellwig 2021-08-18 507
9d5ee6767c8576 block/genhd.c Christoph Hellwig 2021-08-18 508 bdev_add(disk->part0, ddev->devt);
52b85909f85d06 block/genhd.c Christoph Hellwig 2021-08-18 509 disk_scan_partitions(disk);
52b85909f85d06 block/genhd.c Christoph Hellwig 2021-08-18 510
52b85909f85d06 block/genhd.c Christoph Hellwig 2021-08-18 511 /*
52b85909f85d06 block/genhd.c Christoph Hellwig 2021-08-18 512 * Announce the disk and partitions after all partitions are
8235b5c1e8c1c0 block/genhd.c Christoph Hellwig 2021-08-18 513 * created. (for hidden disks uevents remain suppressed forever)
52b85909f85d06 block/genhd.c Christoph Hellwig 2021-08-18 514 */
52b85909f85d06 block/genhd.c Christoph Hellwig 2021-08-18 515 dev_set_uevent_suppress(ddev, 0);
52b85909f85d06 block/genhd.c Christoph Hellwig 2021-08-18 516 disk_uevent(disk, KOBJ_ADD);
8ddcd653257c18 block/genhd.c Christoph Hellwig 2017-11-02 517 }
52b85909f85d06 block/genhd.c Christoph Hellwig 2021-08-18 518
75f4dca59694df block/genhd.c Christoph Hellwig 2021-08-18 519 disk_update_readahead(disk);
77ea887e433ad8 block/genhd.c Tejun Heo 2010-12-08 520 disk_add_events(disk);
83cbce9574462c block/genhd.c Luis Chamberlain 2021-08-18 521 return 0;
83cbce9574462c block/genhd.c Luis Chamberlain 2021-08-18 522
83cbce9574462c block/genhd.c Luis Chamberlain 2021-08-18 523 out_unregister_bdi:
83cbce9574462c block/genhd.c Luis Chamberlain 2021-08-18 524 if (!(disk->flags & GENHD_FL_HIDDEN))
83cbce9574462c block/genhd.c Luis Chamberlain 2021-08-18 525 bdi_unregister(disk->bdi);
83cbce9574462c block/genhd.c Luis Chamberlain 2021-08-18 526 out_unregister_queue:
83cbce9574462c block/genhd.c Luis Chamberlain 2021-08-18 527 blk_unregister_queue(disk);
83cbce9574462c block/genhd.c Luis Chamberlain 2021-08-18 528 out_put_slave_dir:
83cbce9574462c block/genhd.c Luis Chamberlain 2021-08-18 529 kobject_put(disk->slave_dir);
83cbce9574462c block/genhd.c Luis Chamberlain 2021-08-18 530 out_put_holder_dir:
83cbce9574462c block/genhd.c Luis Chamberlain 2021-08-18 531 kobject_put(disk->part0->bd_holder_dir);
83cbce9574462c block/genhd.c Luis Chamberlain 2021-08-18 532 out_del_integrity:
83cbce9574462c block/genhd.c Luis Chamberlain 2021-08-18 533 blk_integrity_del(disk);
83cbce9574462c block/genhd.c Luis Chamberlain 2021-08-18 534 out_del_block_link:
83cbce9574462c block/genhd.c Luis Chamberlain 2021-08-18 535 if (!sysfs_deprecated)
83cbce9574462c block/genhd.c Luis Chamberlain 2021-08-18 536 sysfs_remove_link(block_depr, dev_name(ddev));
83cbce9574462c block/genhd.c Luis Chamberlain 2021-08-18 537 out_device_del:
83cbce9574462c block/genhd.c Luis Chamberlain 2021-08-18 538 device_del(ddev);
83cbce9574462c block/genhd.c Luis Chamberlain 2021-08-18 539 out_disk_release_events:
83cbce9574462c block/genhd.c Luis Chamberlain 2021-08-18 540 disk_release_events(disk);
83cbce9574462c block/genhd.c Luis Chamberlain 2021-08-18 541 out_free_ext_minor:
83cbce9574462c block/genhd.c Luis Chamberlain 2021-08-18 542 if (disk->major == BLOCK_EXT_MAJOR)
83cbce9574462c block/genhd.c Luis Chamberlain 2021-08-18 543 blk_free_ext_minor(disk->first_minor);
53099761729ca1 block/genhd.c Luis Chamberlain 2021-07-15 544 return ret;
^1da177e4c3f41 drivers/block/genhd.c Linus Torvalds 2005-04-16 545 }
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@xxxxxxxxxxxx