Skip to content

Commit b0907ca

Browse files
Adrian Huangliu-song-6
Adrian Huang
authored andcommitted
md: fix incorrect declaration about claim_rdev in md_import_device
Commit fb541ca ("md: remove lock_bdev / unlock_bdev") removes wrappers for blkdev_get/blkdev_put. However, the uninitialized local static variable of pointer type 'claim_rdev' in md_import_device() is NULL, which leads to the following warning call trace: WARNING: CPU: 22 PID: 1037 at block/bdev.c:577 bd_prepare_to_claim+0x131/0x150 CPU: 22 PID: 1037 Comm: mdadm Not tainted 6.2.0-rc3+ #69 .. RIP: 0010:bd_prepare_to_claim+0x131/0x150 .. Call Trace: <TASK> ? _raw_spin_unlock+0x15/0x30 ? iput+0x6a/0x220 blkdev_get_by_dev.part.0+0x4b/0x300 md_import_device+0x126/0x1d0 new_dev_store+0x184/0x240 md_attr_store+0x80/0xf0 kernfs_fop_write_iter+0x128/0x1c0 vfs_write+0x2be/0x3c0 ksys_write+0x5f/0xe0 do_syscall_64+0x38/0x90 entry_SYSCALL_64_after_hwframe+0x72/0xdc It turns out the md device cannot be used: md: could not open device unknown-block(259,0). md: md127 stopped. Fix the issue by declaring the local static variable of struct type and passing the pointer of the variable to blkdev_get_by_dev(). Fixes: fb541ca ("md: remove lock_bdev / unlock_bdev") Cc: Christoph Hellwig <[email protected]> Signed-off-by: Adrian Huang <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Signed-off-by: Song Liu <[email protected]>
1 parent 3d25b1e commit b0907ca

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/md/md.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3644,7 +3644,7 @@ EXPORT_SYMBOL_GPL(md_rdev_init);
36443644
*/
36453645
static struct md_rdev *md_import_device(dev_t newdev, int super_format, int super_minor)
36463646
{
3647-
static struct md_rdev *claim_rdev; /* just for claiming the bdev */
3647+
static struct md_rdev claim_rdev; /* just for claiming the bdev */
36483648
struct md_rdev *rdev;
36493649
sector_t size;
36503650
int err;
@@ -3662,7 +3662,7 @@ static struct md_rdev *md_import_device(dev_t newdev, int super_format, int supe
36623662

36633663
rdev->bdev = blkdev_get_by_dev(newdev,
36643664
FMODE_READ | FMODE_WRITE | FMODE_EXCL,
3665-
super_format == -2 ? claim_rdev : rdev);
3665+
super_format == -2 ? &claim_rdev : rdev);
36663666
if (IS_ERR(rdev->bdev)) {
36673667
pr_warn("md: could not open device unknown-block(%u,%u).\n",
36683668
MAJOR(newdev), MINOR(newdev));

0 commit comments

Comments
 (0)