[PATCH v2 05/26] block/cgroup: Modify the blkg_conf_open_bdev_frozen() calling convention

Bart Van Assche
2026-03-25T21:45:47Z

Instead of returning either a negative error number or a positive memory
flags value, pass a memory flags pointer as an argument and return zero
upon success. This patch prepares for adding thread-safety annotations
by changing the calling convention into something that is supported by
__cond_acquires().

Cc: Tejun Heo <tj@kernel.org>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
block/blk-cgroup.c | 12 +++++-------
block/blk-cgroup.h | 4 +++-
block/blk-iocost.c | 6 +++---
3 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
index 8c4052babffb..5b246020aced 100644
--- a/block/blk-cgroup.c
+++ b/block/blk-cgroup.c
@@ -815,14 +815,12 @@ EXPORT_SYMBOL_GPL(blkg_conf_open_bdev);
* Similar to blkg_conf_open_bdev, but additionally freezes the queue,
* ensures the correct locking order between freeze queue and q->rq_qos_mutex.
*
- * This function returns negative error on failure. On success it returns
- * memflags which must be saved and later passed to
- * blkg_conf_close_bdev_frozen() for restoring the memalloc scope.
+ * Returns: a negative error on failure or zero if successful.
*/
-unsigned long __must_check blkg_conf_open_bdev_frozen(struct blkg_conf_ctx *ctx)
+int blkg_conf_open_bdev_frozen(struct blkg_conf_ctx *ctx,
+ unsigned long *memflags)
{
int ret;
- unsigned long memflags;

if (ctx->bdev)
return -EINVAL;
@@ -838,10 +836,10 @@ unsigned long __must_check blkg_conf_open_bdev_frozen(struct blkg_conf_ctx *ctx)
*/
mutex_unlock(&ctx->bdev->bd_queue->rq_qos_mutex);

- memflags = blk_mq_freeze_queue(ctx->bdev->bd_queue);
+ *memflags = blk_mq_freeze_queue(ctx->bdev->bd_queue);
mutex_lock(&ctx->bdev->bd_queue->rq_qos_mutex);

- return memflags;
+ return 0;
}

/**
diff --git a/block/blk-cgroup.h b/block/blk-cgroup.h
index f0a3af520c55..f56fab637093 100644
--- a/block/blk-cgroup.h
+++ b/block/blk-cgroup.h
@@ -220,7 +220,9 @@ struct blkg_conf_ctx {
void blkg_conf_init(struct blkg_conf_ctx *ctx, char *input);
int blkg_conf_open_bdev(struct blkg_conf_ctx *ctx)
__cond_acquires(0, &ctx->bdev->bd_queue->rq_qos_mutex);
-unsigned long blkg_conf_open_bdev_frozen(struct blkg_conf_ctx *ctx);
+int blkg_conf_open_bdev_frozen(struct blkg_conf_ctx *ctx,
+ unsigned long *memflags)
+ __cond_acquires(0, &ctx->bdev->bd_queue->rq_qos_mutex);
int blkg_conf_prep(struct blkcg *blkcg, const struct blkcg_policy *pol,
struct blkg_conf_ctx *ctx)
__cond_acquires(0, &ctx->bdev->bd_disk->queue->queue_lock);
diff --git a/block/blk-iocost.c b/block/blk-iocost.c
index e435ac0c41e5..9f8bdae5a4b3 100644
--- a/block/blk-iocost.c
+++ b/block/blk-iocost.c
@@ -3232,9 +3232,9 @@ static ssize_t ioc_qos_write(struct kernfs_open_file *of, char *input,

blkg_conf_init(&ctx, input);

- memflags = blkg_conf_open_bdev_frozen(&ctx);
- if (IS_ERR_VALUE(memflags))
- return memflags;
+ ret = blkg_conf_open_bdev_frozen(&ctx, &memflags);
+ if (ret)
+ return ret;

body = ctx.body;
disk = ctx.bdev->bd_disk;