From patchwork Mon Mar 6 12:58:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 64642 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1836308wrd; Mon, 6 Mar 2023 05:21:17 -0800 (PST) X-Google-Smtp-Source: AK7set8bd3UjLVyE9kAWCJW6XQYn8DtBTV86cuJAPB5WrYsTEgQAkSiL8N4aLgmCr5NRnfgOephz X-Received: by 2002:a17:906:16d5:b0:8b1:79d0:bc58 with SMTP id t21-20020a17090616d500b008b179d0bc58mr9020453ejd.16.1678108877245; Mon, 06 Mar 2023 05:21:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678108877; cv=none; d=google.com; s=arc-20160816; b=vdBUnXpZHWfgmbAxJlBspQG8XAP2NCTHsHZs8a7DsKS7L4aUZeL3ul2XiWuvOb8vNL E7B69X1uXeT2JGinBvSRMMBw8BGLthBVs6A0UhoCi5aalDVXz+Xz4DL4QDgViqUvyEad dnQbZRZz+mvuvHBbseNlQRdSOHejGW1kY/yv9vzx1/V+No7zxfJNBitK8OQI9AvoiPDj kCLOPgM/IyfgHiUrLN7E7KaS0eMn9JJr21l4hQMyjaw/7UnWCfsRlGAyRLTOx9TBp1Rt GmE2vknVysZCxODNFpOuiWeQlrX3+sqmEyot869t9fH5gse0n0uhZ+tTOlDvJPwB8uZy F1ww== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=felfT43D0ByEEC43Rq1xqotzNKKcG2VF+lRhbg02WB4=; b=bh4Sm7qbMSShT1ORImZn5i+c9QEy5CbRa+BkKTyDf6wZqNp4XPZ8wHlDyzOqhlgvCo EbdZqyUdRTMzBsGgRuXq54BILI0MCJijte+nC2rXa9nP0TUzrqBwXX2wmg0ZPcTr6jLT jIdYVs0piYgn8AJ28ev+F3jZRA2N6GaAq04mxBr+zrRdB9u0ZkTQ/Lf6VY/eP5vOnQkn 03U1s4f4prbOHZUyv0j8LrMYeb5GE7pWfZTwOcC3xDyzb/j05x7hAAsxNrNjdRcDCLri lpn+lqkTY3f6llLsmPpqcdfqXbjng/EvIY+kf4xRzKUniT8lmIKUilVeZwKnh1hnTDiN r7EA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2022082101 header.b=tgaP+NM0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=walle.cc Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u25-20020a1709063b9900b008dbb5a2ea5fsi396511ejf.644.2023.03.06.05.20.52; Mon, 06 Mar 2023 05:21:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2022082101 header.b=tgaP+NM0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=walle.cc Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230370AbjCFM6c (ORCPT + 99 others); Mon, 6 Mar 2023 07:58:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58436 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230247AbjCFM62 (ORCPT ); Mon, 6 Mar 2023 07:58:28 -0500 Received: from mail.3ffe.de (0001.3ffe.de [IPv6:2a01:4f8:c0c:9d57::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4440623874; Mon, 6 Mar 2023 04:58:22 -0800 (PST) Received: from mwalle01.kontron.local. (unknown [213.135.10.150]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.3ffe.de (Postfix) with ESMTPSA id D7E6D100; Mon, 6 Mar 2023 13:58:17 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2022082101; t=1678107498; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=felfT43D0ByEEC43Rq1xqotzNKKcG2VF+lRhbg02WB4=; b=tgaP+NM0dhhp7GXFV8BWTt6vnZLjr1w+1W/5++uBU3EwNELH8TA/dSk8nEjPE7hC3vvvxV xbADrut9+vZU3+IEgKrhA+DFgS52V98rRBEtFn2AumZX+b3sLMpowctuF45agryOrcwb0j Sb7fNhecL0+AmyBRFj+tcx/2EGLu4N0DXl9xfDa8qjbniCuD7rZZZXiHDDeckY2xuv/2VW TNUzuwazhSNsxkH5RuJqdv71mgPVF1Eqlul+RjJo6GJtj2rqp4T9MeIybpjy9y9sz0yeIN AvF88gzzRDul1iVPKJ2w+dI2iwVV7eaSkUrh4hVju4W6cZX/+9UjD39RETt4aw== From: Michael Walle To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra Cc: linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, Michael Walle , stable@vger.kernel.org Subject: [PATCH 1/4] mtd: core: provide unique name for nvmem device, take two Date: Mon, 6 Mar 2023 13:58:02 +0100 Message-Id: <20230306125805.678668-1-michael@walle.cc> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759624693609094482?= X-GMAIL-MSGID: =?utf-8?q?1759624693609094482?= Commit c048b60d39e1 ("mtd: core: provide unique name for nvmem device") tries to give the nvmem device a unique name, but fails badly if the mtd device doesn't have a "struct device" associated with it, i.e. if CONFIG_MTD_PARTITIONED_MASTER is not set. This will result in the name "(null)-user-otp", which is not unique. It seems the best we can do is to use the compatible name together with a unique identifier added by the nvmem subsystem by using NVMEM_DEVID_AUTO. Fixes: c048b60d39e1 ("mtd: core: provide unique name for nvmem device") Cc: stable@vger.kernel.org Signed-off-by: Michael Walle --- drivers/mtd/mtdcore.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c index 0feacb9fbdac..3fe2825a85a1 100644 --- a/drivers/mtd/mtdcore.c +++ b/drivers/mtd/mtdcore.c @@ -888,8 +888,7 @@ static struct nvmem_device *mtd_otp_nvmem_register(struct mtd_info *mtd, /* OTP nvmem will be registered on the physical device */ config.dev = mtd->dev.parent; - config.name = kasprintf(GFP_KERNEL, "%s-%s", dev_name(&mtd->dev), compatible); - config.id = NVMEM_DEVID_NONE; + config.name = compatible; config.owner = THIS_MODULE; config.type = NVMEM_TYPE_OTP; config.root_only = true; @@ -905,7 +904,6 @@ static struct nvmem_device *mtd_otp_nvmem_register(struct mtd_info *mtd, nvmem = NULL; of_node_put(np); - kfree(config.name); return nvmem; } From patchwork Mon Mar 6 12:58:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 64635 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1831643wrd; Mon, 6 Mar 2023 05:12:33 -0800 (PST) X-Google-Smtp-Source: AK7set85F4b4qOW0n/BlDpxcr0YDk3CV703ovbGNN/aGq2DxirdjUU7KfB32N5flW+4feMPQWjqD X-Received: by 2002:a05:6a20:4407:b0:ce:2f40:6e9b with SMTP id ce7-20020a056a20440700b000ce2f406e9bmr15988356pzb.28.1678108353011; Mon, 06 Mar 2023 05:12:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678108352; cv=none; d=google.com; s=arc-20160816; b=P6Wgc2xuOxJc9Q7m2EmkiwG2K61dbziwWlA3oSLg4HkDrGSVVvb/hjT13imqzv90Do 8qGRENkAroSRbxSswDEpkiY1FP0SXMPZk8KtXA7WNNa4S87+Ee/ZoxrKqoMRcM+p5Tnd vwomUNg/mPP7J9fWpU0jhYn40FO7305FaOnZ0OR3xxpKBEkAdoFgpEu9z7ADWKzGqTWH v5BfYzNXeioP6hTOp8Sz/TrIvef8rP13zwd4s1yAEdZjddnk68fAAGGaX4IhRsKgGXop svPAq9xN4vxqV3CFpUZ+eG6CpaMUO5vOn6AD0VGYQcfsVFV7WYpCZ4mrjbqWib4rV+qB /u/w== 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=1CeOMe/AYsWIkrv6IYk3xhBvkgKOswiPrxwsxlRjwQc=; b=gz8SzcFCEFqdRspS9swzPXu0IZrcQLZdcVUOzDruL9i4ugoYdp4MwTWmNRp1slecn5 4zcqgq/kMgKG3y90m5kkgTc60y5TSgO6wfWGXwEu1ux1L4ivXz9vRuH9gxmDwOWC4E2B CqKSABosC19NLLyGbhcAf4dc9ocUILgBH0jX3/0E3egz2KwzbuKcDsP8tJWj2hWzJ2xX NitpTh5ApftqFOKRDhBvNcF0Y0HDVyUYYSEGSZAnPNMWv8ywC4AmI+N9IezuT38I37Kr lE8dzIU0pRA2sVrphC7SeQSAGBxwWTk8VwKcoKqSI5CNKL8/eqLuhqWTEAEf5Vayw/FA gV/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2022082101 header.b="H/JZdRw5"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=walle.cc Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s6-20020a634506000000b004fbd4ae5651si9477906pga.170.2023.03.06.05.12.11; Mon, 06 Mar 2023 05:12:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2022082101 header.b="H/JZdRw5"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=walle.cc Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230387AbjCFM6i (ORCPT + 99 others); Mon, 6 Mar 2023 07:58:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58460 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230268AbjCFM62 (ORCPT ); Mon, 6 Mar 2023 07:58:28 -0500 Received: from mail.3ffe.de (0001.3ffe.de [IPv6:2a01:4f8:c0c:9d57::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5576424112; Mon, 6 Mar 2023 04:58:22 -0800 (PST) Received: from mwalle01.kontron.local. (unknown [213.135.10.150]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.3ffe.de (Postfix) with ESMTPSA id AE38DD27; Mon, 6 Mar 2023 13:58:18 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2022082101; t=1678107498; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1CeOMe/AYsWIkrv6IYk3xhBvkgKOswiPrxwsxlRjwQc=; b=H/JZdRw5jHgYMU2/CMQO6ohvSVwUzf3v9R97C8WcFqa42EcyNnddC3qThQN2Nl+GnESDoL R0srgoK4hYITyV5xejObg/aQpZ4Gtg7PEiY4GvnHDqoVSSNm7xA/eCMGnltpnFQlDvHejT 1qhLmv3BLowZ19yGU3nQ7GMQf2RiL/nV9UqLCImzeVP/T1U0Z00DkagPWl70DzUS9rfUIl IWeVX+QAKsE8p6g0dECm/Ol+gkVZcO3/ui6h0ZDjYB49s/3ey48kEp4Nnjb4fkynZjGLFV 3Mv6bSEqF0DmzAtHPr+Gtq2URZSldhH0qH0FoU27YnbHBlhHR8tFkQz2uUmfmA== From: Michael Walle To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra Cc: linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, Michael Walle , stable@vger.kernel.org Subject: [PATCH 2/4] mtd: core: fix nvmem error reporting Date: Mon, 6 Mar 2023 13:58:03 +0100 Message-Id: <20230306125805.678668-2-michael@walle.cc> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230306125805.678668-1-michael@walle.cc> References: <20230306125805.678668-1-michael@walle.cc> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759624144012173030?= X-GMAIL-MSGID: =?utf-8?q?1759624144012173030?= The master MTD will only have an associated device if CONFIG_MTD_PARTITIONED_MASTER is set, thus we cannot use dev_err() on mtd->dev. Instead use the parent device which is the physical flash memory. Fixes: 4b361cfa8624 ("mtd: core: add OTP nvmem provider support") Cc: stable@vger.kernel.org Signed-off-by: Michael Walle --- drivers/mtd/mtdcore.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c index 3fe2825a85a1..4a19e69fb77b 100644 --- a/drivers/mtd/mtdcore.c +++ b/drivers/mtd/mtdcore.c @@ -938,6 +938,7 @@ static int mtd_nvmem_fact_otp_reg_read(void *priv, unsigned int offset, static int mtd_otp_nvmem_add(struct mtd_info *mtd) { + struct device *dev = mtd->dev.parent; struct nvmem_device *nvmem; ssize_t size; int err; @@ -951,7 +952,7 @@ static int mtd_otp_nvmem_add(struct mtd_info *mtd) nvmem = mtd_otp_nvmem_register(mtd, "user-otp", size, mtd_nvmem_user_otp_reg_read); if (IS_ERR(nvmem)) { - dev_err(&mtd->dev, "Failed to register OTP NVMEM device\n"); + dev_err(dev, "Failed to register OTP NVMEM device\n"); return PTR_ERR(nvmem); } mtd->otp_user_nvmem = nvmem; @@ -969,7 +970,7 @@ static int mtd_otp_nvmem_add(struct mtd_info *mtd) nvmem = mtd_otp_nvmem_register(mtd, "factory-otp", size, mtd_nvmem_fact_otp_reg_read); if (IS_ERR(nvmem)) { - dev_err(&mtd->dev, "Failed to register OTP NVMEM device\n"); + dev_err(dev, "Failed to register OTP NVMEM device\n"); err = PTR_ERR(nvmem); goto err; } From patchwork Mon Mar 6 12:58:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 64644 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1836445wrd; Mon, 6 Mar 2023 05:21:33 -0800 (PST) X-Google-Smtp-Source: AK7set9kpEHLpIWK1HNYotHa9nU0dqE/uMXeGBWE99yNwlLVr8HsSj9SlpAQ4dvPRPZ9c9eLSzrI X-Received: by 2002:aa7:d04e:0:b0:4ab:178d:3d9f with SMTP id n14-20020aa7d04e000000b004ab178d3d9fmr8462602edo.28.1678108893266; Mon, 06 Mar 2023 05:21:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678108893; cv=none; d=google.com; s=arc-20160816; b=X2Uc74aegRoSJwGO63XcSU1bv0OwZy6wV1sujmOdzv8zKmXf/f2qqinc5M82pVx5uD Q3GEDCX4HGc2thTLbc8IUu9+8amdbJtbyDic2b6pBkBVf9dQ1YktyFpxNLdo3lg3/VWP y8t2Sek89BisgSkL+Vj/h+rOGgntAsrUPiMQoQgfHR7xT4WpVN4MQGNcbQAjmsMUud2X B3xfI5fPowSNhBCU8NDAispHetmRyVFbjXuzuQPDQua7rmSIUE9DruzJNpCf5aNhAA1J VKVpxnJAXFvsGPK9MynN2W5YtkazGAmFMmul/8V58qpHMYup1aj1nRDhSg8hrfZjrsPr z8gg== 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=3jggkbUJ5OxlpR1kYN/iXcmteZ/OMssiGsaodrVJEL4=; b=V7ZZr+T/l8ux7ghHB+Yz/LqOF+RUIovqAAJPmwNxKJJkNuMk86hsQ1IevMT1RMR3U4 LiDyLYybDies1wDDptX0lIB+5t1wzpe/JWY2164hXDpnjh+pvGLTuxLOjpypW2We1AEW KOAbOptFl6+ve4j0khjzdPHFRdqi0xa6OTg9sbG/XrTlbuqmsm9tKTHgLi6OOtF6mRVa Q4hKW2vMV51d9RHVtmOXD14kbU1j1L0M24hgopGK1tdOCMs1zdEdn/HxcWtdtfZ9bgqk 5Pz7F6CP2KCoUm1iamZARXe3XEg3Pup2mYQ9GizwyjQ7TlEymXLulh6gObUyTD3Bh3Ro QJ9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2022082101 header.b=hXJNDQSo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=walle.cc Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u17-20020aa7d891000000b004c0cce59f79si6663917edq.120.2023.03.06.05.21.10; Mon, 06 Mar 2023 05:21:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2022082101 header.b=hXJNDQSo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=walle.cc Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230382AbjCFM6f (ORCPT + 99 others); Mon, 6 Mar 2023 07:58:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230239AbjCFM62 (ORCPT ); Mon, 6 Mar 2023 07:58:28 -0500 Received: from mail.3ffe.de (0001.3ffe.de [IPv6:2a01:4f8:c0c:9d57::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 451661F921; Mon, 6 Mar 2023 04:58:22 -0800 (PST) Received: from mwalle01.kontron.local. (unknown [213.135.10.150]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.3ffe.de (Postfix) with ESMTPSA id 6DDAC164C; Mon, 6 Mar 2023 13:58:19 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2022082101; t=1678107499; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3jggkbUJ5OxlpR1kYN/iXcmteZ/OMssiGsaodrVJEL4=; b=hXJNDQSoSWkg00rCZBI4b8JalYiJb2rgm3Okc+AJ/JdLMTlY8vz0QWVssJdvq951+qV6Kw WrO55vXSj6jQh2g3EybN6mYt8/nuRlCPRwcBGC6zlAdXOAdyrU54J9j5T4+NKKvXee83x6 WTZq+NJ6iHRVZEmu341ddw/jmRCxG6iSSZX3xh0cOKohRVi/aStX9Nv9kVDki4Zel8B7+j eZsy2kee3/pGOwVVfu6d9UMlNgAM8zqiOTDF01qNzHkSZTrs+ftCoEgTUvsB/uKpyiQHkE 77+rCVi4vAvi7glMGN/hJpybw7s3BSS6wf+CiLffcdTAjKX/NHtyXdreWNQvWQ== From: Michael Walle To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra Cc: linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, Michael Walle , stable@vger.kernel.org Subject: [PATCH 3/4] mtd: core: fix error path for nvmem provider Date: Mon, 6 Mar 2023 13:58:04 +0100 Message-Id: <20230306125805.678668-3-michael@walle.cc> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230306125805.678668-1-michael@walle.cc> References: <20230306125805.678668-1-michael@walle.cc> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759624711281272685?= X-GMAIL-MSGID: =?utf-8?q?1759624711281272685?= If mtd_otp_nvmem_add() fails, the partitions won't be removed because there is simply no call to del_mtd_partitions(). Unfortunately, add_mtd_partitions() will print all partitions to the kernel console. If mtd_otp_nvmem_add() returns -EPROBE_DEFER this would print the partitions multiple times to the kernel console. Instead move mtd_otp_nvmem_add() to the beginning of the function. Fixes: 4b361cfa8624 ("mtd: core: add OTP nvmem provider support") Cc: stable@vger.kernel.org Signed-off-by: Michael Walle --- drivers/mtd/mtdcore.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c index 4a19e69fb77b..d6675bf03557 100644 --- a/drivers/mtd/mtdcore.c +++ b/drivers/mtd/mtdcore.c @@ -1022,10 +1022,14 @@ int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types, mtd_set_dev_defaults(mtd); + ret = mtd_otp_nvmem_add(mtd); + if (ret) + goto out; + if (IS_ENABLED(CONFIG_MTD_PARTITIONED_MASTER)) { ret = add_mtd_device(mtd); if (ret) - return ret; + goto out; } /* Prefer parsed partitions over driver-provided fallback */ @@ -1060,9 +1064,12 @@ int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types, register_reboot_notifier(&mtd->reboot_notifier); } - ret = mtd_otp_nvmem_add(mtd); - out: + if (ret) { + nvmem_unregister(mtd->otp_user_nvmem); + nvmem_unregister(mtd->otp_factory_nvmem); + } + if (ret && device_is_registered(&mtd->dev)) del_mtd_device(mtd); From patchwork Mon Mar 6 12:58:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 64632 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1831034wrd; Mon, 6 Mar 2023 05:11:29 -0800 (PST) X-Google-Smtp-Source: AK7set8DdUoqxnnsCbqwlqHF4vQjjMOKFeV3+fwEqP4J07i9XiE08Tw78Fcb4gOh0s0lzFjjpkwY X-Received: by 2002:a17:90a:db92:b0:237:44ad:5124 with SMTP id h18-20020a17090adb9200b0023744ad5124mr11236443pjv.42.1678108288549; Mon, 06 Mar 2023 05:11:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678108288; cv=none; d=google.com; s=arc-20160816; b=KSTueQMHCG/HWZhMAcFHmWfTDNidwPcwPNt1rWb4tWFYVC2+VmhiA+jwPXYGX118Sg AjWvQSQZG6fGBFoGHBiRjFn6J8TD43NFaWv6aiZ+2dLpP9EAePYiio0wYBDppR+s8yQG 7U+n4NLc9TieE9GpgqUCjog8Ic93PD1Ew5LANfqIcsg8u0+kTAkxwfzcCAraObKCLdlN +qWvhJ0BEQpYivSYQyYK/aBxm1JJ3/4w8sSWYf7+wgt0V37RfP96JV7r39hzM41hfIl3 vVOcwswnLUgXGCdF7msTaqJ84FlxvJ/NPiv/nQfhckULOLWW81v16UTCZuUuXalwh2Ij vxNw== 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=VjUKX8vcOHRxfuq1rLlQX2Q888LcQ64xmxe+6S+e/IE=; b=n3IJfAM9Ymr7nqtzWB9Ma64NCquYhcxZVStRqNZQ8IswmPS+8q5DL5b6JxqM8Ris+q YE9p8v1jCQKeymCWPQftGMefQ4KhDcyky1M9mzKA9k1KTUm83lMlmYVFUN6P6xTNCoPK OpalIeFel/knMreM9jy4WBdDR6T2o5BqPQSd1HGX2LZjXRvnF6TF1dBLf/hQxuiQQ0RZ xNdFot3krhP8D+3w1SfV5qR7rrZ78gSgPCxXd4hdgmr2ChmRkcpWr9oXhjz5vBEML7Wt LDUVo9GhnTmO/1HHuCeqbt8N2DHZxP2oQIxAsS8jE0grdJcnPsFoWS0N8G38dvb2sdvo bFlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2022082101 header.b=remoxRjf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=walle.cc Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p14-20020a17090a680e00b002349fd50c3bsi11343707pjj.40.2023.03.06.05.11.15; Mon, 06 Mar 2023 05:11:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2022082101 header.b=remoxRjf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=walle.cc Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230348AbjCFM6a (ORCPT + 99 others); Mon, 6 Mar 2023 07:58:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230254AbjCFM62 (ORCPT ); Mon, 6 Mar 2023 07:58:28 -0500 Received: from mail.3ffe.de (0001.3ffe.de [159.69.201.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F3BD223137 for ; Mon, 6 Mar 2023 04:58:21 -0800 (PST) Received: from mwalle01.kontron.local. (unknown [213.135.10.150]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.3ffe.de (Postfix) with ESMTPSA id 3E19C166A; Mon, 6 Mar 2023 13:58:20 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2022082101; t=1678107500; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VjUKX8vcOHRxfuq1rLlQX2Q888LcQ64xmxe+6S+e/IE=; b=remoxRjffuVdFV7RP3A/DnTRNbgpNuzcP3/5Mg9FRfPXhjxTQZ50iPuDU7OZnQcfHyZ7zO 9E7JrxIJIKD7pqQim7XtEAG+cO3qoXl3QzBIxSExnODOS2nuzneBbUL8Z35SobE49Eik7+ ry9Ino+B/stNJLhVunGZmd6t+JJVAsfqqefv6K/tixr06EYzbzuwfxvqI1yvBHI/Zlhgtz Y6uNyLjCduevVlEnmfGrCoib/8UiZ+qK+YiMSRDCcaDCp75kLJBg4ltLf0zjAeSKb5oK4B dIdBBn5Zk4La6lL4Lj/8CTrMQVvXmJ9P970akTIj2U3/eVVBg5pyf1r23rvDWQ== From: Michael Walle To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra Cc: linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, Michael Walle Subject: [PATCH 4/4] mtd: core: prepare mtd_otp_nvmem_add() to handle -EPROBE_DEFER Date: Mon, 6 Mar 2023 13:58:05 +0100 Message-Id: <20230306125805.678668-4-michael@walle.cc> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230306125805.678668-1-michael@walle.cc> References: <20230306125805.678668-1-michael@walle.cc> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759624077000741630?= X-GMAIL-MSGID: =?utf-8?q?1759624077000741630?= NVMEM soon will get the ability for nvmem layouts and these might not be ready when nvmem_register() is called and thus it might return -EPROBE_DEFER. Don't print the error message in this case. Signed-off-by: Michael Walle --- drivers/mtd/mtdcore.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c index d6675bf03557..4f9bd78bc6f9 100644 --- a/drivers/mtd/mtdcore.c +++ b/drivers/mtd/mtdcore.c @@ -952,8 +952,8 @@ static int mtd_otp_nvmem_add(struct mtd_info *mtd) nvmem = mtd_otp_nvmem_register(mtd, "user-otp", size, mtd_nvmem_user_otp_reg_read); if (IS_ERR(nvmem)) { - dev_err(dev, "Failed to register OTP NVMEM device\n"); - return PTR_ERR(nvmem); + err = PTR_ERR(nvmem); + goto err; } mtd->otp_user_nvmem = nvmem; } @@ -970,7 +970,6 @@ static int mtd_otp_nvmem_add(struct mtd_info *mtd) nvmem = mtd_otp_nvmem_register(mtd, "factory-otp", size, mtd_nvmem_fact_otp_reg_read); if (IS_ERR(nvmem)) { - dev_err(dev, "Failed to register OTP NVMEM device\n"); err = PTR_ERR(nvmem); goto err; } @@ -982,7 +981,7 @@ static int mtd_otp_nvmem_add(struct mtd_info *mtd) err: nvmem_unregister(mtd->otp_user_nvmem); - return err; + return dev_err_probe(dev, err, "Failed to register OTP NVMEM device\n"); } /**