@@ -3466,30 +3466,36 @@ static void rawnand_enable_cont_reads(struct nand_chip *chip, unsigned int page,
3466
3466
u32 readlen , int col )
3467
3467
{
3468
3468
struct mtd_info * mtd = nand_to_mtd (chip );
3469
- unsigned int end_page , end_col ;
3469
+ unsigned int first_page , last_page ;
3470
3470
3471
3471
chip -> cont_read .ongoing = false;
3472
3472
3473
3473
if (!chip -> controller -> supported_op .cont_read )
3474
3474
return ;
3475
3475
3476
- end_page = DIV_ROUND_UP (col + readlen , mtd -> writesize );
3477
- end_col = (col + readlen ) % mtd -> writesize ;
3476
+ /*
3477
+ * Don't bother making any calculations if the length is too small.
3478
+ * Side effect: avoids possible integer underflows below.
3479
+ */
3480
+ if (readlen < (2 * mtd -> writesize ))
3481
+ return ;
3478
3482
3483
+ /* Derive the page where continuous read should start (the first full page read) */
3484
+ first_page = page ;
3479
3485
if (col )
3480
- page ++ ;
3481
-
3482
- if (end_col && end_page )
3483
- end_page -- ;
3486
+ first_page ++ ;
3484
3487
3485
- if (page + 1 > end_page )
3486
- return ;
3487
-
3488
- chip -> cont_read .first_page = page ;
3489
- chip -> cont_read .last_page = end_page ;
3490
- chip -> cont_read .ongoing = true;
3488
+ /* Derive the page where continuous read should stop (the last full page read) */
3489
+ last_page = page + ((col + readlen ) / mtd -> writesize ) - 1 ;
3491
3490
3492
- rawnand_cap_cont_reads (chip );
3491
+ /* Configure and enable continuous read when suitable */
3492
+ if (first_page < last_page ) {
3493
+ chip -> cont_read .first_page = first_page ;
3494
+ chip -> cont_read .last_page = last_page ;
3495
+ chip -> cont_read .ongoing = true;
3496
+ /* May reset the ongoing flag */
3497
+ rawnand_cap_cont_reads (chip );
3498
+ }
3493
3499
}
3494
3500
3495
3501
static void rawnand_cont_read_skip_first_page (struct nand_chip * chip , unsigned int page )
0 commit comments