Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp2069814lqt; Sun, 21 Apr 2024 23:41:58 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWUVj+ZW0+mlV0bDzgGfhhyDOe1xzZsX99qXe+joMqKu/g43oMo93OEY1JlUOF0oXYXXJ4s7Thf05ofn6dgibBbZ97VJC25AKYeb4K3ow== X-Google-Smtp-Source: AGHT+IHLZeiEUSe5RXlXUW2N19iXim6i3FJYvyh6yBgtCrzsKKjl0addqT1WtlR5HyvOl7tw8FxR X-Received: by 2002:a05:6a21:350d:b0:1a9:5eb1:7f35 with SMTP id zc13-20020a056a21350d00b001a95eb17f35mr12828450pzb.46.1713768118059; Sun, 21 Apr 2024 23:41:58 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713768118; cv=pass; d=google.com; s=arc-20160816; b=YK9rb/xbUvafoF00wnkOeqgRQeFy/zmFM0kRzCHOY12Bhny+rPkpeyq5fZ2/Haulpi tbfNqv2O1iSByJOFRaaRNMvyhWslOgi8Lx8RvOW7f4rhpJYbKz2jjKgVSfc3COH0DZ8J RrvVfENIF4s4BF3gSj63+UG7316qjoHulFQ2zjrByEpP7e/hoA+sthtvXBtRcheYDbI7 rp+OhkJG0pP3WDKLZLo5ZiXFFXeeRl+lAoujFszsXRYeAQPNPm7iHbZj9m5koF1FRfdV 36T/qFAkQ3AgNHbn55b+CQbzH76Q+rGnWnQxukY1I+VhFaGRwzyGXJiMKEKyHd/sCRMf OdQQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=+IHMmWa7PCm5h8KXXIvVWID6BVHToSqTvpYZtQwLUQk=; fh=NGBSpjkqkACfFPrkH8LBojn8cLLvdfvRab4liM15rpU=; b=lIGpPcpInaNL+JqEQCe2ICHnrwXn+eTGm0WxtZCbYTIbbBO+MD2W65q9WjZf1pk2r6 +GMhwr5qaH74yW1iT4EI66iYxpHFVffHaGn6M30IzoRyfb1nYEjyHnTSl/7kwtNAR7Od QKRs+HEIG9DWerNaEx0Lh/bF0gLaYjWkSkM6r8yWNi9UwcAUAsgSQu1MkGFFW4iftEx7 UvxWLxiBefxCu7VR7CRet0JFVlqsBEb7zf0L0UfHNyWQ7gir5Hqfn02xnK9jkskIZ5gQ UPH/0STyCzajkVwPKhgeEwEa12E69ujv6PJgnkS28w8/3/yuQBc25jE4LVlBNJvFvSYn YuAg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ToPa2XSz; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-152797-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-152797-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id j19-20020aa78dd3000000b006ecef03a767si7250456pfr.340.2024.04.21.23.41.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Apr 2024 23:41:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-152797-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ToPa2XSz; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-152797-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-152797-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 316AEB21633 for ; Mon, 22 Apr 2024 06:41:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 453D848CE0; Mon, 22 Apr 2024 06:41:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="ToPa2XSz" Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 99AF2482DD for ; Mon, 22 Apr 2024 06:41:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.43 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713768074; cv=none; b=FB74wCVPdLspdvhZXqEg/QWN/7BGhuvnn7jYfjX774tGeQ/wxsmrQYWAffahV1Rnwo86+DJZ+J3o1B2ouQ7Df5o/pBtOMvMw1++Ixdk1ZeZgL9AAdqz47xTcl2ZyujWXxLSINJqURvZhH2GRouZonJHsPxIIO3MGytWnbY9Bt6Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713768074; c=relaxed/simple; bh=2kiy9wKYCMJpfEz60az6FgPJ48nJ1mHZTsoofiAFxwI=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=KldK8jqbHs4GPR400GmmSZ2ssnJxdMC5AEM0bPI0EMsZBXsJEC9aQJiiBeLPuFZeI7zl/GnCg1I4pno9rVqLXodXAFXafDJyHsgo8ri0FdN03A9ftRWVx0AUjcGapag0q/eKgix0uDNTIaWztEmgJ6d81rOvf99uHzq37Mlauro= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=ToPa2XSz; arc=none smtp.client-ip=209.85.128.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-41a70466b77so2016975e9.0 for ; Sun, 21 Apr 2024 23:41:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1713768071; x=1714372871; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=+IHMmWa7PCm5h8KXXIvVWID6BVHToSqTvpYZtQwLUQk=; b=ToPa2XSzBK46oq/e41jfJlvKDsW8NjKaf/esunPLY7fDsunm2twY6PShm/lNi5jL1x WtEQxCbMMlZMluhvCSJeO+2hd/cEGRSCXauJ1ECB3s5tyQcOWKn1uRMRrHKcYEaNWGAF QkqpgvmxlDLSF+vyEIHO3FaHSSC9Baye1UDPag/CSeBfkB6yJV+hEoVTDTEdSBCfOFaU W0OXUKcbpO8dzXuZtvZ16lB3P6YSN6zTEKE6USeAYo5fxEHd4Epqg2bNJndyKWsUt+hD WSzUivssP/4/EKM0U14XL71C8vZYRas+JhTfzHrkR13PEKy/mtBqfcCwsKP3bR8Huw5g zk2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713768071; x=1714372871; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=+IHMmWa7PCm5h8KXXIvVWID6BVHToSqTvpYZtQwLUQk=; b=JeIF1ir7yq2uKxu0+DSHkuXbT1KJ/86zDgVQafl4MqbRbSMJP5evoMLPhtVNSt7BQ6 FD6thy4W+Xr2rwOatpjIQvEoUAM+ih74em9D+YBpBqu4kELS1LVwUvk/Hvxbk3T2lUhl cO5BOLuTnVa1sjQDkGAyoq1AokAC01EgOYma502k20ltyjOMp0Y2Y06ug+TkIH+xYgfC NkoWBiEqbKmCTReqwH6Mvlocn6bO4Knyu4M4amH6Ot7yVnTJb1HACtWOU0Uwn4o1cp7Y /JXv4npFRqU8tl2IrFYFlco2uzU6HZd/ReDSYe8hBOlLWT+cK9zJknrrUD2kynbym4lW nRuA== X-Forwarded-Encrypted: i=1; AJvYcCW+DG4T57FF38hZGu5Osf7YoIbOKQiYtJTIAoXor4Y0HTs1U/mbg3mbnz+nMx059qM0wfTjPfrF+dbyOrh8A9RT6QrQS4AhMOM0vqeg X-Gm-Message-State: AOJu0YyEUcLpVHI2ZustX6j8ncK4YUwUfYiWxqJB1PTLWJphXsdi1smV xIeE/jnPC9NEKRu47J/11pF2MuH7ZPaOGAcejdFtkvGbKl+UDV6VtQGD+dIFLa4= X-Received: by 2002:a05:600c:4587:b0:417:e00c:fdb8 with SMTP id r7-20020a05600c458700b00417e00cfdb8mr9055250wmo.1.1713768070878; Sun, 21 Apr 2024 23:41:10 -0700 (PDT) Received: from [192.168.2.107] ([79.115.63.100]) by smtp.gmail.com with ESMTPSA id be7-20020a05600c1e8700b0041a5b68ea32sm2186473wmb.27.2024.04.21.23.41.09 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 21 Apr 2024 23:41:10 -0700 (PDT) Message-ID: Date: Mon, 22 Apr 2024 07:41:08 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 5/6] mtd: spi-nor: simplify spi_nor_get_flash_info() To: Michael Walle , Pratyush Yadav , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra Cc: Ricardo Ribalda , linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org References: <20240419141249.609534-1-mwalle@kernel.org> <20240419141249.609534-6-mwalle@kernel.org> Content-Language: en-US From: Tudor Ambarus In-Reply-To: <20240419141249.609534-6-mwalle@kernel.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 4/19/24 15:12, Michael Walle wrote: > 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 4e2ae6642d4c..8e4ae1317870 100644 > --- a/drivers/mtd/spi-nor/core.c > +++ b/drivers/mtd/spi-nor/core.c > @@ -3294,39 +3294,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) { you can remove else if with 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); keep the warning where it was > - info = jinfo; move this so that it belongs to if (!info || info->id) > - } > } > and then return info. Does it work? if (name) info = spi_nor_match_name(nor, name); if (!info || info->id) { jinfo = spi_nor_detect(nor); if (IS_ERR(jinfo)) return jinfo; if (jinfo != info) dev_warn((); info = jinfo; } return info; > - 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;