linux-raid.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1] md: fix incorrect declaration about claim_rdev in md_import_device
@ 2023-01-10  1:45 Adrian Huang
  2023-01-10  6:48 ` Christoph Hellwig
  0 siblings, 1 reply; 3+ messages in thread
From: Adrian Huang @ 2023-01-10  1:45 UTC (permalink / raw)
  To: linux-raid; +Cc: Song Liu, Adrian Huang, Christoph Hellwig, Adrian Huang

From: Adrian Huang <ahuang12@lenovo.com>

Commit fb541ca4c365 ("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: fb541ca4c365 ("md: remove lock_bdev / unlock_bdev")
Cc: Christoph Hellwig <hch@lst.de>
Signed-off-by: Adrian Huang <ahuang12@lenovo.com>
---
 drivers/md/md.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/md/md.c b/drivers/md/md.c
index 8af639296b3c..02b0240e7c71 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -3644,7 +3644,7 @@ EXPORT_SYMBOL_GPL(md_rdev_init);
  */
 static struct md_rdev *md_import_device(dev_t newdev, int super_format, int super_minor)
 {
-	static struct md_rdev *claim_rdev; /* just for claiming the bdev */
+	static struct md_rdev claim_rdev; /* just for claiming the bdev */
 	struct md_rdev *rdev;
 	sector_t size;
 	int err;
@@ -3662,7 +3662,7 @@ static struct md_rdev *md_import_device(dev_t newdev, int super_format, int supe
 
 	rdev->bdev = blkdev_get_by_dev(newdev,
 			FMODE_READ | FMODE_WRITE | FMODE_EXCL,
-			super_format == -2 ? claim_rdev : rdev);
+			super_format == -2 ? &claim_rdev : rdev);
 	if (IS_ERR(rdev->bdev)) {
 		pr_warn("md: could not open device unknown-block(%u,%u).\n",
 			MAJOR(newdev), MINOR(newdev));
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/1] md: fix incorrect declaration about claim_rdev in md_import_device
  2023-01-10  1:45 [PATCH 1/1] md: fix incorrect declaration about claim_rdev in md_import_device Adrian Huang
@ 2023-01-10  6:48 ` Christoph Hellwig
  2023-01-12 18:58   ` Song Liu
  0 siblings, 1 reply; 3+ messages in thread
From: Christoph Hellwig @ 2023-01-10  6:48 UTC (permalink / raw)
  To: Adrian Huang; +Cc: linux-raid, Song Liu, Christoph Hellwig, Adrian Huang

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/1] md: fix incorrect declaration about claim_rdev in md_import_device
  2023-01-10  6:48 ` Christoph Hellwig
@ 2023-01-12 18:58   ` Song Liu
  0 siblings, 0 replies; 3+ messages in thread
From: Song Liu @ 2023-01-12 18:58 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: Adrian Huang, linux-raid, Adrian Huang

On Mon, Jan 9, 2023 at 10:48 PM Christoph Hellwig <hch@lst.de> wrote:
>
> Looks good:
>
> Reviewed-by: Christoph Hellwig <hch@lst.de>

Applied to md-fixes. Thanks!

Song

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-01-12 19:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-01-10  1:45 [PATCH 1/1] md: fix incorrect declaration about claim_rdev in md_import_device Adrian Huang
2023-01-10  6:48 ` Christoph Hellwig
2023-01-12 18:58   ` Song Liu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).