Skip to content

Commit 4f9d406

Browse files
Li Nanrichardweinberger
authored andcommitted
ubi: block: fix null-pointer-dereference in ubiblock_create()
Similar to commit adbf4c4 ("ubi: block: fix memleak in ubiblock_create()"), 'dev->gd' is not assigned but dereferenced if blk_mq_alloc_tag_set() fails, and leading to a null-pointer-dereference. Fix it by using pr_err() and variable 'dev' to print error log. Additionally, the log in the error handle path of idr_alloc() has been improved by using pr_err(), too. Before initializing device name, using dev_err() will print error log with 'null' instead of the actual device name, like this: block (null): ... ~~~~~~ It is unclear. Using pr_err() can print more details of the device. The improved log is: ubiblock0_0: ... Fixes: 77567b2 ("ubi: use blk_mq_alloc_disk and blk_cleanup_disk") Reported-by: Dan Carpenter <dan.carpenter@linaro.org> Signed-off-by: Li Nan <linan122@huawei.com> Reviewed-by: Zhihao Cheng <chengzhihao1@huawei.com> Reviewed-by: Daniel Golle <daniel@makrotopia.org> Signed-off-by: Richard Weinberger <richard@nod.at>
1 parent 3998614 commit 4f9d406

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

drivers/mtd/ubi/block.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,8 @@ int ubiblock_create(struct ubi_volume_info *vi)
390390

391391
ret = blk_mq_alloc_tag_set(&dev->tag_set);
392392
if (ret) {
393-
dev_err(disk_to_dev(dev->gd), "blk_mq_alloc_tag_set failed");
393+
pr_err("ubiblock%d_%d: blk_mq_alloc_tag_set failed\n",
394+
dev->ubi_num, dev->vol_id);
394395
goto out_free_dev;
395396
}
396397

@@ -407,8 +408,8 @@ int ubiblock_create(struct ubi_volume_info *vi)
407408
gd->minors = 1;
408409
gd->first_minor = idr_alloc(&ubiblock_minor_idr, dev, 0, 0, GFP_KERNEL);
409410
if (gd->first_minor < 0) {
410-
dev_err(disk_to_dev(gd),
411-
"block: dynamic minor allocation failed");
411+
pr_err("ubiblock%d_%d: block: dynamic minor allocation failed\n",
412+
dev->ubi_num, dev->vol_id);
412413
ret = -ENODEV;
413414
goto out_cleanup_disk;
414415
}

0 commit comments

Comments
 (0)