Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2314191pxp; Mon, 21 Mar 2022 16:41:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw/3EPuMW0Hwd+xkT7S9pK6RXSOW2fy5N7Aodl2/4qEMfko5ad+JVVcfyfkydybKfrUufeA X-Received: by 2002:a17:902:ab41:b0:153:2c4b:4eee with SMTP id ij1-20020a170902ab4100b001532c4b4eeemr15687806plb.48.1647906090787; Mon, 21 Mar 2022 16:41:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647906090; cv=none; d=google.com; s=arc-20160816; b=ueDXhENzZ/AL/VrWium/qTE0fzDWDaePm1RF3DwGYEU40EszEnQS0L7xTp/wIBMMdj oElz5OBIJTsgwnJoyWA51flvSVoEzFh+5iNrwOrIiTRFutGU0j6MILzPtfS8PdMGFkLr 5iVlQ9gPARZG5VTyqy3Ib9gXr58+C/bj70Gddw6A3lzBVixmHXXg7SoHvGvUNs5o2j6t C9ooYdQUjGBglgnW7CfiDRJEJ0exhqFXHZKUx66/lAy2pEo/jvidhKJ/tumFN5fn2GIk x0YW9Bi9CU4FGbMMBr0Pw/Wn8mAHoaL924TPh2vZlLON0QL2rXkufvNi/tSK8bPiQySf GTKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:user-agent:references:in-reply-to :subject:cc:to:from:date:content-transfer-encoding:mime-version :dkim-signature; bh=TEMN5oOp8pSsz/f4qOvx8LZ7Vw8/HeFkF2XWTUYxriQ=; b=QmpCWDsxeiBp+kC9GmAkpQv4N1G4OMYrA5/k5Cx7FClL5MerOb9TGq3XSbny4zBSFH 846uc12Nwhef78K5TEESOSmuCifgwUkZoXKHyKAMY2gKGGlth8aXuF7bs0DDYXc/lsvx LO5dBq07dXQbLa4PGo8RM1Y/SxAHjyqhTYk2kYCEQCraUtyzyH7oMXYXbq0Xnksqp78e avBOg8yK38S1K6vwUHNKcdtANkHkuz9cPCD6r39xOcG20tZKeIxbdh0cnjfFgPrvvpiy pw9/Uf/iQbEucxKwochw0RIcvblTAfWuGf/ARDskQ87iY4HkRmtHGef/RVRLLsWxJ3UL 0F/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2016061301 header.b=BtjgrziD; 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 Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id s22-20020a170902a51600b00153b2d165a0si711317plq.424.2022.03.21.16.41.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Mar 2022 16:41:30 -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=pass header.i=@walle.cc header.s=mail2016061301 header.b=BtjgrziD; 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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 54AFA465CDF; Mon, 21 Mar 2022 15:55:08 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230201AbiCUWzK (ORCPT + 99 others); Mon, 21 Mar 2022 18:55:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230054AbiCUWyt (ORCPT ); Mon, 21 Mar 2022 18:54:49 -0400 Received: from ssl.serverraum.org (ssl.serverraum.org [176.9.125.105]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A03F82323 for ; Mon, 21 Mar 2022 15:38:10 -0700 (PDT) Received: from ssl.serverraum.org (web.serverraum.org [172.16.0.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ssl.serverraum.org (Postfix) with ESMTPSA id 6F11322175; Mon, 21 Mar 2022 23:38:08 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2016061301; t=1647902288; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TEMN5oOp8pSsz/f4qOvx8LZ7Vw8/HeFkF2XWTUYxriQ=; b=BtjgrziDWJyVywDlXY3kCqPTQGKAeoqqVoErY5czyswMRNwE6++zFd01lSfoevNWfORAU5 i/34WLLul0p9ATWtQxhvb+Vn0AFDBI1eMsTVPpa1dO6fTGKbgAz1/OXp5tg8JVT2C9ybC8 g52amaC2MzGEQUgacAV4Gb8MPSeEsVk= MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Mon, 21 Mar 2022 23:38:08 +0100 From: Michael Walle To: Pratyush Yadav Cc: Tudor.Ambarus@microchip.com, miquel.raynal@bootlin.com, richard@nod.at, vigneshr@ti.com, linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, Nicolas.Ferre@microchip.com Subject: Re: [PATCH v2 3/8] mtd: spi-nor: core: Use auto-detection only once In-Reply-To: <20220321174251.ehhobu26tgoxrbps@ti.com> References: <20220228111712.111737-1-tudor.ambarus@microchip.com> <20220228111712.111737-4-tudor.ambarus@microchip.com> <20220321121455.bpql7x4ebhq7s36l@ti.com> <20220321174251.ehhobu26tgoxrbps@ti.com> User-Agent: Roundcube Webmail/1.4.13 Message-ID: <148e6c16421e6a94a2ee41fa251130df@walle.cc> X-Sender: michael@walle.cc X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 Am 2022-03-21 18:42, schrieb Pratyush Yadav: > On 21/03/22 12:50PM, Tudor.Ambarus@microchip.com wrote: >> On 3/21/22 14:14, Pratyush Yadav wrote: >> > EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe >> > >> > On 28/02/22 01:17PM, Tudor Ambarus wrote: >> >> In case spi_nor_match_name() returned NULL, the auto detection was >> >> issued twice. There's no reason to try to detect the same chip twice, >> >> do the auto detection only once. >> >> >> >> Signed-off-by: Tudor Ambarus >> >> --- >> >> drivers/mtd/spi-nor/core.c | 10 ++++++---- >> >> 1 file changed, 6 insertions(+), 4 deletions(-) >> >> >> >> diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c >> >> index f87cb7d3daab..b1d6fa65417d 100644 >> >> --- a/drivers/mtd/spi-nor/core.c >> >> +++ b/drivers/mtd/spi-nor/core.c >> >> @@ -2894,13 +2894,15 @@ 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 *info = NULL, *detected_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) >> >> - info = spi_nor_read_id(nor); >> >> + if (!info) { >> >> + detected_info = spi_nor_read_id(nor); >> >> + info = detected_info; >> >> + } >> >> if (IS_ERR_OR_NULL(info)) >> >> return ERR_PTR(-ENOENT); >> >> >> >> @@ -2908,7 +2910,7 @@ static const struct flash_info *spi_nor_get_flash_info(struct spi_nor *nor, >> >> * If caller has specified name of flash model that can normally be >> >> * detected using JEDEC, let's verify it. >> >> */ >> >> - if (name && info->id_len) { >> >> + if (name && !detected_info && info->id_len) { >> >> const struct flash_info *jinfo; >> >> >> >> jinfo = spi_nor_read_id(nor); >> > >> > I think the flow can be a little bit better. How about: >> > >> > if (name) >> > info = spi_nor_match_name(); >> > >> > if (!info) { >> > info = spi_nor_read_id(); >> > if (IS_ERR_OR_NULL(info)) >> > return ERR_PTR(-ENOENT); >> > >> > return info; >> > } +1 for the flow. But is it correct that we just ignore any former error and just replace it with ENOENT? Should we return NULL here and let the caller handle the translation from NULL to ENOENT (and keeping any other errors) >> >> Here we miss the IS_ERR check in case info is retrieved with >> spi_nor_match_name(). >> Do you expect spi_nor_match_name() to ever return an error? As it is >> now it doesn't. >> I'm fine either way. In case you want me to follow your suggestion, >> give me a sign >> and I'll make a dedicated patch to move the IS_ERR_OR_NULL check. Will >> add your >> Suggested-by tag. > > I think it should be safe to assume it won't ever return an error since > all it does is iterate over an array that is always present. I don't > see > that changing in the foreseeable future either. So I think not having > the IS_ERR check is fine. But what does it cost to just add the error check now so it won't be forgotten in the future? if (name) { info = spi_nor_match_name(); if (IS_ERR(info)) return info; } if (!info) return spi_nor_read_id(); And then let the caller handle NULL and translate it to ENOENT. -michael