bdi: add a ->dev_name field to struct backing_dev_info
authorChristoph Hellwig <hch@lst.de>
Mon, 4 May 2020 12:47:56 +0000 (14:47 +0200)
committerJens Axboe <axboe@kernel.dk>
Sat, 9 May 2020 22:07:57 +0000 (16:07 -0600)
Cache a copy of the name for the life time of the backing_dev_info
structure so that we can reference it even after unregistering.

Fixes: 68f23b89067f ("memcg: fix a crash in wb_workfn when a device disappears")
Reported-by: Yufen Yu <yuyufen@huawei.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Jan Kara <jack@suse.cz>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
include/linux/backing-dev-defs.h
mm/backing-dev.c

index ee577a83cfe67a8af1ed3ed83ffa7ae345eb3787..7367150f962a333b7f689c84e3ab2223a7281b16 100644 (file)
@@ -219,6 +219,7 @@ struct backing_dev_info {
        wait_queue_head_t wb_waitq;
 
        struct device *dev;
+       char dev_name[64];
        struct device *owner;
 
        struct timer_list laptop_mode_wb_timer;
index c2c44c89ee5d712da07bd9f54e679174a954000b..efc5b83acd2df59499f80c450e2db3b6f2c176a5 100644 (file)
@@ -938,7 +938,8 @@ int bdi_register_va(struct backing_dev_info *bdi, const char *fmt, va_list args)
        if (bdi->dev)   /* The driver needs to use separate queues per device */
                return 0;
 
-       dev = device_create_vargs(bdi_class, NULL, MKDEV(0, 0), bdi, fmt, args);
+       vsnprintf(bdi->dev_name, sizeof(bdi->dev_name), fmt, args);
+       dev = device_create(bdi_class, NULL, MKDEV(0, 0), bdi, bdi->dev_name);
        if (IS_ERR(dev))
                return PTR_ERR(dev);
 
@@ -1047,7 +1048,7 @@ const char *bdi_dev_name(struct backing_dev_info *bdi)
 {
        if (!bdi || !bdi->dev)
                return bdi_unknown_name;
-       return dev_name(bdi->dev);
+       return bdi->dev_name;
 }
 EXPORT_SYMBOL_GPL(bdi_dev_name);