Re: [PATCH V5 9/9] null_blk: serialize configfs attribute shows with the file-scope lock

From: Bart Van Assche

Date: Fri Jul 24 2026 - 17:16:17 EST



On 7/13/26 9:18 PM, Zizhi Wo wrote:
diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c
index 67cd32d28887..c8487a630e1a 100644
--- a/drivers/block/null_blk/main.c
+++ b/drivers/block/null_blk/main.c
@@ -345,8 +345,14 @@ static ssize_t nullb_device_bool_attr_store(bool *val, const char *page,
static ssize_t \
nullb_device_##NAME##_show(struct config_item *item, char *page) \
{ \
- return nullb_device_##TYPE##_attr_show( \
+ ssize_t ret; \
+ \
+ mutex_lock(&lock); \
+ ret = nullb_device_##TYPE##_attr_show( \
to_nullb_device(item)->NAME, page); \
+ mutex_unlock(&lock); \
+ \
+ return ret; \
} \
static ssize_t \
nullb_device_##NAME##_store(struct config_item *item, const char *page, \
@@ -479,7 +485,13 @@ NULLB_DEVICE_ATTR(badblocks_partial_io, bool, NULL);
static ssize_t nullb_device_power_show(struct config_item *item, char *page)
{
- return nullb_device_bool_attr_show(to_nullb_device(item)->power, page);
+ ssize_t ret;
+
+ mutex_lock(&lock);
+ ret = nullb_device_bool_attr_show(to_nullb_device(item)->power, page);
+ mutex_unlock(&lock);
+
+ return ret;
}

The above changes would be much more elegant if guard()() would be used instead of explicit mutex_lock() and mutex_unlock() calls.

Thanks,

Bart.