Skip to content

Commit 26e197b

Browse files
Ryand1234axboe
authored andcommitted
block: fix potential invalid pointer dereference in blk_add_partition
The blk_add_partition() function initially used a single if-condition (IS_ERR(part)) to check for errors when adding a partition. This was modified to handle the specific case of -ENXIO separately, allowing the function to proceed without logging the error in this case. However, this change unintentionally left a path where md_autodetect_dev() could be called without confirming that part is a valid pointer. This commit separates the error handling logic by splitting the initial if-condition, improving code readability and handling specific error scenarios explicitly. The function now distinguishes the general error case from -ENXIO without altering the existing behavior of md_autodetect_dev() calls. Fixes: b720530 (block: allow partitions on host aware zone devices) Signed-off-by: Riyan Dhiman <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent cc08968 commit 26e197b

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

block/partitions/core.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -555,9 +555,11 @@ static bool blk_add_partition(struct gendisk *disk,
555555

556556
part = add_partition(disk, p, from, size, state->parts[p].flags,
557557
&state->parts[p].info);
558-
if (IS_ERR(part) && PTR_ERR(part) != -ENXIO) {
559-
printk(KERN_ERR " %s: p%d could not be added: %pe\n",
560-
disk->disk_name, p, part);
558+
if (IS_ERR(part)) {
559+
if (PTR_ERR(part) != -ENXIO) {
560+
printk(KERN_ERR " %s: p%d could not be added: %pe\n",
561+
disk->disk_name, p, part);
562+
}
561563
return true;
562564
}
563565

0 commit comments

Comments
 (0)