Skip to content

Commit e253242

Browse files
committed
mtd: rawnand: qcom: Fix address parsing within ->exec_op()
The naddrs variable is initialized but not used. Fixing this could have been a matter of dropping the variable, but the right way to do it looks a bit more complex: we can avoid useless writes to the q_op structure by using it. In practice we could even have possible out-of-bound bugs with the existing implementation. Let's fix all that by just performing the right number of assignments in the addr{1,2}_reg fields. Fixes: 89550be ("mtd: rawnand: qcom: Implement exec_op()") Reported-by: kernel test robot <lkp@intel.com> Closes: https://lore.kernel.org/oe-kbuild-all/202307131959.PdPSC86K-lkp@intel.com/ Closes: https://lore.kernel.org/oe-kbuild-all/202307131730.NOYbcjBr-lkp@intel.com/ Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> Acked-by: Manivannan Sadhasivam <mani@kernel.org> Reviewed-by: Tudor Ambarus <tudor.ambarus@linaro.org> Link: https://lore.kernel.org/linux-mtd/20230716144612.32132-9-miquel.raynal@bootlin.com
1 parent e260efe commit e253242

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

drivers/mtd/nand/raw/qcom_nandc.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2616,12 +2616,13 @@ static void qcom_parse_instructions(struct nand_chip *chip,
26162616
offset = nand_subop_get_addr_start_off(subop, op_id);
26172617
naddrs = nand_subop_get_num_addr_cyc(subop, op_id);
26182618
addrs = &instr->ctx.addr.addrs[offset];
2619-
for (i = 0; i < MAX_ADDRESS_CYCLE; i++) {
2620-
if (i < 4)
2621-
q_op->addr1_reg |= (u32)addrs[i] << i * 8;
2622-
else
2623-
q_op->addr2_reg |= addrs[i];
2624-
}
2619+
2620+
for (i = 0; i < min_t(unsigned int, 4, naddrs); i++)
2621+
q_op->addr1_reg |= addrs[i] << (i * 8);
2622+
2623+
if (naddrs > 4)
2624+
q_op->addr2_reg |= addrs[4];
2625+
26252626
q_op->rdy_delay_ns = instr->delay_ns;
26262627
break;
26272628

0 commit comments

Comments
 (0)