public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
From: Boris Brezillon <boris.brezillon@free-electrons.com>
To: Peter Pan <peterpandong@micron.com>
Cc: <richard@nod.at>, <computersforpeace@gmail.com>,
	<arnaud.mouiche@gmail.com>, <thomas.petazzoni@free-electrons.com>,
	<linux-mtd@lists.infradead.org>, <peterpansjtu@gmail.com>,
	<linshunquan1@hisilicon.com>
Subject: Re: [PATCH v3 1/8] mtd: nand: add more helpers in nand.h
Date: Fri, 17 Mar 2017 14:07:50 +0100	[thread overview]
Message-ID: <20170317140750.463d1d32@bbrezillon> (raw)
In-Reply-To: <1489646857-10112-2-git-send-email-peterpandong@micron.com>

On Thu, 16 Mar 2017 14:47:30 +0800
Peter Pan <peterpandong@micron.com> wrote:

> This commit adds some helpers in nand.h
>     nand_size()
>     valid_nand_address()
>     valid_nand_oob_ops()
>     nand_oob_ops_across_page()
>     valid_nand_erase_ops()
> 
> Signed-off-by: Peter Pan <peterpandong@micron.com>
> ---
>  include/linux/mtd/nand.h | 59 ++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 59 insertions(+)
> 
> diff --git a/include/linux/mtd/nand.h b/include/linux/mtd/nand.h
> index c2197b4..4a812e6 100644
> --- a/include/linux/mtd/nand.h
> +++ b/include/linux/mtd/nand.h
> @@ -410,6 +410,65 @@ static inline int nand_neraseblocks(struct nand_device *nand)
>  }
>  
>  /**
> + * nand_size - Get NAND size
> + * @nand: NAND device
> + *
> + * Returns the total size exposed by @nand.
> + */
> +static inline u64 nand_size(struct nand_device *nand)
> +{
> +	return nand->memorg.ndies * nand->memorg.diesize;
> +}
> +
> +static inline bool valid_nand_address(struct nand_device *nand, loff_t addr)

Please keep consistent prefixes. Maybe we should name it
nand_check_address(), return -EINVAL if it's wrong and 0 otherwise:

static inline int nand_check_address(struct nand_device *nand,
				     loff_t addr)
{
	return addr < nand_size(nand) ? 0 : -EINVAL;
}

> +{
> +	return addr < nand_size(nand);
> +}
> +
> +static inline bool valid_nand_oob_ops(struct nand_device *nand, loff_t start,
> +				      struct mtd_oob_ops *ops)
> +{
> +	struct mtd_info *mtd = nand_to_mtd(nand);
> +	int ooblen = ops->mode == MTD_OPS_AUTO_OOB ?
> +		mtd->oobavail : mtd->oobsize;
> +
> +	if (ops->ooboffs >= ooblen)
> +		return false;
> +	if (ops->ooboffs + ops->ooblen >
> +	    (nand_len_to_pages(nand, nand_size(nand)) -
> +			       nand_offs_to_page(nand, start)) * ooblen)
> +		return false;
> +
> +	return true;
> +}

Ditto.

> +
> +static inline bool nand_oob_ops_across_page(struct nand_device *nand,
> +					    struct mtd_oob_ops *ops)
> +{
> +	struct mtd_info *mtd = nand_to_mtd(nand);
> +	int ooblen = ops->mode == MTD_OPS_AUTO_OOB ?
> +		     mtd->oobavail : mtd->oobsize;
> +
> +	return (ops->ooboffs + ops->ooblen) > ooblen;
> +}
> +
> +static inline bool valid_nand_erase_ops(struct nand_device *nand,
> +					struct erase_info *einfo)

Ditto.

> +{
> +	/* check address align on block boundary */
> +	if (einfo->addr & (nand_eraseblock_size(nand) - 1))
> +		return false;
> +	/* check lendth align on block boundary */
> +	if (einfo->len & (nand_eraseblock_size(nand) - 1))
> +		return false;
> +	/* Do not allow erase past end of device */
> +	if ((einfo->addr + einfo->len) > nand_size(nand))
> +		return false;
> +
> +	return true;
> +}
> +
> +/**
>   * nand_register - Register a NAND device
>   * @nand: NAND device
>   *

  reply	other threads:[~2017-03-17 13:08 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-16  6:47 [PATCH v3 0/8] Introduction to SPI NAND framework Peter Pan
2017-03-16  6:47 ` [PATCH v3 1/8] mtd: nand: add more helpers in nand.h Peter Pan
2017-03-17 13:07   ` Boris Brezillon [this message]
2017-03-20  4:51     ` Peter Pan
2017-03-16  6:47 ` [PATCH v3 2/8] mtd: nand: add oob iterator in nand_for_each_page Peter Pan
2017-03-17 13:11   ` Boris Brezillon
2017-03-20  4:52     ` Peter Pan
2017-03-16  6:47 ` [PATCH v3 3/8] nand: spi: add basic blocks for infrastructure Peter Pan
2017-03-16  9:55   ` Boris Brezillon
2017-03-17  5:45     ` Peter Pan
2017-03-17 10:20   ` Arnaud Mouiche
2017-03-17 10:22     ` Peter Pan
2017-03-17 13:38   ` Boris Brezillon
2017-03-20  4:55     ` Peter Pan
2017-03-16  6:47 ` [PATCH v3 4/8] nand: spi: add basic operations support Peter Pan
2017-03-17 10:33   ` Arnaud Mouiche
2017-03-17 10:49     ` Peter Pan
2017-03-17 11:02       ` Boris Brezillon
2017-03-17 11:09         ` Peter Pan
2017-03-17 11:12           ` Boris Brezillon
2017-03-17 11:18             ` Peter Pan
2017-03-16  6:47 ` [PATCH v3 5/8] nand: spi: Add bad block support Peter Pan
2017-03-17 12:22   ` Arnaud Mouiche
2017-03-17 12:31     ` Boris Brezillon
2017-03-20  4:49       ` Peter Pan
2017-03-16  6:47 ` [PATCH v3 6/8] nand: spi: add Micron spi nand support Peter Pan
2017-03-16  6:47 ` [PATCH v3 7/8] nand: spi: Add generic SPI controller support Peter Pan
2017-03-17 14:20   ` Boris Brezillon
2017-03-17 17:32     ` Arnaud Mouiche
2017-03-17 17:48       ` Boris Brezillon
2017-03-20  4:58         ` Peter Pan
2017-03-20  5:56           ` Boris Brezillon
2017-03-20  7:15             ` Peter Pan
2017-03-16  6:47 ` [PATCH v3 8/8] MAINTAINERS: Add SPI NAND entry Peter Pan
2017-03-17 10:02 ` [PATCH v3 0/8] Introduction to SPI NAND framework Arnaud Mouiche
2017-03-17 10:34   ` Peter Pan

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=20170317140750.463d1d32@bbrezillon \
    --to=boris.brezillon@free-electrons.com \
    --cc=arnaud.mouiche@gmail.com \
    --cc=computersforpeace@gmail.com \
    --cc=linshunquan1@hisilicon.com \
    --cc=linux-mtd@lists.infradead.org \
    --cc=peterpandong@micron.com \
    --cc=peterpansjtu@gmail.com \
    --cc=richard@nod.at \
    --cc=thomas.petazzoni@free-electrons.com \
    /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