Skip to contentSkip to conversation

block: update add_partition() error handling

PATCH New Tejun Heo 1 participant 1 message Jul 14, 2008 Block layer

lore
Share & tools
lore

Tejun Heo

author
#0 lore raw

PATCH 1/1 block: update add_partition() error handling

add_partition() had some number of holes in the error handling path. Update it.

* make add_partition() return error code on failure and report failure from caller

* make add_partition() check whether the specified slot is already occupied instead of doing that in caller

* make add_partition() check error return from device_add()

---
 block/ioctl.c         |   17 +++++++++--------
 fs/partitions/check.c |   44 ++++++++++++++++++++++++++++++++++----------
 include/linux/genhd.h |    2 +-
 3 files changed, 44 insertions(+), 19 deletions(-)
block/ioctl.c +9 -8
index f0178c4..ecbdd74 100644
@@ -16,7 +16,7 @@ static int blkpg_ioctl(struct block_device *bdev, struct blkpg_ioctl_arg __user
 	struct blkpg_partition p;
 	long long start, length;
 	int part;
-	int i;
+	int i, rc;
 
 	if (!capable(CAP_SYS_ADMIN))
 		return -EACCES;
@@ -42,12 +42,9 @@ static int blkpg_ioctl(struct block_device *bdev, struct blkpg_ioctl_arg __user
 				    || pstart < 0 || plength < 0)
 					return -EINVAL;
 			}
-			/* partition number in use? */
+
 			mutex_lock(&bdev->bd_mutex);
-			if (disk->part[part - 1]) {
-				mutex_unlock(&bdev->bd_mutex);
-				return -EBUSY;
-			}
+
 			/* overlap? */
 			for (i = 0; i < disk->minors - 1; i++) {
 				struct hd_struct *s = disk->part[i];
@@ -60,10 +57,14 @@ static int blkpg_ioctl(struct block_device *bdev, struct blkpg_ioctl_arg __user
 					return -EBUSY;
 				}
 			}
+
 			/* all seems OK */
-			add_partition(disk, part, start, length, ADDPART_FLAG_NONE);
+			rc = add_partition(disk, part, start, length,
+					   ADDPART_FLAG_NONE);
+
 			mutex_unlock(&bdev->bd_mutex);
-			return 0;
+			return rc;
+
 		case BLKPG_DEL_PARTITION:
 			if (!disk->part[part-1])
 				return -ENXIO;
fs/partitions/check.c +34 -10

75 lines not on this page · raw message

include/linux/genhd.h +1 -1
index ae7aec3..e485cf0 100644
@@ -529,7 +529,7 @@ extern dev_t blk_lookup_devt(const char *name, int part);
 extern char *disk_name (struct gendisk *hd, int part, char *buf);
 
 extern int rescan_partitions(struct gendisk *disk, struct block_device *bdev);
-extern void add_partition(struct gendisk *, int, sector_t, sector_t, int);
+extern int add_partition(struct gendisk *, int, sector_t, sector_t, int);
 extern void delete_partition(struct gendisk *, int);
 extern void printk_all_partitions(void);
 
Signature · 1 line
1.5.4.5