Skip to content

Commit 994a62b

Browse files
committed
FROMLIST: misc: fastrpc: Replace hardcoded ctxid mask with GENMASK
Replace the hardcoded context ID mask (0xFF0) with GENMASK(11, 4) to improve readability and follow kernel bitfield conventions. Use FIELD_PREP and FIELD_GET instead of manual shifts for setting and extracting ctxid values. Link: https://lore.kernel.org/all/20260215182136.3995111-3-ekansh.gupta@oss.qualcomm.com/ Reviewed-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com> Signed-off-by: Ekansh Gupta <ekansh.gupta@oss.qualcomm.com>
1 parent 0aa0ac3 commit 994a62b

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

drivers/misc/fastrpc.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
#define FASTRPC_CTX_MAX (256)
3838
#define FASTRPC_INIT_HANDLE 1
3939
#define FASTRPC_DSP_UTILITIES_HANDLE 2
40-
#define FASTRPC_CTXID_MASK (0xFF0)
40+
#define FASTRPC_CTXID_MASK GENMASK(11, 4)
4141
#define INIT_FILELEN_MAX (2 * 1024 * 1024)
4242
#define INIT_FILE_NAMELEN_MAX (128)
4343
#define FASTRPC_DEVICE_NAME "fastrpc"
@@ -515,7 +515,7 @@ static void fastrpc_context_free(struct kref *ref)
515515
fastrpc_buf_free(ctx->buf);
516516

517517
spin_lock_irqsave(&cctx->lock, flags);
518-
idr_remove(&cctx->ctx_idr, ctx->ctxid >> 4);
518+
idr_remove(&cctx->ctx_idr, FIELD_GET(FASTRPC_CTXID_MASK, ctx->ctxid));
519519
spin_unlock_irqrestore(&cctx->lock, flags);
520520

521521
kfree(ctx->maps);
@@ -649,7 +649,7 @@ static struct fastrpc_invoke_ctx *fastrpc_context_alloc(
649649
spin_unlock_irqrestore(&cctx->lock, flags);
650650
goto err_idr;
651651
}
652-
ctx->ctxid = ret << 4;
652+
ctx->ctxid = FIELD_PREP(FASTRPC_CTXID_MASK, ret);
653653
spin_unlock_irqrestore(&cctx->lock, flags);
654654

655655
kref_init(&ctx->refcount);
@@ -2504,7 +2504,7 @@ static int fastrpc_rpmsg_callback(struct rpmsg_device *rpdev, void *data,
25042504
if (len < sizeof(*rsp))
25052505
return -EINVAL;
25062506

2507-
ctxid = ((rsp->ctx & FASTRPC_CTXID_MASK) >> 4);
2507+
ctxid = FIELD_GET(FASTRPC_CTXID_MASK, rsp->ctx);
25082508

25092509
spin_lock_irqsave(&cctx->lock, flags);
25102510
ctx = idr_find(&cctx->ctx_idr, ctxid);

0 commit comments

Comments
 (0)