From: kernel test robot <lkp@intel.com>
To: kbuild@lists.01.org
Subject: [hch-block:bdev-inode 71/72] block/partitions/core.c:417 add_partition() warn: passing zero to 'ERR_PTR'
Date: Sun, 15 Nov 2020 08:23:57 +0800 [thread overview]
Message-ID: <202011150853.XzHCTEdS-lkp@intel.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 31433 bytes --]
CC: kbuild-all(a)lists.01.org
TO: Christoph Hellwig <hch@lst.de>
tree: git://git.infradead.org/users/hch/block.git bdev-inode
head: aa9426788d1aeb32c20dfd1e0181a42a8dd0890d
commit: 884bbcdbaaf8439db16bcf64ec891dcc62d172ea [71/72] block: merge struct block_device and struct hd_struct
:::::: branch date: 5 hours ago
:::::: commit date: 5 hours ago
config: x86_64-randconfig-m001-20201115 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
New smatch warnings:
block/partitions/core.c:417 add_partition() warn: passing zero to 'ERR_PTR'
block/partitions/core.c:602 blk_add_partition() error: 'part' dereferencing possible ERR_PTR()
Old smatch warnings:
block/partitions/core.c:179 check_partition() warn: passing zero to 'ERR_PTR'
vim +/ERR_PTR +417 block/partitions/core.c
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 308
6d2cf6f2b446c4 block/partition-generic.c Bart Van Assche 2017-08-17 309 /*
0e00b86c67ced3 block/partitions/core.c Christoph Hellwig 2020-11-14 310 * Must be called either with disk->mutex held, before a disk can be opened or
6d2cf6f2b446c4 block/partition-generic.c Bart Van Assche 2017-08-17 311 * after all disk users are gone.
6d2cf6f2b446c4 block/partition-generic.c Bart Van Assche 2017-08-17 312 */
884bbcdbaaf843 block/partitions/core.c Christoph Hellwig 2020-11-14 313 static struct block_device *add_partition(struct gendisk *disk, int partno,
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 314 sector_t start, sector_t len, int flags,
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 315 struct partition_meta_info *info)
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 316 {
884bbcdbaaf843 block/partitions/core.c Christoph Hellwig 2020-11-14 317 struct block_device *p;
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 318 dev_t devt = MKDEV(0, 0);
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 319 struct device *ddev = disk_to_dev(disk);
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 320 struct device *pdev;
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 321 struct disk_part_tbl *ptbl;
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 322 const char *dname;
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 323 int err;
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 324
b72053072c0bbe block/partition-generic.c Christoph Hellwig 2020-01-26 325 /*
b72053072c0bbe block/partition-generic.c Christoph Hellwig 2020-01-26 326 * Partitions are not supported on zoned block devices that are used as
b72053072c0bbe block/partition-generic.c Christoph Hellwig 2020-01-26 327 * such.
b72053072c0bbe block/partition-generic.c Christoph Hellwig 2020-01-26 328 */
b72053072c0bbe block/partition-generic.c Christoph Hellwig 2020-01-26 329 switch (disk->queue->limits.zoned) {
b72053072c0bbe block/partition-generic.c Christoph Hellwig 2020-01-26 330 case BLK_ZONED_HM:
b72053072c0bbe block/partition-generic.c Christoph Hellwig 2020-01-26 331 pr_warn("%s: partitions not supported on host managed zoned block device\n",
b72053072c0bbe block/partition-generic.c Christoph Hellwig 2020-01-26 332 disk->disk_name);
b72053072c0bbe block/partition-generic.c Christoph Hellwig 2020-01-26 333 return ERR_PTR(-ENXIO);
b72053072c0bbe block/partition-generic.c Christoph Hellwig 2020-01-26 334 case BLK_ZONED_HA:
b72053072c0bbe block/partition-generic.c Christoph Hellwig 2020-01-26 335 pr_info("%s: disabling host aware zoned block device support due to partitions\n",
b72053072c0bbe block/partition-generic.c Christoph Hellwig 2020-01-26 336 disk->disk_name);
b72053072c0bbe block/partition-generic.c Christoph Hellwig 2020-01-26 337 disk->queue->limits.zoned = BLK_ZONED_NONE;
b72053072c0bbe block/partition-generic.c Christoph Hellwig 2020-01-26 338 break;
b72053072c0bbe block/partition-generic.c Christoph Hellwig 2020-01-26 339 case BLK_ZONED_NONE:
b72053072c0bbe block/partition-generic.c Christoph Hellwig 2020-01-26 340 break;
b72053072c0bbe block/partition-generic.c Christoph Hellwig 2020-01-26 341 }
b72053072c0bbe block/partition-generic.c Christoph Hellwig 2020-01-26 342
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 343 err = disk_expand_part_tbl(disk, partno);
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 344 if (err)
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 345 return ERR_PTR(err);
6d2cf6f2b446c4 block/partition-generic.c Bart Van Assche 2017-08-17 346 ptbl = rcu_dereference_protected(disk->part_tbl, 1);
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 347
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 348 if (ptbl->part[partno])
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 349 return ERR_PTR(-EBUSY);
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 350
884bbcdbaaf843 block/partitions/core.c Christoph Hellwig 2020-11-14 351 p = bdev_alloc(disk, partno);
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 352 if (!p)
884bbcdbaaf843 block/partitions/core.c Christoph Hellwig 2020-11-14 353 return ERR_PTR(-ENOMEM);
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 354
884bbcdbaaf843 block/partitions/core.c Christoph Hellwig 2020-11-14 355 p->bd_start_sect = start;
884bbcdbaaf843 block/partitions/core.c Christoph Hellwig 2020-11-14 356 bdev_set_nr_sectors(p, len);
884bbcdbaaf843 block/partitions/core.c Christoph Hellwig 2020-11-14 357 p->bd_policy = get_disk_ro(disk);
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 358
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 359 if (info) {
f17c21c1ecb80e block/partition-generic.c Christoph Hellwig 2020-03-24 360 struct partition_meta_info *pinfo;
f17c21c1ecb80e block/partition-generic.c Christoph Hellwig 2020-03-24 361
f17c21c1ecb80e block/partition-generic.c Christoph Hellwig 2020-03-24 362 pinfo = kzalloc_node(sizeof(*pinfo), GFP_KERNEL, disk->node_id);
010459fd9ad527 block/partitions/core.c Christoph Hellwig 2020-08-31 363 if (!pinfo)
884bbcdbaaf843 block/partitions/core.c Christoph Hellwig 2020-11-14 364 goto out_free_stats;
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 365 memcpy(pinfo, info, sizeof(*info));
884bbcdbaaf843 block/partitions/core.c Christoph Hellwig 2020-11-14 366 p->bd_meta_info = pinfo;
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 367 }
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 368
884bbcdbaaf843 block/partitions/core.c Christoph Hellwig 2020-11-14 369 pdev = part_to_dev(p);
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 370 dname = dev_name(ddev);
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 371 if (isdigit(dname[strlen(dname) - 1]))
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 372 dev_set_name(pdev, "%sp%d", dname, partno);
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 373 else
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 374 dev_set_name(pdev, "%s%d", dname, partno);
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 375
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 376 device_initialize(pdev);
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 377 pdev->class = &block_class;
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 378 pdev->type = &part_type;
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 379 pdev->parent = ddev;
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 380
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 381 err = blk_alloc_devt(p, &devt);
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 382 if (err)
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 383 goto out_free_info;
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 384 pdev->devt = devt;
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 385
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 386 /* delay uevent until 'holders' subdir is created */
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 387 dev_set_uevent_suppress(pdev, 1);
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 388 err = device_add(pdev);
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 389 if (err)
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 390 goto out_put;
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 391
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 392 err = -ENOMEM;
884bbcdbaaf843 block/partitions/core.c Christoph Hellwig 2020-11-14 393 p->bd_holder_dir = kobject_create_and_add("holders", &pdev->kobj);
884bbcdbaaf843 block/partitions/core.c Christoph Hellwig 2020-11-14 394 if (!p->bd_holder_dir)
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 395 goto out_del;
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 396
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 397 dev_set_uevent_suppress(pdev, 0);
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 398 if (flags & ADDPART_FLAG_WHOLEDISK) {
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 399 err = device_create_file(pdev, &dev_attr_whole_disk);
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 400 if (err)
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 401 goto out_del;
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 402 }
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 403
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 404 /* everything is up and running, commence */
884bbcdbaaf843 block/partitions/core.c Christoph Hellwig 2020-11-14 405 bdev_add(p, devt);
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 406 rcu_assign_pointer(ptbl->part[partno], p);
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 407
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 408 /* suppress uevent if the disk suppresses it */
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 409 if (!dev_get_uevent_suppress(ddev))
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 410 kobject_uevent(&pdev->kobj, KOBJ_ADD);
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 411 return p;
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 412
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 413 out_free_info:
884bbcdbaaf843 block/partitions/core.c Christoph Hellwig 2020-11-14 414 kfree(p->bd_meta_info);
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 415 out_free_stats:
884bbcdbaaf843 block/partitions/core.c Christoph Hellwig 2020-11-14 416 bdput(p);
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 @417 return ERR_PTR(err);
010459fd9ad527 block/partitions/core.c Christoph Hellwig 2020-08-31 418
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 419 out_del:
884bbcdbaaf843 block/partitions/core.c Christoph Hellwig 2020-11-14 420 kobject_put(p->bd_holder_dir);
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 421 device_del(pdev);
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 422 out_put:
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 423 put_device(pdev);
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 424 return ERR_PTR(err);
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 425 }
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 426
fa9156ae597c24 block/partitions/core.c Christoph Hellwig 2020-04-14 427 static bool partition_overlaps(struct gendisk *disk, sector_t start,
fa9156ae597c24 block/partitions/core.c Christoph Hellwig 2020-04-14 428 sector_t length, int skip_partno)
fa9156ae597c24 block/partitions/core.c Christoph Hellwig 2020-04-14 429 {
fa9156ae597c24 block/partitions/core.c Christoph Hellwig 2020-04-14 430 struct disk_part_iter piter;
884bbcdbaaf843 block/partitions/core.c Christoph Hellwig 2020-11-14 431 struct block_device *part;
fa9156ae597c24 block/partitions/core.c Christoph Hellwig 2020-04-14 432 bool overlap = false;
fa9156ae597c24 block/partitions/core.c Christoph Hellwig 2020-04-14 433
fa9156ae597c24 block/partitions/core.c Christoph Hellwig 2020-04-14 434 disk_part_iter_init(&piter, disk, DISK_PITER_INCL_EMPTY);
fa9156ae597c24 block/partitions/core.c Christoph Hellwig 2020-04-14 435 while ((part = disk_part_iter_next(&piter))) {
884bbcdbaaf843 block/partitions/core.c Christoph Hellwig 2020-11-14 436 if (part->bd_partno == skip_partno ||
884bbcdbaaf843 block/partitions/core.c Christoph Hellwig 2020-11-14 437 start >= part->bd_start_sect + bdev_nr_sectors(part) ||
884bbcdbaaf843 block/partitions/core.c Christoph Hellwig 2020-11-14 438 start + length <= part->bd_start_sect)
fa9156ae597c24 block/partitions/core.c Christoph Hellwig 2020-04-14 439 continue;
fa9156ae597c24 block/partitions/core.c Christoph Hellwig 2020-04-14 440 overlap = true;
fa9156ae597c24 block/partitions/core.c Christoph Hellwig 2020-04-14 441 break;
fa9156ae597c24 block/partitions/core.c Christoph Hellwig 2020-04-14 442 }
fa9156ae597c24 block/partitions/core.c Christoph Hellwig 2020-04-14 443
fa9156ae597c24 block/partitions/core.c Christoph Hellwig 2020-04-14 444 disk_part_iter_exit(&piter);
fa9156ae597c24 block/partitions/core.c Christoph Hellwig 2020-04-14 445 return overlap;
fa9156ae597c24 block/partitions/core.c Christoph Hellwig 2020-04-14 446 }
fa9156ae597c24 block/partitions/core.c Christoph Hellwig 2020-04-14 447
fa9156ae597c24 block/partitions/core.c Christoph Hellwig 2020-04-14 448 int bdev_add_partition(struct block_device *bdev, int partno,
fa9156ae597c24 block/partitions/core.c Christoph Hellwig 2020-04-14 449 sector_t start, sector_t length)
fa9156ae597c24 block/partitions/core.c Christoph Hellwig 2020-04-14 450 {
884bbcdbaaf843 block/partitions/core.c Christoph Hellwig 2020-11-14 451 struct block_device *part;
fa9156ae597c24 block/partitions/core.c Christoph Hellwig 2020-04-14 452
0e00b86c67ced3 block/partitions/core.c Christoph Hellwig 2020-11-14 453 mutex_lock(&bdev->bd_disk->mutex);
fa9156ae597c24 block/partitions/core.c Christoph Hellwig 2020-04-14 454 if (partition_overlaps(bdev->bd_disk, start, length, -1)) {
0e00b86c67ced3 block/partitions/core.c Christoph Hellwig 2020-11-14 455 mutex_unlock(&bdev->bd_disk->mutex);
fa9156ae597c24 block/partitions/core.c Christoph Hellwig 2020-04-14 456 return -EBUSY;
fa9156ae597c24 block/partitions/core.c Christoph Hellwig 2020-04-14 457 }
fa9156ae597c24 block/partitions/core.c Christoph Hellwig 2020-04-14 458
fa9156ae597c24 block/partitions/core.c Christoph Hellwig 2020-04-14 459 part = add_partition(bdev->bd_disk, partno, start, length,
fa9156ae597c24 block/partitions/core.c Christoph Hellwig 2020-04-14 460 ADDPART_FLAG_NONE, NULL);
0e00b86c67ced3 block/partitions/core.c Christoph Hellwig 2020-11-14 461 mutex_unlock(&bdev->bd_disk->mutex);
fa9156ae597c24 block/partitions/core.c Christoph Hellwig 2020-04-14 462 return PTR_ERR_OR_ZERO(part);
fa9156ae597c24 block/partitions/core.c Christoph Hellwig 2020-04-14 463 }
fa9156ae597c24 block/partitions/core.c Christoph Hellwig 2020-04-14 464
fa9156ae597c24 block/partitions/core.c Christoph Hellwig 2020-04-14 465 int bdev_del_partition(struct block_device *bdev, int partno)
fa9156ae597c24 block/partitions/core.c Christoph Hellwig 2020-04-14 466 {
884bbcdbaaf843 block/partitions/core.c Christoph Hellwig 2020-11-14 467 struct block_device *part = NULL;
08fc1ab6d748ab block/partitions/core.c Christoph Hellwig 2020-09-01 468 int ret;
fa9156ae597c24 block/partitions/core.c Christoph Hellwig 2020-04-14 469
884bbcdbaaf843 block/partitions/core.c Christoph Hellwig 2020-11-14 470 part = bdget_disk(bdev->bd_disk, partno);
884bbcdbaaf843 block/partitions/core.c Christoph Hellwig 2020-11-14 471 if (!part)
88ce2a530cc986 block/partitions/core.c Christoph Hellwig 2020-09-08 472 return -ENXIO;
fa9156ae597c24 block/partitions/core.c Christoph Hellwig 2020-04-14 473
0e00b86c67ced3 block/partitions/core.c Christoph Hellwig 2020-11-14 474 mutex_lock(&bdev->bd_disk->mutex);
fa9156ae597c24 block/partitions/core.c Christoph Hellwig 2020-04-14 475 ret = -EBUSY;
884bbcdbaaf843 block/partitions/core.c Christoph Hellwig 2020-11-14 476 if (part->bd_openers)
fa9156ae597c24 block/partitions/core.c Christoph Hellwig 2020-04-14 477 goto out_unlock;
fa9156ae597c24 block/partitions/core.c Christoph Hellwig 2020-04-14 478
884bbcdbaaf843 block/partitions/core.c Christoph Hellwig 2020-11-14 479 sync_blockdev(part);
884bbcdbaaf843 block/partitions/core.c Christoph Hellwig 2020-11-14 480 invalidate_bdev(part);
fa9156ae597c24 block/partitions/core.c Christoph Hellwig 2020-04-14 481
8328eb28369a7d block/partitions/core.c Christoph Hellwig 2020-08-31 482 delete_partition(part);
fa9156ae597c24 block/partitions/core.c Christoph Hellwig 2020-04-14 483 ret = 0;
fa9156ae597c24 block/partitions/core.c Christoph Hellwig 2020-04-14 484 out_unlock:
0e00b86c67ced3 block/partitions/core.c Christoph Hellwig 2020-11-14 485 mutex_unlock(&bdev->bd_disk->mutex);
884bbcdbaaf843 block/partitions/core.c Christoph Hellwig 2020-11-14 486 bdput(part);
fa9156ae597c24 block/partitions/core.c Christoph Hellwig 2020-04-14 487 return ret;
fa9156ae597c24 block/partitions/core.c Christoph Hellwig 2020-04-14 488 }
fa9156ae597c24 block/partitions/core.c Christoph Hellwig 2020-04-14 489
fa9156ae597c24 block/partitions/core.c Christoph Hellwig 2020-04-14 490 int bdev_resize_partition(struct block_device *bdev, int partno,
fa9156ae597c24 block/partitions/core.c Christoph Hellwig 2020-04-14 491 sector_t start, sector_t length)
fa9156ae597c24 block/partitions/core.c Christoph Hellwig 2020-04-14 492 {
884bbcdbaaf843 block/partitions/core.c Christoph Hellwig 2020-11-14 493 struct block_device *part = NULL;
fa9156ae597c24 block/partitions/core.c Christoph Hellwig 2020-04-14 494 int ret = 0;
fa9156ae597c24 block/partitions/core.c Christoph Hellwig 2020-04-14 495
884bbcdbaaf843 block/partitions/core.c Christoph Hellwig 2020-11-14 496 part = bdget_disk(bdev->bd_disk, partno);
fa9156ae597c24 block/partitions/core.c Christoph Hellwig 2020-04-14 497 if (!part)
fa9156ae597c24 block/partitions/core.c Christoph Hellwig 2020-04-14 498 return -ENXIO;
fa9156ae597c24 block/partitions/core.c Christoph Hellwig 2020-04-14 499
0e00b86c67ced3 block/partitions/core.c Christoph Hellwig 2020-11-14 500 mutex_lock(&bdev->bd_disk->mutex);
fa9156ae597c24 block/partitions/core.c Christoph Hellwig 2020-04-14 501 ret = -EINVAL;
884bbcdbaaf843 block/partitions/core.c Christoph Hellwig 2020-11-14 502 if (start != part->bd_start_sect)
fa9156ae597c24 block/partitions/core.c Christoph Hellwig 2020-04-14 503 goto out_unlock;
fa9156ae597c24 block/partitions/core.c Christoph Hellwig 2020-04-14 504
fa9156ae597c24 block/partitions/core.c Christoph Hellwig 2020-04-14 505 ret = -EBUSY;
fa9156ae597c24 block/partitions/core.c Christoph Hellwig 2020-04-14 506 if (partition_overlaps(bdev->bd_disk, start, length, partno))
fa9156ae597c24 block/partitions/core.c Christoph Hellwig 2020-04-14 507 goto out_unlock;
fa9156ae597c24 block/partitions/core.c Christoph Hellwig 2020-04-14 508
884bbcdbaaf843 block/partitions/core.c Christoph Hellwig 2020-11-14 509 bdev_set_nr_sectors(part, length);
fa9156ae597c24 block/partitions/core.c Christoph Hellwig 2020-04-14 510
fa9156ae597c24 block/partitions/core.c Christoph Hellwig 2020-04-14 511 ret = 0;
fa9156ae597c24 block/partitions/core.c Christoph Hellwig 2020-04-14 512 out_unlock:
0e00b86c67ced3 block/partitions/core.c Christoph Hellwig 2020-11-14 513 mutex_unlock(&bdev->bd_disk->mutex);
884bbcdbaaf843 block/partitions/core.c Christoph Hellwig 2020-11-14 514 bdput(part);
fa9156ae597c24 block/partitions/core.c Christoph Hellwig 2020-04-14 515 return ret;
fa9156ae597c24 block/partitions/core.c Christoph Hellwig 2020-04-14 516 }
fa9156ae597c24 block/partitions/core.c Christoph Hellwig 2020-04-14 517
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 518 static bool disk_unlock_native_capacity(struct gendisk *disk)
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 519 {
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 520 const struct block_device_operations *bdops = disk->fops;
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 521
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 522 if (bdops->unlock_native_capacity &&
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 523 !(disk->flags & GENHD_FL_NATIVE_CAPACITY)) {
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 524 printk(KERN_CONT "enabling native capacity\n");
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 525 bdops->unlock_native_capacity(disk);
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 526 disk->flags |= GENHD_FL_NATIVE_CAPACITY;
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 527 return true;
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 528 } else {
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 529 printk(KERN_CONT "truncated\n");
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 530 return false;
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 531 }
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 532 }
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 533
d46430bf5a2298 block/partitions/core.c Christoph Hellwig 2020-04-14 534 int blk_drop_partitions(struct block_device *bdev)
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 535 {
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 536 struct disk_part_iter piter;
884bbcdbaaf843 block/partitions/core.c Christoph Hellwig 2020-11-14 537 struct block_device *part;
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 538
10c70d95c0f2f9 block/partitions/core.c Christoph Hellwig 2020-04-28 539 if (bdev->bd_part_count)
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 540 return -EBUSY;
e669c1da03a9dd block/partitions/core.c Christoph Hellwig 2020-04-14 541
e669c1da03a9dd block/partitions/core.c Christoph Hellwig 2020-04-14 542 sync_blockdev(bdev);
e669c1da03a9dd block/partitions/core.c Christoph Hellwig 2020-04-14 543 invalidate_bdev(bdev);
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 544
d46430bf5a2298 block/partitions/core.c Christoph Hellwig 2020-04-14 545 disk_part_iter_init(&piter, bdev->bd_disk, DISK_PITER_INCL_EMPTY);
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 546 while ((part = disk_part_iter_next(&piter)))
8328eb28369a7d block/partitions/core.c Christoph Hellwig 2020-08-31 547 delete_partition(part);
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 548 disk_part_iter_exit(&piter);
94ea4158f1733e block/partition-generic.c Al Viro 2011-09-16 549
fe316bf2d5847b block/partition-generic.c Jun'ichi Nomura 2012-03-02 550 return 0;
fe316bf2d5847b block/partition-generic.c Jun'ichi Nomura 2012-03-02 551 }
21be6cdc00954b block/partitions/core.c Christoph Hellwig 2020-04-14 552 #ifdef CONFIG_S390
21be6cdc00954b block/partitions/core.c Christoph Hellwig 2020-04-14 553 /* for historic reasons in the DASD driver */
21be6cdc00954b block/partitions/core.c Christoph Hellwig 2020-04-14 554 EXPORT_SYMBOL_GPL(blk_drop_partitions);
21be6cdc00954b block/partitions/core.c Christoph Hellwig 2020-04-14 555 #endif
fe316bf2d5847b block/partition-generic.c Jun'ichi Nomura 2012-03-02 556
f902b02600028d block/partition-generic.c Christoph Hellwig 2019-11-14 557 static bool blk_add_partition(struct gendisk *disk, struct block_device *bdev,
f902b02600028d block/partition-generic.c Christoph Hellwig 2019-11-14 558 struct parsed_partitions *state, int p)
fe316bf2d5847b block/partition-generic.c Jun'ichi Nomura 2012-03-02 559 {
f902b02600028d block/partition-generic.c Christoph Hellwig 2019-11-14 560 sector_t size = state->parts[p].size;
f902b02600028d block/partition-generic.c Christoph Hellwig 2019-11-14 561 sector_t from = state->parts[p].from;
884bbcdbaaf843 block/partitions/core.c Christoph Hellwig 2020-11-14 562 struct block_device *part;
f902b02600028d block/partition-generic.c Christoph Hellwig 2019-11-14 563
f902b02600028d block/partition-generic.c Christoph Hellwig 2019-11-14 564 if (!size)
f902b02600028d block/partition-generic.c Christoph Hellwig 2019-11-14 565 return true;
f902b02600028d block/partition-generic.c Christoph Hellwig 2019-11-14 566
f902b02600028d block/partition-generic.c Christoph Hellwig 2019-11-14 567 if (from >= get_capacity(disk)) {
f902b02600028d block/partition-generic.c Christoph Hellwig 2019-11-14 568 printk(KERN_WARNING
f902b02600028d block/partition-generic.c Christoph Hellwig 2019-11-14 569 "%s: p%d start %llu is beyond EOD, ",
f902b02600028d block/partition-generic.c Christoph Hellwig 2019-11-14 570 disk->disk_name, p, (unsigned long long) from);
f902b02600028d block/partition-generic.c Christoph Hellwig 2019-11-14 571 if (disk_unlock_native_capacity(disk))
f902b02600028d block/partition-generic.c Christoph Hellwig 2019-11-14 572 return false;
f902b02600028d block/partition-generic.c Christoph Hellwig 2019-11-14 573 return true;
fe316bf2d5847b block/partition-generic.c Jun'ichi Nomura 2012-03-02 574 }
fe316bf2d5847b block/partition-generic.c Jun'ichi Nomura 2012-03-02 575
f902b02600028d block/partition-generic.c Christoph Hellwig 2019-11-14 576 if (from + size > get_capacity(disk)) {
f902b02600028d block/partition-generic.c Christoph Hellwig 2019-11-14 577 printk(KERN_WARNING
f902b02600028d block/partition-generic.c Christoph Hellwig 2019-11-14 578 "%s: p%d size %llu extends beyond EOD, ",
f902b02600028d block/partition-generic.c Christoph Hellwig 2019-11-14 579 disk->disk_name, p, (unsigned long long) size);
fe316bf2d5847b block/partition-generic.c Jun'ichi Nomura 2012-03-02 580
f902b02600028d block/partition-generic.c Christoph Hellwig 2019-11-14 581 if (disk_unlock_native_capacity(disk))
f902b02600028d block/partition-generic.c Christoph Hellwig 2019-11-14 582 return false;
f902b02600028d block/partition-generic.c Christoph Hellwig 2019-11-14 583
f902b02600028d block/partition-generic.c Christoph Hellwig 2019-11-14 584 /*
f902b02600028d block/partition-generic.c Christoph Hellwig 2019-11-14 585 * We can not ignore partitions of broken tables created by for
f902b02600028d block/partition-generic.c Christoph Hellwig 2019-11-14 586 * example camera firmware, but we limit them to the end of the
f902b02600028d block/partition-generic.c Christoph Hellwig 2019-11-14 587 * disk to avoid creating invalid block devices.
f902b02600028d block/partition-generic.c Christoph Hellwig 2019-11-14 588 */
f902b02600028d block/partition-generic.c Christoph Hellwig 2019-11-14 589 size = get_capacity(disk) - from;
f902b02600028d block/partition-generic.c Christoph Hellwig 2019-11-14 590 }
f902b02600028d block/partition-generic.c Christoph Hellwig 2019-11-14 591
f902b02600028d block/partition-generic.c Christoph Hellwig 2019-11-14 592 part = add_partition(disk, p, from, size, state->parts[p].flags,
f902b02600028d block/partition-generic.c Christoph Hellwig 2019-11-14 593 &state->parts[p].info);
b72053072c0bbe block/partition-generic.c Christoph Hellwig 2020-01-26 594 if (IS_ERR(part) && PTR_ERR(part) != -ENXIO) {
f902b02600028d block/partition-generic.c Christoph Hellwig 2019-11-14 595 printk(KERN_ERR " %s: p%d could not be added: %ld\n",
f902b02600028d block/partition-generic.c Christoph Hellwig 2019-11-14 596 disk->disk_name, p, -PTR_ERR(part));
f902b02600028d block/partition-generic.c Christoph Hellwig 2019-11-14 597 return true;
f902b02600028d block/partition-generic.c Christoph Hellwig 2019-11-14 598 }
f902b02600028d block/partition-generic.c Christoph Hellwig 2019-11-14 599
74cc979c3c7f83 block/partition-generic.c Christoph Hellwig 2020-03-24 600 if (IS_BUILTIN(CONFIG_BLK_DEV_MD) &&
74cc979c3c7f83 block/partition-generic.c Christoph Hellwig 2020-03-24 601 (state->parts[p].flags & ADDPART_FLAG_RAID))
884bbcdbaaf843 block/partitions/core.c Christoph Hellwig 2020-11-14 @602 md_autodetect_dev(part->bd_dev);
74cc979c3c7f83 block/partition-generic.c Christoph Hellwig 2020-03-24 603
f902b02600028d block/partition-generic.c Christoph Hellwig 2019-11-14 604 return true;
f902b02600028d block/partition-generic.c Christoph Hellwig 2019-11-14 605 }
f902b02600028d block/partition-generic.c Christoph Hellwig 2019-11-14 606
:::::: The code at line 417 was first introduced by commit
:::::: 94ea4158f1733e3b10cef067d535f504866e0c41 separate partition format handling from generic code
:::::: TO: Al Viro <viro@zeniv.linux.org.uk>
:::::: CC: Al Viro <viro@zeniv.linux.org.uk>
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 31307 bytes --]
next reply other threads:[~2020-11-15 0:23 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-15 0:23 kernel test robot [this message]
-- strict thread matches above, loose matches on Subject: below --
2020-11-16 9:29 [hch-block:bdev-inode 71/72] block/partitions/core.c:417 add_partition() warn: passing zero to 'ERR_PTR' Dan Carpenter
2020-11-16 9:29 ` Dan Carpenter
2020-11-16 10:00 ` Christoph Hellwig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=202011150853.XzHCTEdS-lkp@intel.com \
--to=lkp@intel.com \
--cc=kbuild@lists.01.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.