Skip to content

Commit 760c435

Browse files
committed
mtd: rawnand: make subop helpers return unsigned values
A report from Colin Ian King pointed a CoverityScan issue where error values on these helpers where not checked in the drivers. These helpers can error out only in case of a software bug in driver code, not because of a runtime/hardware error. Hence, let's WARN_ON() in this case and return 0 which is harmless anyway. Fixes: 8878b12 ("mtd: nand: add ->exec_op() implementation") Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> Reviewed-by: Boris Brezillon <boris.brezillon@bootlin.com> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
1 parent d166541 commit 760c435

2 files changed

Lines changed: 30 additions & 30 deletions

File tree

‎drivers/mtd/nand/raw/nand_base.c‎

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2668,8 +2668,8 @@ static bool nand_subop_instr_is_valid(const struct nand_subop *subop,
26682668
return subop && instr_idx < subop->ninstrs;
26692669
}
26702670

2671-
static int nand_subop_get_start_off(const struct nand_subop *subop,
2672-
unsigned int instr_idx)
2671+
static unsigned int nand_subop_get_start_off(const struct nand_subop *subop,
2672+
unsigned int instr_idx)
26732673
{
26742674
if (instr_idx)
26752675
return 0;
@@ -2688,12 +2688,12 @@ static int nand_subop_get_start_off(const struct nand_subop *subop,
26882688
*
26892689
* Given an address instruction, returns the offset of the first cycle to issue.
26902690
*/
2691-
int nand_subop_get_addr_start_off(const struct nand_subop *subop,
2692-
unsigned int instr_idx)
2691+
unsigned int nand_subop_get_addr_start_off(const struct nand_subop *subop,
2692+
unsigned int instr_idx)
26932693
{
2694-
if (!nand_subop_instr_is_valid(subop, instr_idx) ||
2695-
subop->instrs[instr_idx].type != NAND_OP_ADDR_INSTR)
2696-
return -EINVAL;
2694+
if (WARN_ON(!nand_subop_instr_is_valid(subop, instr_idx) ||
2695+
subop->instrs[instr_idx].type != NAND_OP_ADDR_INSTR))
2696+
return 0;
26972697

26982698
return nand_subop_get_start_off(subop, instr_idx);
26992699
}
@@ -2710,14 +2710,14 @@ EXPORT_SYMBOL_GPL(nand_subop_get_addr_start_off);
27102710
*
27112711
* Given an address instruction, returns the number of address cycle to issue.
27122712
*/
2713-
int nand_subop_get_num_addr_cyc(const struct nand_subop *subop,
2714-
unsigned int instr_idx)
2713+
unsigned int nand_subop_get_num_addr_cyc(const struct nand_subop *subop,
2714+
unsigned int instr_idx)
27152715
{
27162716
int start_off, end_off;
27172717

2718-
if (!nand_subop_instr_is_valid(subop, instr_idx) ||
2719-
subop->instrs[instr_idx].type != NAND_OP_ADDR_INSTR)
2720-
return -EINVAL;
2718+
if (WARN_ON(!nand_subop_instr_is_valid(subop, instr_idx) ||
2719+
subop->instrs[instr_idx].type != NAND_OP_ADDR_INSTR))
2720+
return 0;
27212721

27222722
start_off = nand_subop_get_addr_start_off(subop, instr_idx);
27232723

@@ -2742,12 +2742,12 @@ EXPORT_SYMBOL_GPL(nand_subop_get_num_addr_cyc);
27422742
*
27432743
* Given a data instruction, returns the offset to start from.
27442744
*/
2745-
int nand_subop_get_data_start_off(const struct nand_subop *subop,
2746-
unsigned int instr_idx)
2745+
unsigned int nand_subop_get_data_start_off(const struct nand_subop *subop,
2746+
unsigned int instr_idx)
27472747
{
2748-
if (!nand_subop_instr_is_valid(subop, instr_idx) ||
2749-
!nand_instr_is_data(&subop->instrs[instr_idx]))
2750-
return -EINVAL;
2748+
if (WARN_ON(!nand_subop_instr_is_valid(subop, instr_idx) ||
2749+
!nand_instr_is_data(&subop->instrs[instr_idx])))
2750+
return 0;
27512751

27522752
return nand_subop_get_start_off(subop, instr_idx);
27532753
}
@@ -2764,14 +2764,14 @@ EXPORT_SYMBOL_GPL(nand_subop_get_data_start_off);
27642764
*
27652765
* Returns the length of the chunk of data to send/receive.
27662766
*/
2767-
int nand_subop_get_data_len(const struct nand_subop *subop,
2768-
unsigned int instr_idx)
2767+
unsigned int nand_subop_get_data_len(const struct nand_subop *subop,
2768+
unsigned int instr_idx)
27692769
{
27702770
int start_off = 0, end_off;
27712771

2772-
if (!nand_subop_instr_is_valid(subop, instr_idx) ||
2773-
!nand_instr_is_data(&subop->instrs[instr_idx]))
2774-
return -EINVAL;
2772+
if (WARN_ON(!nand_subop_instr_is_valid(subop, instr_idx) ||
2773+
!nand_instr_is_data(&subop->instrs[instr_idx])))
2774+
return 0;
27752775

27762776
start_off = nand_subop_get_data_start_off(subop, instr_idx);
27772777

‎include/linux/mtd/rawnand.h‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,14 +1007,14 @@ struct nand_subop {
10071007
unsigned int last_instr_end_off;
10081008
};
10091009

1010-
int nand_subop_get_addr_start_off(const struct nand_subop *subop,
1011-
unsigned int op_id);
1012-
int nand_subop_get_num_addr_cyc(const struct nand_subop *subop,
1013-
unsigned int op_id);
1014-
int nand_subop_get_data_start_off(const struct nand_subop *subop,
1015-
unsigned int op_id);
1016-
int nand_subop_get_data_len(const struct nand_subop *subop,
1017-
unsigned int op_id);
1010+
unsigned int nand_subop_get_addr_start_off(const struct nand_subop *subop,
1011+
unsigned int op_id);
1012+
unsigned int nand_subop_get_num_addr_cyc(const struct nand_subop *subop,
1013+
unsigned int op_id);
1014+
unsigned int nand_subop_get_data_start_off(const struct nand_subop *subop,
1015+
unsigned int op_id);
1016+
unsigned int nand_subop_get_data_len(const struct nand_subop *subop,
1017+
unsigned int op_id);
10181018

10191019
/**
10201020
* struct nand_op_parser_addr_constraints - Constraints for address instructions

0 commit comments

Comments
 (0)