Linux-mtd Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Huang Shijie <shijie.huang@intel.com>
To: "Rafał Miłecki" <zajec5@gmail.com>
Cc: Bean Huo <beanhuo@micron.com>,
	Brian Norris <computersforpeace@gmail.com>,
	linux-mtd@lists.infradead.org,
	David Woodhouse <David.Woodhouse@intel.com>,
	Artem Bityutskiy <dedekind1@gmail.com>
Subject: Re: [PATCH V2] mtd: spi-nor: prefer more specific entries from chips database
Date: Fri, 7 Nov 2014 09:21:15 +0800	[thread overview]
Message-ID: <20141107012115.GA28978@shldeISGChi005.sh.intel.com> (raw)
In-Reply-To: <1415257333-6488-1-git-send-email-zajec5@gmail.com>

On Thu, Nov 06, 2014 at 08:02:13AM +0100, Rafał Miłecki wrote:
> With two entries sharing first ID bytes but one of them having more of
> them, we should prefer the more specific one. Consider following:
> 1) n25q128a11 with ID 0x20bb18
> 2) n25q128a13 with ID 0x20bb181234
> we should prefer entry with the longer ID.
I perfer to make a limit before we add new item to the table:
    Put the longest one in the first place.

By this way, we can avoid the too much "for"s in the following code
which makes the code a little complicated.
 
So It should looks like this in the table.     
  1) n25q128a13 with ID 0x20bb181234
  2) n25q128a11 with ID 0x20bb18

Hi Brian, what's your opinion?
  
thanks
Huang Shijie
> 
> Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
> Cc: Bean Huo <beanhuo@micron.com>
> Cc: Huang Shijie <shijie.huang@intel.com>
> ---
> V2: Rebase on top of Huang patches
> ---
>  drivers/mtd/spi-nor/spi-nor.c | 14 ++++++++++----
>  1 file changed, 10 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
> index 209e701..80e333f 100644
> --- a/drivers/mtd/spi-nor/spi-nor.c
> +++ b/drivers/mtd/spi-nor/spi-nor.c
> @@ -667,6 +667,7 @@ static const struct spi_device_id *spi_nor_read_id(struct spi_nor *nor)
>  	int			tmp;
>  	u8			id[SPI_NOR_MAX_ID_LEN];
>  	struct flash_info	*info;
> +	u8			len;
>  
>  	tmp = nor->read_reg(nor, SPINOR_OP_RDID, id, SPI_NOR_MAX_ID_LEN);
>  	if (tmp < 0) {
> @@ -674,10 +675,15 @@ static const struct spi_device_id *spi_nor_read_id(struct spi_nor *nor)
>  		return ERR_PTR(tmp);
>  	}
>  
> -	for (tmp = 0; tmp < ARRAY_SIZE(spi_nor_ids) - 1; tmp++) {
> -		info = (void *)spi_nor_ids[tmp].driver_data;
> -		if (info->id_len) {
> -			if (!memcmp(info->id, id, info->id_len))
> +	/*
> +	 * Start looking for entries with the longest ID, then go to the less
> +	 * specific ones.
> +	 */
> +	for (len = SPI_NOR_MAX_ID_LEN; len > 0; len--) {
> +		for (tmp = 0; tmp < ARRAY_SIZE(spi_nor_ids) - 1; tmp++) {
> +			info = (void *)spi_nor_ids[tmp].driver_data;
> +			if (info->id_len == len &&
> +			    !memcmp(info->id, id, info->id_len))
>  				return &spi_nor_ids[tmp];
>  		}
>  	}
> -- 
> 1.8.4.5
> 

  reply	other threads:[~2014-11-07  1:21 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-22  7:33 [PATCH] mtd: spi-nor: prefer more specific entries from chips database Rafał Miłecki
2014-11-06  7:02 ` [PATCH V2] " Rafał Miłecki
2014-11-07  1:21   ` Huang Shijie [this message]
2014-11-07  1:49     ` Bean Huo 霍斌斌 (beanhuo)
2014-11-07  2:06       ` Huang Shijie
2014-11-07  2:26         ` Bean Huo 霍斌斌 (beanhuo)

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=20141107012115.GA28978@shldeISGChi005.sh.intel.com \
    --to=shijie.huang@intel.com \
    --cc=David.Woodhouse@intel.com \
    --cc=beanhuo@micron.com \
    --cc=computersforpeace@gmail.com \
    --cc=dedekind1@gmail.com \
    --cc=linux-mtd@lists.infradead.org \
    --cc=zajec5@gmail.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