Skip to contentSkip to conversation

crypto: hisilicon/qm - add __counted_by_ptr to dfx_diff_registers

PATCH In review Bill Wendling 3 participants 3 messages Sep 23 – Oct 2

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 crypto: hisilicon/qm - add __counted_by_ptr to dfx_diff_registers

Annotate the pointer field 'regs' in 'struct dfx_diff_registers' with the '__counted_by_ptr' attribute, referencing the 'reg_len' member which holds the element count of the allocated memory.

In 'drivers/crypto/hisilicon/debugfs.c', the 'dfx_regs_init' function allocates the 'diff_regs' array and initializes each element's 'regs' pointer after setting its 'reg_len'.

Since 'reg_len' is set before 'regs' is assigned, the compiler's bounds sanitizer can correctly associate the pointer with its allocated size.

---
 include/linux/hisi_acc_qm.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/hisi_acc_qm.h +1 -1
index 8dc49fa2123b..f2885d60b468 100644
@@ -196,7 +196,7 @@ struct qm_dev_dfx {
 };
 
 struct dfx_diff_registers {
-	u32 *regs;
+	u32 *regs __counted_by_ptr(reg_len);
 	u32 reg_offset;
 	u32 reg_len;
 };
Signature · 1 line
2.55.0.1082.g2b9226bbc0-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Bill Wendling

Annotate the pointer field 'regs' in 'struct dfx_diff_registers' with the '__counted_by_ptr' attribute, referencing the 'reg_len' member which holds the element count of the allocated memory.

In 'drivers/crypto/hisilicon/debugfs.c', the 'dfx_regs_init' function allocates the 'diff_regs' array and initializes each element's 'regs' pointer after setting its 'reg_len'.

Quoted 6 lines

Since 'reg_len' is set before 'regs' is assigned, the compiler's bounds sanitizer can correctly associate the pointer with its allocated size.

Thanks
-Gustavo

Quoted 17 lines
---
  include/linux/hisi_acc_qm.h | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/hisi_acc_qm.h +1 -1
index 8dc49fa2123b..f2885d60b468 100644
@@ -196,7 +196,7 @@ struct qm_dev_dfx {
  };
 
  struct dfx_diff_registers {
-	u32 *regs;
+	u32 *regs __counted_by_ptr(reg_len);
  	u32 reg_offset;
  	u32 reg_len;
  };
maintainer
#2 lore raw
In reply to Bill Wendling
Quoted 11 lines · Bill Wendling

Annotate the pointer field 'regs' in 'struct dfx_diff_registers' with the '__counted_by_ptr' attribute, referencing the 'reg_len' member which holds the element count of the allocated memory.

In 'drivers/crypto/hisilicon/debugfs.c', the 'dfx_regs_init' function allocates the 'diff_regs' array and initializes each element's 'regs' pointer after setting its 'reg_len'.

Since 'reg_len' is set before 'regs' is assigned, the compiler's bounds sanitizer can correctly associate the pointer with its allocated size.

Quoted 6 lines

---
include/linux/hisi_acc_qm.h | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)

Patch applied. Thanks.

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt