@@ -57,14 +57,15 @@ qcom_alloc_bam_transaction(struct qcom_nand_controller *nandc)
57
57
bam_txn_buf += sizeof (* bam_txn );
58
58
59
59
bam_txn -> bam_ce = bam_txn_buf ;
60
- bam_txn_buf +=
61
- sizeof (* bam_txn -> bam_ce ) * QPIC_PER_CW_CMD_ELEMENTS * num_cw ;
60
+ bam_txn -> bam_ce_nitems = QPIC_PER_CW_CMD_ELEMENTS * num_cw ;
61
+ bam_txn_buf += sizeof (* bam_txn -> bam_ce ) * bam_txn -> bam_ce_nitems ;
62
62
63
63
bam_txn -> cmd_sgl = bam_txn_buf ;
64
- bam_txn_buf +=
65
- sizeof (* bam_txn -> cmd_sgl ) * QPIC_PER_CW_CMD_SGL * num_cw ;
64
+ bam_txn -> cmd_sgl_nitems = QPIC_PER_CW_CMD_SGL * num_cw ;
65
+ bam_txn_buf += sizeof (* bam_txn -> cmd_sgl ) * bam_txn -> cmd_sgl_nitems ;
66
66
67
67
bam_txn -> data_sgl = bam_txn_buf ;
68
+ bam_txn -> data_sgl_nitems = QPIC_PER_CW_DATA_SGL * num_cw ;
68
69
69
70
init_completion (& bam_txn -> txn_done );
70
71
@@ -238,6 +239,11 @@ int qcom_prep_bam_dma_desc_cmd(struct qcom_nand_controller *nandc, bool read,
238
239
struct bam_transaction * bam_txn = nandc -> bam_txn ;
239
240
u32 offset ;
240
241
242
+ if (bam_txn -> bam_ce_pos + size > bam_txn -> bam_ce_nitems ) {
243
+ dev_err (nandc -> dev , "BAM %s array is full\n" , "CE" );
244
+ return - EINVAL ;
245
+ }
246
+
241
247
bam_ce_buffer = & bam_txn -> bam_ce [bam_txn -> bam_ce_pos ];
242
248
243
249
/* fill the command desc */
@@ -258,6 +264,12 @@ int qcom_prep_bam_dma_desc_cmd(struct qcom_nand_controller *nandc, bool read,
258
264
259
265
/* use the separate sgl after this command */
260
266
if (flags & NAND_BAM_NEXT_SGL ) {
267
+ if (bam_txn -> cmd_sgl_pos >= bam_txn -> cmd_sgl_nitems ) {
268
+ dev_err (nandc -> dev , "BAM %s array is full\n" ,
269
+ "CMD sgl" );
270
+ return - EINVAL ;
271
+ }
272
+
261
273
bam_ce_buffer = & bam_txn -> bam_ce [bam_txn -> bam_ce_start ];
262
274
bam_ce_size = (bam_txn -> bam_ce_pos -
263
275
bam_txn -> bam_ce_start ) *
@@ -297,10 +309,20 @@ int qcom_prep_bam_dma_desc_data(struct qcom_nand_controller *nandc, bool read,
297
309
struct bam_transaction * bam_txn = nandc -> bam_txn ;
298
310
299
311
if (read ) {
312
+ if (bam_txn -> rx_sgl_pos >= bam_txn -> data_sgl_nitems ) {
313
+ dev_err (nandc -> dev , "BAM %s array is full\n" , "RX sgl" );
314
+ return - EINVAL ;
315
+ }
316
+
300
317
sg_set_buf (& bam_txn -> data_sgl [bam_txn -> rx_sgl_pos ],
301
318
vaddr , size );
302
319
bam_txn -> rx_sgl_pos ++ ;
303
320
} else {
321
+ if (bam_txn -> tx_sgl_pos >= bam_txn -> data_sgl_nitems ) {
322
+ dev_err (nandc -> dev , "BAM %s array is full\n" , "TX sgl" );
323
+ return - EINVAL ;
324
+ }
325
+
304
326
sg_set_buf (& bam_txn -> data_sgl [bam_txn -> tx_sgl_pos ],
305
327
vaddr , size );
306
328
bam_txn -> tx_sgl_pos ++ ;
0 commit comments