]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
mtd: nand: qpic_common: use {cmd,data}_sgl_nitems for sg_init_table()
authorGabor Juhos <j4g8y7@gmail.com>
Mon, 11 Aug 2025 08:30:42 +0000 (10:30 +0200)
committerMiquel Raynal <miquel.raynal@bootlin.com>
Thu, 28 Aug 2025 12:23:20 +0000 (14:23 +0200)
Since commit ddaad4ad774d ("mtd: nand: qpic_common: prevent out of
bounds access of BAM arrays"), the {cmd,data}_sgl_nitems members in
the 'bam_transaction' structure are containing the number of elements
in the cmd/data scatter-gather lists.

Change the qcom_clear_bam_transaction() function to use these numbers
while reinitializing the sg lists instead of recomputing the number of
elements to make it less error prone.

Signed-off-by: Gabor Juhos <j4g8y7@gmail.com>
Acked-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
drivers/mtd/nand/qpic_common.c

index 8e604cc22ca310159edf4d8dbc2f6a82d5119eb4..db6c46a6fe01c71e8bb0379eb1f289c7e56701c9 100644 (file)
@@ -89,10 +89,8 @@ void qcom_clear_bam_transaction(struct qcom_nand_controller *nandc)
        memset(&bam_txn->bam_positions, 0, sizeof(bam_txn->bam_positions));
        bam_txn->last_data_desc = NULL;
 
-       sg_init_table(bam_txn->cmd_sgl, nandc->max_cwperpage *
-                     QPIC_PER_CW_CMD_SGL);
-       sg_init_table(bam_txn->data_sgl, nandc->max_cwperpage *
-                     QPIC_PER_CW_DATA_SGL);
+       sg_init_table(bam_txn->cmd_sgl, bam_txn->cmd_sgl_nitems);
+       sg_init_table(bam_txn->data_sgl, bam_txn->data_sgl_nitems);
 
        reinit_completion(&bam_txn->txn_done);
 }