Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp50440imu; Thu, 8 Nov 2018 04:55:37 -0800 (PST) X-Google-Smtp-Source: AJdET5et5Ao6gARkSQwZRdhqq2cfU0FltWmqTJ5W/SCpgS9SqjpzgOZB0/mDN6C/RdgE8q5VBIKE X-Received: by 2002:a63:ce08:: with SMTP id y8mr3668875pgf.388.1541681737156; Thu, 08 Nov 2018 04:55:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541681737; cv=none; d=google.com; s=arc-20160816; b=nJ/JiGCz1Jqe3RRSx9EukoF9M+wi7WRNNfvLpftDbL4lttHOQSj953ClFmqlFGlAD1 zETah2uPyEnbT2/10SBu9wtybUzJsh3lV5Q9HaZ7BlCwuL4ZyLrvmfC1+jhqsNxAQrNr V026EKCBYYztGKgKSph6va8v3lXdJi15DhcROjeJXyBNswOaEvoYzyr0rpp3tluxOB5J x9SxrqmELoD9pOy3ZgICijZc6rzZ0c/+9pfZrOoOA3+ovWQTVNv8C4opUSeKR8ZWRyCM 3VjRaJuJj8gKuLwa0WqRZeIZT9plMLlhBzyb4HhWN9dZEIAKUYsoYyVOcBy/rEbqNseD VXWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=KLNqD+f3OhPxDQnesoYAUZCKfjZ0+GgxXCJfff287Qo=; b=u6InrqoIiIMvh2SgMYR0T5J24LEg5F7IEt2tGdpBXD9Idkem9KQOGHAfKSjPAKkj9j g+3j8GE9kY3dcEji/ZAh/9Exf/LRctW24tQVwy/zseigL4UbHeIXRVUlgQvaQNu0/+Lo rdOZ3OY1eKuIBbG/fROPQWlhmOR1S9FbjWEPBN3Mc6vExjbRKkjXG8RdAI68XOrGP+I9 9sOdrkJjRpXJpEJmaXqM19m+Fj38fWg+tYyApqNmtdw4hKbGQMoibFApI69YEAmn1DOI JU+tpDpcZouszxCxOusCHU8nxRyVvAgDHghjzyHh9Du6Vx85hKkaZ1eM5T43bWfvu1rJ X30Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id gn6si4024684plb.321.2018.11.08.04.55.21; Thu, 08 Nov 2018 04:55:37 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726926AbeKHWaW (ORCPT + 99 others); Thu, 8 Nov 2018 17:30:22 -0500 Received: from mail.bootlin.com ([62.4.15.54]:36920 "EHLO mail.bootlin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726781AbeKHWaW (ORCPT ); Thu, 8 Nov 2018 17:30:22 -0500 Received: by mail.bootlin.com (Postfix, from userid 110) id 4920E224CF; Thu, 8 Nov 2018 13:54:58 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mail.bootlin.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT, URIBL_BLOCKED shortcircuit=ham autolearn=disabled version=3.4.2 Received: from bbrezillon (aaubervilliers-681-1-30-49.w90-88.abo.wanadoo.fr [90.88.15.49]) by mail.bootlin.com (Postfix) with ESMTPSA id EB13B224CC; Thu, 8 Nov 2018 13:54:47 +0100 (CET) Date: Thu, 8 Nov 2018 13:54:47 +0100 From: Boris Brezillon To: Cc: , , , , , , , Subject: Re: [PATCH 3/7] mtd: spi-nor: add restriction for nmaps in smpt parser Message-ID: <20181108135447.36a0314c@bbrezillon> In-Reply-To: <20181108110653.21063-4-tudor.ambarus@microchip.com> References: <20181108110653.21063-1-tudor.ambarus@microchip.com> <20181108110653.21063-4-tudor.ambarus@microchip.com> X-Mailer: Claws Mail 3.16.0 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 8 Nov 2018 11:07:11 +0000 wrote: > The map selector is limited to a maximum of 8 bits, allowing > for a maximum of 256 possible map configurations. The total > number of map configurations should be addressable by the > total number of bits described by the detection commands. > > For example: if there are five to eight possible sector map > configurations, at least three configuration detection commands > will be needed to extract three bits of configuration selection > information from the device in order to identify which configuration > is currently in use. > > Suggested-by: Boris Brezillon I don't remember suggesting this :-). > Signed-off-by: Tudor Ambarus > --- > drivers/mtd/spi-nor/spi-nor.c | 15 +++++++++++++-- > 1 file changed, 13 insertions(+), 2 deletions(-) > > diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c > index 59dcedb08691..bd1866d714f2 100644 > --- a/drivers/mtd/spi-nor/spi-nor.c > +++ b/drivers/mtd/spi-nor/spi-nor.c > @@ -2868,7 +2868,7 @@ static const u32 *spi_nor_get_map_in_use(struct spi_nor *nor, const u32 *smpt, > const u32 *ret = NULL; > u32 addr; > int err; > - u8 i; > + u8 i, ncmds, nmaps; > u8 addr_width, read_opcode, read_dummy; > u8 read_data_mask, data_byte, map_id; > > @@ -2877,6 +2877,7 @@ static const u32 *spi_nor_get_map_in_use(struct spi_nor *nor, const u32 *smpt, > read_opcode = nor->read_opcode; > > map_id = 0; > + ncmds = 0; > /* Determine if there are any optional Detection Command Descriptors */ > for (i = 0; i < smpt_len; i += 2) { > if (smpt[i] & SMPT_DESC_TYPE_MAP) > @@ -2896,6 +2897,7 @@ static const u32 *spi_nor_get_map_in_use(struct spi_nor *nor, const u32 *smpt, > * Configuration that is currently in use. > */ > map_id = map_id << 1 | !!(data_byte & read_data_mask); > + ncmds++; > } > > /* > @@ -2905,7 +2907,16 @@ static const u32 *spi_nor_get_map_in_use(struct spi_nor *nor, const u32 *smpt, > * > * Find the matching configuration map. > */ > - while (i < smpt_len) { > + for (nmaps = 0; i < smpt_len; nmaps++) { > + /* > + * The map selector is limited to a maximum of 8 bits, allowing > + * for a maximum of 256 possible map configurations. The total > + * number of map configurations should be addressable by the > + * total number of bits described by the detection commands. > + */ > + if (ncmds && nmaps >= (1 << (ncmds + 1))) > + break; > + Maybe I missed something but it sounds like this change is just optimizing the SPMT parsing a bit, and to be honest, I'm not sure this is really needed. Most of the time, smpt_len will be rather small, so trying to bail out earlier is not bringing much perf improvements. > if (SMPT_MAP_ID(smpt[i]) == map_id) { > ret = smpt + i; > break;