Received: by 2002:ab2:7041:0:b0:1f4:bcc8:f211 with SMTP id x1csp156335lql; Fri, 12 Apr 2024 06:45:28 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVNVaX0HDLZ98pq5WYixBrsEHpd7Ii47kepRGGR6m4VmiVzUmDq2WDgzpNytIlsMR/SmYW3MpZfChZQddItH51D2wAxGrpwzWTh+Ec3lg== X-Google-Smtp-Source: AGHT+IGDmjhSeSze7gTKp5OHeOYTCG9AeFvtsrMLHB49LHxBVD6PCBl/i/mTiXXTUszsRlsKFi9I X-Received: by 2002:a50:9b1a:0:b0:56e:2464:7c41 with SMTP id o26-20020a509b1a000000b0056e24647c41mr1993803edi.19.1712929528424; Fri, 12 Apr 2024 06:45:28 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712929528; cv=pass; d=google.com; s=arc-20160816; b=euBxLyTxnOelX6JIsoxyoMdnanorIsOJzMAWvBmKVvkV9XqY3XyUvJzt5dcEVs6mYu CLP6C0DIy7XAEI20zruk5TI1CUCBAa5N9LRDNiN/C0USRgzXv4QJBjSovtlL+0sM8q+q 33FNC5Sk7ixh2+A7y+3/ny3RoKF9e/Z6O8bMgkmYRu5PfNNcgNwlIF4Jq0Kskjtkss0/ WAlyF+o9k4aPtW+5XTCkJHVn7McS/7aYxKbqKounBQItxcD2eUsn8LWe9x6Y2jRGnnK9 xnDw12B303XGKTynI26Uj8mKG5yesJ6vTLCg3a2rqd0jB/tLcdCMx+3Pw9pVyXP4112S hf8g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=tMgEP1yCBtLYna2l+DwEbpRSd4PqENsWFw5CT04fzsU=; fh=LuNSX3JVG+htsysoJ/xF51pAKitwHo02H/zRZAOLqDw=; b=X4lGlXZF+cnKV6PpEqZJzJkPUyZxMV1wAW5oll84JV59aOl19dakniDiWzlLmjGvnU gmktrWzTNf2ZyxcjzTKJ0kPhOpqrBqFLJQrrOwAfPigy7Eogdq2u9L7JgfCx8ugec6pj Rzt2baWRQ7vgt450ChJP6g2qNpgSQN5RMnsntQUgBQRXB00t1Vi5mdkMDzqdrh1UcK5b KmBWV1Ljdo0M8ycyiMNsfVkxJ0Eh0y29hxa5x6+hZzy+j1fdGQKJxIVuzr+eRbCWXQ1C flHJFOKz5b9hgT2k0Meoi1g1W4geX18ZK1+hixo9oSq+Qf+ZAUY6OYNJp8RiEjYIjPK7 s/1g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=kzndw7DQ; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-142754-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-142754-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id u22-20020a50c056000000b0056e1dc788b6si1681887edd.94.2024.04.12.06.45.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 06:45:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-142754-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=kzndw7DQ; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-142754-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-142754-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 29C171F22EC8 for ; Fri, 12 Apr 2024 13:45:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 942ED86146; Fri, 12 Apr 2024 13:44:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="kzndw7DQ" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C04E685954 for ; Fri, 12 Apr 2024 13:44:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712929465; cv=none; b=qVyDX63qHQlGhWsyRVNEeZItefduxxvdiophaPIJyF+3oR9tVVRiH3lXhAK9e/4BMT5jLH8j9visD1hTPOng8tL7X7XT9vmE2KGcURwLZQztYvIld0lnd8mzgN6N4V6L5wfp/tX3i9KcPgsUrzfG0Ip58UBkSb1YSl5e+2boNA0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712929465; c=relaxed/simple; bh=B7/0WXuNeHfB1kb629KPZ4FB30EU6w2b00Yh+4BqI5Q=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=K1MfrXTJle3k6D4AGkFl5FLM9DDI1DMa72Pc+zn2RUQzc4TLbe4FCmdrsQIWs04oya5Hk11lfbt7+nJ/WgDCC5a+WjlvkXZaqScTB6j7K1k489Uhp/pBYqBLtIOGqWqnPCQDYAoPbcUuQbH+abbkKILs3njLbSyF5yIl4aRpf8o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kzndw7DQ; arc=none smtp.client-ip=10.30.226.201 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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(-) 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 -- 2.39.2