Skip to content

Commit dd3c8f4

Browse files
Mani-Sadhasivammiquelraynal
authored andcommitted
mtd: rawnand: qcom: Handle unsupported opcode in qcom_op_cmd_mapping()
Handle the scenario where the caller has passed an unsupported opcode to qcom_op_cmd_mapping(). In that case, log the error and return the -EOPNOTSUPP errono. Also, let's propagate this error code all the way up. This also fixes the following smatch warning: drivers/mtd/nand/raw/qcom_nandc.c:2941 qcom_op_cmd_mapping() error: uninitialized symbol 'ret'. Reported-by: kernel test robot <lkp@intel.com> Reported-by: Dan Carpenter <dan.carpenter@linaro.org> Closes: https://lore.kernel.org/r/202308032022.SnXkKyFs-lkp@intel.com/ Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> Link: https://lore.kernel.org/linux-mtd/20230805174146.57006-4-manivannan.sadhasivam@linaro.org
1 parent d68b7e5 commit dd3c8f4

1 file changed

Lines changed: 27 additions & 8 deletions

File tree

drivers/mtd/nand/raw/qcom_nandc.c

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2585,20 +2585,23 @@ static int qcom_op_cmd_mapping(struct qcom_nand_controller *nandc, u8 opcode,
25852585
q_op->flag = OP_PROGRAM_PAGE;
25862586
nandc->exec_opwrite = true;
25872587
break;
2588+
default:
2589+
dev_err(nandc->dev, "Opcode not supported: %u\n", opcode);
2590+
return -EOPNOTSUPP;
25882591
}
25892592

25902593
return cmd;
25912594
}
25922595

25932596
/* NAND framework ->exec_op() hooks and related helpers */
2594-
static void qcom_parse_instructions(struct nand_chip *chip,
2597+
static int qcom_parse_instructions(struct nand_chip *chip,
25952598
const struct nand_subop *subop,
25962599
struct qcom_op *q_op)
25972600
{
25982601
struct qcom_nand_controller *nandc = get_qcom_nand_controller(chip);
25992602
const struct nand_op_instr *instr = NULL;
26002603
unsigned int op_id;
2601-
int i;
2604+
int i, ret;
26022605

26032606
for (op_id = 0; op_id < subop->ninstrs; op_id++) {
26042607
unsigned int offset, naddrs;
@@ -2608,7 +2611,11 @@ static void qcom_parse_instructions(struct nand_chip *chip,
26082611

26092612
switch (instr->type) {
26102613
case NAND_OP_CMD_INSTR:
2611-
q_op->cmd_reg = qcom_op_cmd_mapping(nandc, instr->ctx.cmd.opcode, q_op);
2614+
ret = qcom_op_cmd_mapping(nandc, instr->ctx.cmd.opcode, q_op);
2615+
if (ret < 0)
2616+
return ret;
2617+
2618+
q_op->cmd_reg = ret;
26122619
q_op->rdy_delay_ns = instr->delay_ns;
26132620
break;
26142621

@@ -2641,6 +2648,8 @@ static void qcom_parse_instructions(struct nand_chip *chip,
26412648
break;
26422649
}
26432650
}
2651+
2652+
return 0;
26442653
}
26452654

26462655
static void qcom_delay_ns(unsigned int ns)
@@ -2689,7 +2698,9 @@ static int qcom_read_status_exec(struct nand_chip *chip,
26892698

26902699
host->status = NAND_STATUS_READY | NAND_STATUS_WP;
26912700

2692-
qcom_parse_instructions(chip, subop, &q_op);
2701+
ret = qcom_parse_instructions(chip, subop, &q_op);
2702+
if (ret)
2703+
return ret;
26932704

26942705
num_cw = nandc->exec_opwrite ? ecc->steps : 1;
26952706
nandc->exec_opwrite = false;
@@ -2749,7 +2760,9 @@ static int qcom_read_id_type_exec(struct nand_chip *chip, const struct nand_subo
27492760
unsigned int len = 0;
27502761
int ret;
27512762

2752-
qcom_parse_instructions(chip, subop, &q_op);
2763+
ret = qcom_parse_instructions(chip, subop, &q_op);
2764+
if (ret)
2765+
return ret;
27532766

27542767
nandc->buf_count = 0;
27552768
nandc->buf_start = 0;
@@ -2797,7 +2810,9 @@ static int qcom_misc_cmd_type_exec(struct nand_chip *chip, const struct nand_sub
27972810
struct qcom_op q_op = {};
27982811
int ret;
27992812

2800-
qcom_parse_instructions(chip, subop, &q_op);
2813+
ret = qcom_parse_instructions(chip, subop, &q_op);
2814+
if (ret)
2815+
return ret;
28012816

28022817
if (q_op.flag == OP_PROGRAM_PAGE)
28032818
goto wait_rdy;
@@ -2843,7 +2858,9 @@ static int qcom_param_page_type_exec(struct nand_chip *chip, const struct nand_
28432858
unsigned int len = 0;
28442859
int ret;
28452860

2846-
qcom_parse_instructions(chip, subop, &q_op);
2861+
ret = qcom_parse_instructions(chip, subop, &q_op);
2862+
if (ret)
2863+
return ret;
28472864

28482865
q_op.cmd_reg |= PAGE_ACC | LAST_PAGE;
28492866

@@ -2937,7 +2954,9 @@ static int qcom_erase_cmd_type_exec(struct nand_chip *chip, const struct nand_su
29372954
struct qcom_op q_op = {};
29382955
int ret;
29392956

2940-
qcom_parse_instructions(chip, subop, &q_op);
2957+
ret = qcom_parse_instructions(chip, subop, &q_op);
2958+
if (ret)
2959+
return ret;
29412960

29422961
q_op.cmd_reg |= PAGE_ACC | LAST_PAGE;
29432962

0 commit comments

Comments
 (0)