From patchwork Fri Apr 12 13:44:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 1923146 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=qV3YwvZ7; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=kzndw7DQ; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VGHqs2M6yz1yYB for ; Fri, 12 Apr 2024 23:44:57 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=N0RCNDiK/6QYizix4N11AC6Se+iuZWE0Nl7AHHxRSeI=; b=qV3YwvZ7kEdBZG VTuTNizosRj9IwXXzsYrFw10pxE3arOstpMzUSiccbaknk7nDt9yqgtFXE8cYp7Upf3KYw9dcL39N DuXvDavVmft6ahGyHBWmKQ1k445bHlzwNlH6qaQOpp9YzjQ3YY/SDwqjU6QE7l736Mn1kv0WtABoS TqCHKOPExizpMGMOo1+91L6LjFuoUQLdVpZGgoEJ6Dqb1ibPvhSBlZXkNy9OE3PaBDdnMWAXV/k6a LkVeYUiqXQXonddzJmYKaQt6xpx+zmp6fhd/dHSl8RmZD9fHtjnngF4yNzPzQRhk8+I7hmmzNMerr q25FG9uaZa1EXit4MJ7A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rvHCr-0000000HOVF-2MJY; Fri, 12 Apr 2024 13:44:41 +0000 Received: from sin.source.kernel.org ([2604:1380:40e1:4800::1]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rvHCd-0000000HOK5-2xqc for linux-mtd@lists.infradead.org; Fri, 12 Apr 2024 13:44:30 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 04039CE3951; Fri, 12 Apr 2024 13:44:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E0450C2BD11; Fri, 12 Apr 2024 13:44:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712929465; bh=B7/0WXuNeHfB1kb629KPZ4FB30EU6w2b00Yh+4BqI5Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kzndw7DQL4qgxyf+i/F1X6Ux4uobIQIrrUahDYPKEe/uuUdQiwNY8rkMf8YlVuaKn BJaODhv1AMqazS3IfOT5wTTawOpqvif6YS31LOmMRqD3QKVELrlEWI0Y2W54NvubhU C4+X7gQz9EZhjd+Etq3YVBUUWNAReyN5bl8djIWSsasPto7Cj8/RSdy7K7LmYOh8BL F4aOZiroGwU4dYWR7Ia3chsHv8fsJUJDoDEYHz2Fox/8Dl7e4R1HlttvXeI0nmA2zZ edOMT2eWhJop6owo34F7zDkQir/C3uUzSpYGylF608I8UXURaH0Z9yinJIQHfOH/jO 6dz+CbrPEv+hQ== From: Michael Walle To: Tudor Ambarus , Pratyush Yadav , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra Cc: linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org, Michael Walle Subject: [PATCH v1 5/6] mtd: spi-nor: simplify spi_nor_get_flash_info() Date: Fri, 12 Apr 2024 15:44:04 +0200 Message-Id: <20240412134405.381832-6-mwalle@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240412134405.381832-1-mwalle@kernel.org> References: <20240412134405.381832-1-mwalle@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240412_064428_818547_70F1D5E8 X-CRM114-Status: GOOD ( 14.62 ) X-Spam-Score: -4.6 (----) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Rework spi_nor_get_flash_info() to make it look more straight forward and esp. don't return early. The latter is a preparation to check for deprecated flashes. Signed-off-by: Michael Walle --- drivers/mtd/spi-nor/core.c | 45 ++++++++++++++++++ 1 file changed, 21 insertions(+), 24 deletions(-) Content analysis details: (-4.6 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [2604:1380:40e1:4800:0:0:0:1 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -2.1 DKIMWL_WL_HIGH DKIMwl.org - High trust sender X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Rework spi_nor_get_flash_info() to make it look more straight forward and esp. don't return early. The latter is a preparation to check for deprecated flashes. Signed-off-by: Michael Walle Reviewed-by: Pratyush Yadav --- drivers/mtd/spi-nor/core.c | 45 ++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c index bbfef7b3997f..58d310427d35 100644 --- a/drivers/mtd/spi-nor/core.c +++ b/drivers/mtd/spi-nor/core.c @@ -3311,39 +3311,36 @@ static const struct flash_info *spi_nor_match_name(struct spi_nor *nor, static const struct flash_info *spi_nor_get_flash_info(struct spi_nor *nor, const char *name) { - const struct flash_info *info = NULL; + const struct flash_info *jinfo = NULL, *info = NULL; if (name) info = spi_nor_match_name(nor, name); - /* Try to auto-detect if chip name wasn't specified or not found */ - if (!info) - return spi_nor_detect(nor); - /* - * If caller has specified name of flash model that can normally be - * detected using JEDEC, let's verify it. + * Auto-detect if chip name wasn't specified or not found, or the chip + * has an ID. If the chip supposedly has an ID, we also do an + * auto-detection to compare it later. */ - if (name && info->id) { - const struct flash_info *jinfo; - + if (!info || info->id) { jinfo = spi_nor_detect(nor); - if (IS_ERR(jinfo)) { + if (IS_ERR(jinfo)) return jinfo; - } else if (jinfo != info) { - /* - * JEDEC knows better, so overwrite platform ID. We - * can't trust partitions any longer, but we'll let - * mtd apply them anyway, since some partitions may be - * marked read-only, and we don't want to loose that - * information, even if it's not 100% accurate. - */ - dev_warn(nor->dev, "found %s, expected %s\n", - jinfo->name, info->name); - info = jinfo; - } } - return info; + /* + * If caller has specified name of flash model that can normally be + * detected using JEDEC, let's verify it. + */ + if (info && jinfo && jinfo != info) + dev_warn(nor->dev, "found %s, expected %s\n", + jinfo->name, info->name); + + /* + * JEDEC knows better, so overwrite platform ID. We can't trust + * partitions any longer, but we'll let mtd apply them anyway, since + * some partitions may be marked read-only, and we don't want to loose + * that information, even if it's not 100% accurate. + */ + return jinfo ?: info; } static u32