linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: boris.brezillon@free-electrons.com (Boris Brezillon)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 3/3] mtd: nand: sunxi: fix subpage write
Date: Mon, 6 Jun 2016 14:07:09 +0200	[thread overview]
Message-ID: <20160606140709.614bbb04@bbrezillon> (raw)
In-Reply-To: <1465214354-31493-4-git-send-email-boris.brezillon@free-electrons.com>

On Mon,  6 Jun 2016 13:59:14 +0200
Boris Brezillon <boris.brezillon@free-electrons.com> wrote:

Oops, I forgot to add this commit message:

"
Implement ecc->write_subpage() to prevent core code from assigning
this hook to nand_write_subpage_hwecc(). This default implementation
tries to call ecc->hwctl() which in our case is NULL, thus leading
to a NULL pointer dereference.
"

> Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
> ---
>  drivers/mtd/nand/sunxi_nand.c | 33 ++++++++++++++++++++++++++++++++-
>  1 file changed, 32 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/mtd/nand/sunxi_nand.c b/drivers/mtd/nand/sunxi_nand.c
> index 252cbbf..409acbe 100644
> --- a/drivers/mtd/nand/sunxi_nand.c
> +++ b/drivers/mtd/nand/sunxi_nand.c
> @@ -1350,6 +1350,36 @@ static int sunxi_nfc_hw_ecc_write_page(struct mtd_info *mtd,
>  	return 0;
>  }
>  
> +static int sunxi_nfc_hw_ecc_write_subpage(struct mtd_info *mtd,
> +					  struct nand_chip *chip,
> +					  u32 data_offs, u32 data_len,
> +					  const u8 *buf, int oob_required,
> +					  int page)
> +{
> +	struct nand_ecc_ctrl *ecc = &chip->ecc;
> +	int ret, i, cur_off = 0;
> +
> +	sunxi_nfc_hw_ecc_enable(mtd);
> +
> +	for (i = data_offs / ecc->size;
> +	     i < DIV_ROUND_UP(data_offs + data_len, ecc->size); i++) {
> +		int data_off = i * ecc->size;
> +		int oob_off = i * (ecc->bytes + 4);
> +		const u8 *data = buf + data_off;
> +		const u8 *oob = chip->oob_poi + oob_off;
> +
> +		ret = sunxi_nfc_hw_ecc_write_chunk(mtd, data, data_off, oob,
> +						   oob_off + mtd->writesize,
> +						   &cur_off, !i, page);
> +		if (ret)
> +			return ret;
> +	}
> +
> +	sunxi_nfc_hw_ecc_disable(mtd);
> +
> +	return 0;
> +}
> +
>  static int sunxi_nfc_hw_ecc_write_page_dma(struct mtd_info *mtd,
>  					   struct nand_chip *chip,
>  					   const u8 *buf,
> @@ -1862,7 +1892,8 @@ static int sunxi_nand_hw_ecc_ctrl_init(struct mtd_info *mtd,
>  		ecc->write_page = sunxi_nfc_hw_ecc_write_page;
>  	}
>  
> -	/* TODO: support DMA for raw accesses */
> +	/* TODO: support DMA for raw accesses and subpage write */
> +	ecc->write_subpage = sunxi_nfc_hw_ecc_write_subpage;
>  	ecc->read_oob_raw = nand_read_oob_std;
>  	ecc->write_oob_raw = nand_write_oob_std;
>  	ecc->read_subpage = sunxi_nfc_hw_ecc_read_subpage;



-- 
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

  reply	other threads:[~2016-06-06 12:07 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-06 11:59 [PATCH 0/3] mtd: nand: sunxi: fix SLC NAND support Boris Brezillon
2016-06-06 11:59 ` [PATCH 1/3] mtd: nand: sunxi: prefer 1k ECC blocks when applicable Boris Brezillon
2016-06-06 11:59 ` [PATCH 2/3] mtd: nand: sunxi: check ecc->size values Boris Brezillon
2016-06-06 11:59 ` [PATCH 3/3] mtd: nand: sunxi: fix subpage write Boris Brezillon
2016-06-06 12:07   ` Boris Brezillon [this message]
2016-06-20 11:52 ` [PATCH 0/3] mtd: nand: sunxi: fix SLC NAND support Boris Brezillon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160606140709.614bbb04@bbrezillon \
    --to=boris.brezillon@free-electrons.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).