diff options
Diffstat (limited to 'fs/partitions/check.c')
-rw-r--r-- | fs/partitions/check.c | 40 |
1 files changed, 31 insertions, 9 deletions
diff --git a/fs/partitions/check.c b/fs/partitions/check.c index 6149e4b58c88..7d6b34e201db 100644 --- a/fs/partitions/check.c +++ b/fs/partitions/check.c | |||
@@ -344,18 +344,18 @@ static ssize_t whole_disk_show(struct device *dev, | |||
344 | static DEVICE_ATTR(whole_disk, S_IRUSR | S_IRGRP | S_IROTH, | 344 | static DEVICE_ATTR(whole_disk, S_IRUSR | S_IRGRP | S_IROTH, |
345 | whole_disk_show, NULL); | 345 | whole_disk_show, NULL); |
346 | 346 | ||
347 | void add_partition(struct gendisk *disk, int part, sector_t start, sector_t len, int flags) | 347 | int add_partition(struct gendisk *disk, int part, sector_t start, sector_t len, int flags) |
348 | { | 348 | { |
349 | struct hd_struct *p; | 349 | struct hd_struct *p; |
350 | int err; | 350 | int err; |
351 | 351 | ||
352 | p = kzalloc(sizeof(*p), GFP_KERNEL); | 352 | p = kzalloc(sizeof(*p), GFP_KERNEL); |
353 | if (!p) | 353 | if (!p) |
354 | return; | 354 | return -ENOMEM; |
355 | 355 | ||
356 | if (!init_part_stats(p)) { | 356 | if (!init_part_stats(p)) { |
357 | kfree(p); | 357 | err = -ENOMEM; |
358 | return; | 358 | goto out0; |
359 | } | 359 | } |
360 | p->start_sect = start; | 360 | p->start_sect = start; |
361 | p->nr_sects = len; | 361 | p->nr_sects = len; |
@@ -378,15 +378,31 @@ void add_partition(struct gendisk *disk, int part, sector_t start, sector_t len, | |||
378 | 378 | ||
379 | /* delay uevent until 'holders' subdir is created */ | 379 | /* delay uevent until 'holders' subdir is created */ |
380 | p->dev.uevent_suppress = 1; | 380 | p->dev.uevent_suppress = 1; |
381 | device_add(&p->dev); | 381 | err = device_add(&p->dev); |
382 | if (err) | ||
383 | goto out1; | ||
382 | partition_sysfs_add_subdir(p); | 384 | partition_sysfs_add_subdir(p); |
383 | p->dev.uevent_suppress = 0; | 385 | p->dev.uevent_suppress = 0; |
384 | if (flags & ADDPART_FLAG_WHOLEDISK) | 386 | if (flags & ADDPART_FLAG_WHOLEDISK) { |
385 | err = device_create_file(&p->dev, &dev_attr_whole_disk); | 387 | err = device_create_file(&p->dev, &dev_attr_whole_disk); |
388 | if (err) | ||
389 | goto out2; | ||
390 | } | ||
386 | 391 | ||
387 | /* suppress uevent if the disk supresses it */ | 392 | /* suppress uevent if the disk supresses it */ |
388 | if (!disk->dev.uevent_suppress) | 393 | if (!disk->dev.uevent_suppress) |
389 | kobject_uevent(&p->dev.kobj, KOBJ_ADD); | 394 | kobject_uevent(&p->dev.kobj, KOBJ_ADD); |
395 | |||
396 | return 0; | ||
397 | |||
398 | out2: | ||
399 | device_del(&p->dev); | ||
400 | out1: | ||
401 | put_device(&p->dev); | ||
402 | free_part_stats(p); | ||
403 | out0: | ||
404 | kfree(p); | ||
405 | return err; | ||
390 | } | 406 | } |
391 | 407 | ||
392 | /* Not exported, helper to add_disk(). */ | 408 | /* Not exported, helper to add_disk(). */ |
@@ -401,7 +417,7 @@ void register_disk(struct gendisk *disk) | |||
401 | disk->dev.parent = disk->driverfs_dev; | 417 | disk->dev.parent = disk->driverfs_dev; |
402 | disk->dev.devt = MKDEV(disk->major, disk->first_minor); | 418 | disk->dev.devt = MKDEV(disk->major, disk->first_minor); |
403 | 419 | ||
404 | strlcpy(disk->dev.bus_id, disk->disk_name, KOBJ_NAME_LEN); | 420 | strlcpy(disk->dev.bus_id, disk->disk_name, BUS_ID_SIZE); |
405 | /* ewww... some of these buggers have / in the name... */ | 421 | /* ewww... some of these buggers have / in the name... */ |
406 | s = strchr(disk->dev.bus_id, '/'); | 422 | s = strchr(disk->dev.bus_id, '/'); |
407 | if (s) | 423 | if (s) |
@@ -483,10 +499,16 @@ int rescan_partitions(struct gendisk *disk, struct block_device *bdev) | |||
483 | if (!size) | 499 | if (!size) |
484 | continue; | 500 | continue; |
485 | if (from + size > get_capacity(disk)) { | 501 | if (from + size > get_capacity(disk)) { |
486 | printk(" %s: p%d exceeds device capacity\n", | 502 | printk(KERN_ERR " %s: p%d exceeds device capacity\n", |
487 | disk->disk_name, p); | 503 | disk->disk_name, p); |
504 | continue; | ||
505 | } | ||
506 | res = add_partition(disk, p, from, size, state->parts[p].flags); | ||
507 | if (res) { | ||
508 | printk(KERN_ERR " %s: p%d could not be added: %d\n", | ||
509 | disk->disk_name, p, -res); | ||
510 | continue; | ||
488 | } | 511 | } |
489 | add_partition(disk, p, from, size, state->parts[p].flags); | ||
490 | #ifdef CONFIG_BLK_DEV_MD | 512 | #ifdef CONFIG_BLK_DEV_MD |
491 | if (state->parts[p].flags & ADDPART_FLAG_RAID) | 513 | if (state->parts[p].flags & ADDPART_FLAG_RAID) |
492 | md_autodetect_dev(bdev->bd_dev+p); | 514 | md_autodetect_dev(bdev->bd_dev+p); |