[PATCH v4 1/4] soc: qcom: smem: add IN_PARTITION_RANGE helper
From: Albert Esteve
Date: Thu Oct 22 2026 - 06:00:44 EST
From: Sarannya S <sarannya.s@xxxxxxxxxxxxxxxx>
Add IN_PARTITION_RANGE() to test that a pointer lies in [start, end]
and that pointer + size does not wrap.
Signed-off-by: Sarannya S <sarannya.s@xxxxxxxxxxxxxxxx>
Signed-off-by: Pranav Mahesh Phansalkar <pranav.phansalkar@xxxxxxxxxxxxxxxx>
Signed-off-by: Sudeepgoud Patil <sudeep.patil@xxxxxxxxxxxxxxxx>
Signed-off-by: Albert Esteve <aesteve@xxxxxxxxxx>
---
drivers/soc/qcom/smem.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/drivers/soc/qcom/smem.c b/drivers/soc/qcom/smem.c
index b5e7bd8c1512..36a4a10f3aec 100644
--- a/drivers/soc/qcom/smem.c
+++ b/drivers/soc/qcom/smem.c
@@ -2,6 +2,7 @@
/*
* Copyright (c) 2015, Sony Mobile Communications AB.
* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
+ * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
*/
#include <linux/debugfs.h>
@@ -88,6 +89,18 @@
/* Processor/host identifier for the global partition */
#define SMEM_GLOBAL_HOST 0xfffe
+/* Entry range check
+ * ptr >= start : Checks if ptr is at or past the start of the region
+ * ptr <= end : Checks if ptr is within the region
+ * size <= end - ptr: Checks if size fits in the remaining space, using
+ * uintptr_t subtraction to avoid pointer overflow UB
+ * (safe because ptr <= end is checked first)
+ */
+#define IN_PARTITION_RANGE(ptr, size, start, end) \
+ ((void *)(ptr) >= (void *)(start) && \
+ (void *)(ptr) <= (void *)(end) && \
+ (size) <= (uintptr_t)(end) - (uintptr_t)(ptr))
+
/**
* struct smem_proc_comm - proc_comm communication struct (legacy)
* @command: current command to be executed
--
2.55.0