Skip to content

Commit

Permalink
mtd: rawnand: arasan: Provide an additional ->exec_op() check
Browse files Browse the repository at this point in the history
The controller only supports data payload requests which are multiple of 4.
Rounding up will not work if we reached the end of the device and the
controller will just refuse the request. Hence any unaligned data request
that ends at the device boundary should be refused.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Signed-off-by: Amit Kumar Mahapatra <amit.kumar-mahapatra@xilinx.com>
  • Loading branch information
miquelraynal authored and michalsimek committed Jul 11, 2022
1 parent 47b9437 commit 6ced49c
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions drivers/mtd/nand/raw/arasan-nand-controller.c
Expand Up @@ -891,6 +891,7 @@ static const struct nand_op_parser anfc_op_parser = NAND_OP_PARSER(
static int anfc_check_op(struct nand_chip *chip,
const struct nand_operation *op)
{
struct mtd_info *mtd = nand_to_mtd(chip);
const struct nand_op_instr *instr;
int op_id;

Expand Down Expand Up @@ -940,6 +941,35 @@ static int anfc_check_op(struct nand_chip *chip,
op->instrs[1].type == NAND_OP_DATA_IN_INSTR)
return -ENOTSUPP;

/*
* The controller only supports data payload requests which are a
* multiple of 4. This may confuse the core as the core could request a
* given number of bytes and then another number of bytes without
* re-synchronizing the pointer. In practice, most data accesses are
* 4-byte aligned and thus this is not an issue in practice. However,
* rounding up will not work if we reached the end of the device. Any
* unaligned data request that ends at the device boundary would confuse
* the controller and cannot be performed.
*
* TODO: The nand_op_parser framework should be extended to
* support custom checks on DATA instructions.
*/
if (op->ninstrs == 4 &&
op->instrs[0].type == NAND_OP_CMD_INSTR &&
op->instrs[1].type == NAND_OP_ADDR_INSTR &&
op->instrs[1].ctx.addr.naddrs == 2 &&
op->instrs[2].type == NAND_OP_CMD_INSTR &&
op->instrs[3].type == NAND_OP_DATA_IN_INSTR) {
unsigned int start_off, end_off;

start_off = (op->instrs[1].ctx.addr.addrs[1] << 8) +
op->instrs[1].ctx.addr.addrs[0];
end_off = start_off + round_up(op->instrs[3].ctx.data.len, 4);

if (end_off >= mtd->writesize + mtd->oobsize)
return -ENOTSUPP;
}

return nand_op_parser_exec_op(chip, &anfc_op_parser, op, true);
}

Expand Down

0 comments on commit 6ced49c

Please sign in to comment.