On 9/23/26 07:09, Bill Wendling wrote:
Under compiler-supported bounds checking (via KASAN or UBSAN), pointer
fields inside structures can be annotated with the '__counted_by_ptr'
attribute to specify which field in the same structure holds the element
count. This enables the compiler to perform runtime bounds checking on
the pointer.
Annotate the "base" pointer field in "struct adc5_device_data" with the
"__counted_by_ptr" attribute pointing to "num_sdams". The number of
SDAMs is determined from the device property and assigned to "num_sdams"
which is then used to initialize "base" via "devm_kcalloc".
By ensuring "num_sdams" is set to the correct element count prior to
the "base" pointer allocation, and since the size of "base" is never
reallocated or changed, this annotation is safe and will not cause any
false-positive runtime bounds check panics or KASAN issues.
Cc: [email protected]
Assisted-by: LLM
Signed-off-by: Bill Wendling <[email protected]>
Reviewed-by: Gustavo A. R. Silva <[email protected]>
Thanks
-Gustavo
---
include/linux/iio/adc/qcom-adc5-gen3-common.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/linux/iio/adc/qcom-adc5-gen3-common.h
b/include/linux/iio/adc/qcom-adc5-gen3-common.h
index 39cbfcbdb101..b3e2c2f50e8f 100644
--- a/include/linux/iio/adc/qcom-adc5-gen3-common.h
+++ b/include/linux/iio/adc/qcom-adc5-gen3-common.h
@@ -137,7 +137,7 @@ struct adc5_sdam_data {
*/
struct adc5_device_data {
struct regmap *regmap;
- struct adc5_sdam_data *base;
+ struct adc5_sdam_data *base __counted_by_ptr(num_sdams);
int num_sdams;
};