Re: [PATCH V5 8/9] null_blk: serialize configfs attribute stores with device setup

From: Bart Van Assche

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


On 7/13/26 9:18 PM, Zizhi Wo wrote:
ret = nullb_device_##TYPE##_attr_store(&new_value, page, count);\
if (ret < 0) \
return ret; \
+ ret = 0; \
+ mutex_lock(&lock); \
if (apply_fn) \
ret = apply_fn(dev, new_value); \
else if (test_bit(NULLB_DEV_FL_CONFIGURED, &dev->flags)) \
ret = -EBUSY; \
+ if (!ret) \
+ dev->NAME = new_value; \
+ mutex_unlock(&lock); \
if (ret < 0) \
return ret; \
- dev->NAME = new_value; \
return count; \
} \

If guard()() would be used instead of explicit mutex_lock() and
mutex_unlock() calls, the if (ret) test wouldn't have to be duplicated,
isn't it?

Additionally, the above changes modify the behavior if apply_fn()
returns a strictly positive value (> 0).

Bart.