Annotate the functions in block/partitions/core.c that are called with disk->open_mutex held with __must_hold(&disk->open_mutex): - add_partition() - blk_add_partition() - blk_add_partitions() - bdev_disk_changed() (both declaration in and definition) Remove the stale comment above add_partition() claiming it may be called without open_mutex held, which contradicts both lockdep_assert_held(&disk->open_mutex) and the new annotation. Do not annotate drop_partition() since its callers obtain the mutex through a different pointer, e.g. disk->open_mutex instead of part->bd_disk->open_mutex, and since Clang cannot determine that these expressions refer to the same mutex. The lockdep_assert_held() call in drop_partition() keeps verifying the locking requirement at runtime. Signed-off-by: Bart Van Assche --- block/partitions/core.c | 8 ++++---- include/linux/blkdev.h | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/block/partitions/core.c b/block/partitions/core.c index b5c59b79ca7c..9d55a7ac83d9 100644 --- a/block/partitions/core.c +++ b/block/partitions/core.c @@ -288,13 +288,10 @@ static ssize_t whole_disk_show(struct device *dev, } static const DEVICE_ATTR(whole_disk, 0444, whole_disk_show, NULL); -/* - * Must be called either with open_mutex held, before a disk can be opened or - * after all disk users are gone. - */ static struct block_device *add_partition(struct gendisk *disk, int partno, sector_t start, sector_t len, int flags, struct partition_meta_info *info) + __must_hold(&disk->open_mutex) { dev_t devt = MKDEV(0, 0); struct device *ddev = disk_to_dev(disk); @@ -530,6 +527,7 @@ static bool disk_unlock_native_capacity(struct gendisk *disk) static bool blk_add_partition(struct gendisk *disk, struct parsed_partitions *state, int p) + __must_hold(&disk->open_mutex) { sector_t size = state->parts[p].size; sector_t from = state->parts[p].from; @@ -581,6 +579,7 @@ static bool blk_add_partition(struct gendisk *disk, } static int blk_add_partitions(struct gendisk *disk) + __must_hold(&disk->open_mutex) { struct parsed_partitions *state; int ret = -EAGAIN, p; @@ -642,6 +641,7 @@ static int blk_add_partitions(struct gendisk *disk) } int bdev_disk_changed(struct gendisk *disk, bool invalidate) + __must_hold(&disk->open_mutex) { struct block_device *part; unsigned long idx; diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 558918349888..daaf5c34e8d6 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1015,7 +1015,8 @@ static inline unsigned int bdev_nr_zones(struct block_device *bdev) return disk_nr_zones(bdev->bd_disk); } -int bdev_disk_changed(struct gendisk *disk, bool invalidate); +int bdev_disk_changed(struct gendisk *disk, bool invalidate) + __must_hold(&disk->open_mutex); void put_disk(struct gendisk *disk); struct gendisk *__blk_alloc_disk(struct queue_limits *lim, int node,