]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
mtd: rawnand: make subop helpers return unsigned values
authorMiquel Raynal <miquel.raynal@bootlin.com>
Wed, 18 Jul 2018 22:09:12 +0000 (00:09 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 19 Sep 2018 20:41:32 +0000 (22:41 +0200)
[ Upstream commit 760c435e0f85ed19e48a90d746ce1de2cd02def7 ]

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: 8878b126df76 ("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>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/mtd/nand/raw/nand_base.c
include/linux/mtd/rawnand.h

index b01d15ec4c56bfbdded578526d76e2ed12b65093..3e3e6a8f1abc45afb42957f9c256ac0c7c6eafe7 100644 (file)
@@ -2668,8 +2668,8 @@ static bool nand_subop_instr_is_valid(const struct nand_subop *subop,
        return subop && instr_idx < subop->ninstrs;
 }
 
-static int nand_subop_get_start_off(const struct nand_subop *subop,
-                                   unsigned int instr_idx)
+static unsigned int nand_subop_get_start_off(const struct nand_subop *subop,
+                                            unsigned int instr_idx)
 {
        if (instr_idx)
                return 0;
@@ -2688,12 +2688,12 @@ static int nand_subop_get_start_off(const struct nand_subop *subop,
  *
  * Given an address instruction, returns the offset of the first cycle to issue.
  */
-int nand_subop_get_addr_start_off(const struct nand_subop *subop,
-                                 unsigned int instr_idx)
+unsigned int nand_subop_get_addr_start_off(const struct nand_subop *subop,
+                                          unsigned int instr_idx)
 {
-       if (!nand_subop_instr_is_valid(subop, instr_idx) ||
-           subop->instrs[instr_idx].type != NAND_OP_ADDR_INSTR)
-               return -EINVAL;
+       if (WARN_ON(!nand_subop_instr_is_valid(subop, instr_idx) ||
+                   subop->instrs[instr_idx].type != NAND_OP_ADDR_INSTR))
+               return 0;
 
        return nand_subop_get_start_off(subop, instr_idx);
 }
@@ -2710,14 +2710,14 @@ EXPORT_SYMBOL_GPL(nand_subop_get_addr_start_off);
  *
  * Given an address instruction, returns the number of address cycle to issue.
  */
-int nand_subop_get_num_addr_cyc(const struct nand_subop *subop,
-                               unsigned int instr_idx)
+unsigned int nand_subop_get_num_addr_cyc(const struct nand_subop *subop,
+                                        unsigned int instr_idx)
 {
        int start_off, end_off;
 
-       if (!nand_subop_instr_is_valid(subop, instr_idx) ||
-           subop->instrs[instr_idx].type != NAND_OP_ADDR_INSTR)
-               return -EINVAL;
+       if (WARN_ON(!nand_subop_instr_is_valid(subop, instr_idx) ||
+                   subop->instrs[instr_idx].type != NAND_OP_ADDR_INSTR))
+               return 0;
 
        start_off = nand_subop_get_addr_start_off(subop, instr_idx);
 
@@ -2742,12 +2742,12 @@ EXPORT_SYMBOL_GPL(nand_subop_get_num_addr_cyc);
  *
  * Given a data instruction, returns the offset to start from.
  */
-int nand_subop_get_data_start_off(const struct nand_subop *subop,
-                                 unsigned int instr_idx)
+unsigned int nand_subop_get_data_start_off(const struct nand_subop *subop,
+                                          unsigned int instr_idx)
 {
-       if (!nand_subop_instr_is_valid(subop, instr_idx) ||
-           !nand_instr_is_data(&subop->instrs[instr_idx]))
-               return -EINVAL;
+       if (WARN_ON(!nand_subop_instr_is_valid(subop, instr_idx) ||
+                   !nand_instr_is_data(&subop->instrs[instr_idx])))
+               return 0;
 
        return nand_subop_get_start_off(subop, instr_idx);
 }
@@ -2764,14 +2764,14 @@ EXPORT_SYMBOL_GPL(nand_subop_get_data_start_off);
  *
  * Returns the length of the chunk of data to send/receive.
  */
-int nand_subop_get_data_len(const struct nand_subop *subop,
-                           unsigned int instr_idx)
+unsigned int nand_subop_get_data_len(const struct nand_subop *subop,
+                                    unsigned int instr_idx)
 {
        int start_off = 0, end_off;
 
-       if (!nand_subop_instr_is_valid(subop, instr_idx) ||
-           !nand_instr_is_data(&subop->instrs[instr_idx]))
-               return -EINVAL;
+       if (WARN_ON(!nand_subop_instr_is_valid(subop, instr_idx) ||
+                   !nand_instr_is_data(&subop->instrs[instr_idx])))
+               return 0;
 
        start_off = nand_subop_get_data_start_off(subop, instr_idx);
 
index 3e8ec3b8a39c7ce39ac563ad157d3f9563c24d86..87c635d6c773af29c0e3053160698740d44e1653 100644 (file)
@@ -986,14 +986,14 @@ struct nand_subop {
        unsigned int last_instr_end_off;
 };
 
-int nand_subop_get_addr_start_off(const struct nand_subop *subop,
-                                 unsigned int op_id);
-int nand_subop_get_num_addr_cyc(const struct nand_subop *subop,
-                               unsigned int op_id);
-int nand_subop_get_data_start_off(const struct nand_subop *subop,
-                                 unsigned int op_id);
-int nand_subop_get_data_len(const struct nand_subop *subop,
-                           unsigned int op_id);
+unsigned int nand_subop_get_addr_start_off(const struct nand_subop *subop,
+                                          unsigned int op_id);
+unsigned int nand_subop_get_num_addr_cyc(const struct nand_subop *subop,
+                                        unsigned int op_id);
+unsigned int nand_subop_get_data_start_off(const struct nand_subop *subop,
+                                          unsigned int op_id);
+unsigned int nand_subop_get_data_len(const struct nand_subop *subop,
+                                    unsigned int op_id);
 
 /**
  * struct nand_op_parser_addr_constraints - Constraints for address instructions