Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp825744pxb; Tue, 12 Apr 2022 14:31:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzoPSusSyktuPXX0qowvUcYlE/SC2VMlvz8RKOOL94rVDhOznHhxTuNp8jaukGnr34367xx X-Received: by 2002:a17:902:9b98:b0:156:52b1:b100 with SMTP id y24-20020a1709029b9800b0015652b1b100mr39472013plp.174.1649799111876; Tue, 12 Apr 2022 14:31:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649799111; cv=none; d=google.com; s=arc-20160816; b=Z1hxXYAJG6S2W84RNTa5BuiOYEuhhYVGJasHvcBMQo8q6KSgYKPSC7JGpMN/F+kMCx FqORRxXZb4C0bdT+2Msk1mwyaw+utX6FkskRFyRez8/GR4N3+7ZxIaVaAdxIfdqqV7vk 6wYCA5/xqKIo52mb/bj4KcIMBf8a1Vi8vGmZGoZVIJvmT+ag/78UuXkcP8nK9gihYluN B7yNuLaaSZpAoMB8Z8hlekhX2t+iScLLPyJ7UwagOB5Md4ZTbcFTwHtsg5MC3U1G+36S P6zQ2zB4GT+U6SAkvJknhSz2kjXT+ojqrQlMAX4QuTONyIxUptajCTrQmUbJyXgI7pub vQSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Bu2LjqpkXGgQDyRf9r7sGdO8/MAeashIO4Y5Qd+KtlM=; b=b4lqzFWD30cGDRbAY6XOO0+gomjT7/GY2Oppm3cgIDuI3uupFyhnh3+KX59GOEsd4U mr0diqK/AGZ+O6M5S4gNu8iEr9U0zOXFgsJufPWeeKFji/sIpt65XSNaCg4cwoULzUph +szOhfj4sHi7Gg9nn9QTJtIikOkCkHLAKBiCZjtfHUztSnPx9atCQp3MBYtU6BC/ggdo QjxKUm2R9r7JY1UMg47Bc8iXA+SAAiBTviCkBuROCWpYSruhv+5PaHRP1iS/HIF/GZ/N xPdCmp8Uw2WBSH3Oq1UhE3coivif75LZQVfhm0NajjrxD0Ju8Xkx+cweW1AskrVHHXRM T5AQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@microchip.com header.s=mchp header.b="Zdy2j/5J"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id m2-20020a654c82000000b003816043ef50si4099392pgt.325.2022.04.12.14.31.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Apr 2022 14:31:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=fail header.i=@microchip.com header.s=mchp header.b="Zdy2j/5J"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 02F9DB2472; Tue, 12 Apr 2022 13:38:48 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344219AbiDKJNC (ORCPT + 99 others); Mon, 11 Apr 2022 05:13:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344192AbiDKJM5 (ORCPT ); Mon, 11 Apr 2022 05:12:57 -0400 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D0C7286D5 for ; Mon, 11 Apr 2022 02:10:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1649668244; x=1681204244; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=l502uYE2TnP3MLFemsdwebdVBuL3o2Hjtc5LM+PWKJg=; b=Zdy2j/5JQ2K6xwL/TNIH7cAZnFDq25e6G9Ijqs2X8qwLStRyOOU+HERW 24zSeltiJENJtCSoPJAkQiGvG0Y62iopi/eG6M/03RqN8QE/2/P+wEHBQ irYens3gd9CUZiOEOI+9Uv1cdwmVQp8gr7/3iNVDlik1KDt5IBpFZ8O7p 93w3O7yBK6rFZGX0nEOo4JOm1Q3AXYIS1zFproZ5NtSBB/irdEsExDv9j DlrWNsBuSgmFEH9jhoJW7cvZfj6uzgxirdLrItwL9SGIQ8X2T4RYo3E5V FtFvfCj0FwhLcy09c95KPI+ZKBW/nDahP+P01K2hGMgMMa2//nqnnUIxe g==; X-IronPort-AV: E=Sophos;i="5.90,251,1643698800"; d="scan'208";a="159624234" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa5.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 11 Apr 2022 02:10:44 -0700 Received: from chn-vm-ex04.mchp-main.com (10.10.85.152) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Mon, 11 Apr 2022 02:10:43 -0700 Received: from ROB-ULT-M18064N.mchp-main.com (10.10.115.15) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server id 15.1.2375.17 via Frontend Transport; Mon, 11 Apr 2022 02:10:41 -0700 From: Tudor Ambarus To: , CC: , , , , , , Tudor Ambarus Subject: [PATCH v3 2/9] mtd: spi-nor: Introduce spi_nor_match_id() Date: Mon, 11 Apr 2022 12:10:26 +0300 Message-ID: <20220411091033.98754-3-tudor.ambarus@microchip.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220411091033.98754-1-tudor.ambarus@microchip.com> References: <20220411091033.98754-1-tudor.ambarus@microchip.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Similar to spi_nor_match_name() extend the search of flash_info through all the manufacturers, this time doing the match by ID. There's no reason to limit the search per manufacturer yet, do it globally, search the flash in all the parts of all manufacturers in a single method. Signed-off-by: Tudor Ambarus Reviewed-by: Pratyush Yadav Reviewed-by: Michael Walle --- v3: collect R-bs drivers/mtd/spi-nor/core.c | 40 ++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c index 214d3a1ac6b0..b9cc8bbf1f62 100644 --- a/drivers/mtd/spi-nor/core.c +++ b/drivers/mtd/spi-nor/core.c @@ -1629,16 +1629,21 @@ static const struct spi_nor_manufacturer *manufacturers[] = { &spi_nor_xmc, }; -static const struct flash_info * -spi_nor_search_part_by_id(const struct flash_info *parts, unsigned int nparts, - const u8 *id) +static const struct flash_info *spi_nor_match_id(struct spi_nor *nor, + const u8 *id) { - unsigned int i; + const struct flash_info *part; + unsigned int i, j; - for (i = 0; i < nparts; i++) { - if (parts[i].id_len && - !memcmp(parts[i].id, id, parts[i].id_len)) - return &parts[i]; + for (i = 0; i < ARRAY_SIZE(manufacturers); i++) { + for (j = 0; j < manufacturers[i]->nparts; j++) { + part = &manufacturers[i]->parts[j]; + if (part->id_len && + !memcmp(part->id, id, part->id_len)) { + nor->manufacturer = manufacturers[i]; + return part; + } + } } return NULL; @@ -1648,7 +1653,6 @@ static const struct flash_info *spi_nor_read_id(struct spi_nor *nor) { const struct flash_info *info; u8 *id = nor->bouncebuf; - unsigned int i; int ret; if (nor->spimem) { @@ -1668,19 +1672,13 @@ static const struct flash_info *spi_nor_read_id(struct spi_nor *nor) return ERR_PTR(ret); } - for (i = 0; i < ARRAY_SIZE(manufacturers); i++) { - info = spi_nor_search_part_by_id(manufacturers[i]->parts, - manufacturers[i]->nparts, - id); - if (info) { - nor->manufacturer = manufacturers[i]; - return info; - } + info = spi_nor_match_id(nor, id); + if (!info) { + dev_err(nor->dev, "unrecognized JEDEC id bytes: %*ph\n", + SPI_NOR_MAX_ID_LEN, id); + return ERR_PTR(-ENODEV); } - - dev_err(nor->dev, "unrecognized JEDEC id bytes: %*ph\n", - SPI_NOR_MAX_ID_LEN, id); - return ERR_PTR(-ENODEV); + return info; } static int spi_nor_read(struct mtd_info *mtd, loff_t from, size_t len, -- 2.25.1