The block layer invokes ->release() (lo_release()) with disk->open_mutex held, and __loop_clr_fd() relies on that lock when calling bdev_disk_changed(). Because Clang's context analysis does not know that lo_release() is called with disk->open_mutex held (and does not infer __must_hold() on a callback definition from a function pointer annotation), annotate both lo_release() and __loop_clr_fd() with __must_hold(&disk->open_mutex). Prepare for annotating bdev_disk_changed() with __must_hold(&disk->open_mutex) without introducing a context-analysis warning in drivers/block/loop.c under CONFIG_WARN_CONTEXT_ANALYSIS_ALL=y. Signed-off-by: Bart Van Assche --- drivers/block/loop.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/block/loop.c b/drivers/block/loop.c index 2034205c9cc7..1c4798f0a635 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -1031,6 +1031,7 @@ static int loop_configure(struct loop_device *lo, blk_mode_t mode, } static void __loop_clr_fd(struct gendisk *disk) + __must_hold(&disk->open_mutex) { struct loop_device *lo = disk->private_data; struct queue_limits lim; @@ -1676,6 +1677,7 @@ static int lo_open(struct gendisk *disk, blk_mode_t mode) } static void lo_release(struct gendisk *disk) + __must_hold(&disk->open_mutex) { struct loop_device *lo = disk->private_data; bool need_clear = false;