On Mon, May 19, 2025 at 11:47:18AM +0530, Bharat Bhushan wrote:
/* Allocate extra memory for SG and response address alignment */
total_mem_len = ALIGN(info_len, OTX2_CPT_DPTR_RPTR_ALIGN) + dlen;
This add extra memory for 8-byte (OTX2_CPT_DPTR_RPTR_ALIGN) alignment
total_mem_len = ALIGN(total_mem_len, OTX2_CPT_RES_ADDR_ALIGN) +
sizeof(union otx2_cpt_res_s);
This add extra memory for 32-byte (OTX2_CPT_RES_ADDR_ALIGN)) In case not observed, OTX2_CPT_RES_ADDR_ALIGN is not the same as OTX2_CPT_DPTR_RPTR_ALIGN.
But it doesn't do that. Look, assume that total_mem_len is 64, then ALIGN(64, 32) will still be 64. You're not adding any extra space for the alignment padding.
OTOH, kmalloc can return something that has a page offset of 8, and you will need 24 extra bytes in your structure to make it align at 32.
Now of course if you're very lucky, and total_mem_len starts out at 8, then it would work but that's purely by chance.
Cheers,