[PATCH v2 20/26] null_blk: Enable lock context analysis

Bart Van Assche
2026-03-25T21:46:38Z

Convert __releases() __acquires() into __must_hold(). Add __must_hold()
annotations where these are missing. Annotate two functions that use
conditional locking with __no_context_analysis. Enable lock context
analysis in the Makefile.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
drivers/block/null_blk/Makefile | 2 ++
drivers/block/null_blk/main.c | 7 +++++--
drivers/block/null_blk/zoned.c | 2 ++
3 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/block/null_blk/Makefile b/drivers/block/null_blk/Makefile
index 84c36e512ab8..282b0d51a477 100644
--- a/drivers/block/null_blk/Makefile
+++ b/drivers/block/null_blk/Makefile
@@ -1,5 +1,7 @@
# SPDX-License-Identifier: GPL-2.0

+CONTEXT_ANALYSIS := y
+
# needed for trace events
ccflags-y += -I$(src)

diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c
index f8c0fd57e041..677ac829ef80 100644
--- a/drivers/block/null_blk/main.c
+++ b/drivers/block/null_blk/main.c
@@ -1004,8 +1004,7 @@ static struct nullb_page *null_lookup_page(struct nullb *nullb,

static struct nullb_page *null_insert_page(struct nullb *nullb,
sector_t sector, bool ignore_cache)
- __releases(&nullb->lock)
- __acquires(&nullb->lock)
+ __must_hold(&nullb->lock)
{
u64 idx;
struct nullb_page *t_page;
@@ -1038,6 +1037,7 @@ static struct nullb_page *null_insert_page(struct nullb *nullb,
}

static int null_flush_cache_page(struct nullb *nullb, struct nullb_page *c_page)
+ __must_hold(&nullb->lock)
{
int i;
unsigned int offset;
@@ -1087,6 +1087,7 @@ static int null_flush_cache_page(struct nullb *nullb, struct nullb_page *c_page)
}

static int null_make_cache_space(struct nullb *nullb, unsigned long n)
+ __must_hold(&nullb->lock)
{
int i, err, nr_pages;
struct nullb_page *c_pages[FREE_BATCH];
@@ -1141,6 +1142,7 @@ static int null_make_cache_space(struct nullb *nullb, unsigned long n)

static blk_status_t copy_to_nullb(struct nullb *nullb, void *source,
loff_t pos, size_t n, bool is_fua)
+ __must_hold(&nullb->lock)
{
size_t temp, count = 0;
struct nullb_page *t_page;
@@ -1242,6 +1244,7 @@ static blk_status_t null_handle_flush(struct nullb *nullb)
static blk_status_t null_transfer(struct nullb *nullb, struct page *page,
unsigned int len, unsigned int off, bool is_write, loff_t pos,
bool is_fua)
+ __must_hold(&nullb->lock)
{
struct nullb_device *dev = nullb->dev;
blk_status_t err = BLK_STS_OK;
diff --git a/drivers/block/null_blk/zoned.c b/drivers/block/null_blk/zoned.c
index 384bdce6a9b7..a7f94e76034f 100644
--- a/drivers/block/null_blk/zoned.c
+++ b/drivers/block/null_blk/zoned.c
@@ -32,6 +32,7 @@ static inline void null_init_zone_lock(struct nullb_device *dev,

static inline void null_lock_zone(struct nullb_device *dev,
struct nullb_zone *zone)
+ __no_context_analysis /* conditional locking */
{
if (!dev->memory_backed)
spin_lock_irq(&zone->spinlock);
@@ -41,6 +42,7 @@ static inline void null_lock_zone(struct nullb_device *dev,

static inline void null_unlock_zone(struct nullb_device *dev,
struct nullb_zone *zone)
+ __no_context_analysis /* conditional locking */
{
if (!dev->memory_backed)
spin_unlock_irq(&zone->spinlock);