From patchwork Wed Mar 8 08:20:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 66104 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp213005wrd; Wed, 8 Mar 2023 00:44:36 -0800 (PST) X-Google-Smtp-Source: AK7set/YM5ZiR+HlHKpsyDUnllgw5fUNYVcb7TrCPx/hpLIwvoqhcEwFhYe0w6qtc9upvhAfbbTI X-Received: by 2002:a50:ed83:0:b0:4c3:4da1:3df8 with SMTP id h3-20020a50ed83000000b004c34da13df8mr15266967edr.17.1678265075971; Wed, 08 Mar 2023 00:44:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678265075; cv=none; d=google.com; s=arc-20160816; b=TTOZP8/Dbxr3vwzDrRsp6dryWh5yoi97aBQHt18RlT6tCqWgxeQyI4vSDm3fiOSrDC +s8raeOfRCSxsBk0UhdyU8iRone0eQzQcvsj3eamJgN5rn/UgG3kkkevLhZmSGKDjsa1 bX46KMUsAOa8VK6s3eKgFwLFX7o2QmtjkO5bKDTiHPIDkUlCqelJ1WmuVpsM25Vrc8J5 uK12iKAPsn5Ihy0i0Q+T/RjqKxAu6myXSaPcI4x8eXH8tCIuk04prfPqzGHF3uoOS0hL EL5eTpmUYI6AzK1aNRggU78fX2+AfXUN9tGXsUe+8CaysZuR/I78st5RDM6TEtR5eSgH mw7Q== 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=yET4dLTaObig7qd5g7VQ441qs/AE4iGVqJGo9VFvELM=; b=SLX2FRWxsFvIDa6zHLC8L2JJ2+i4erMkjqxBXj2YTeGyoXVIxR8gdwaeO6zj0Ijwl2 hojGZDepFmDtd/Ovellx9s6whp+KiLx2nz9o9y4DD8m4aqqJ0bVJjA2KdkPciS4xT2FI O36NGgvB2vD90KajYnXhHM/MZdQv789U1lGom4vZiEJVZPNL5aNhi7p9Dcf4K7RNTs3w k/UHgNHnSWktRhipavTkr1/UqZgTeGepNp+LcWBtm+K0C2SebSUpmR9pZ/RVxwNpL3Zi 3BjCxd6CknjKpdTz4F3yyVdEx7QmKO1if7fgUulfWlPguDfFZIzr2rpM+1h2jLu4Ca5T 0yaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2022082101 header.b=Yw7ZU0D5; 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 j3-20020aa7c403000000b004aab3450a00si4348742edq.498.2023.03.08.00.44.12; Wed, 08 Mar 2023 00:44:35 -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=Yw7ZU0D5; 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 S230117AbjCHIVy (ORCPT + 99 others); Wed, 8 Mar 2023 03:21:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230129AbjCHIVN (ORCPT ); Wed, 8 Mar 2023 03:21:13 -0500 Received: from mail.3ffe.de (0001.3ffe.de [IPv6:2a01:4f8:c0c:9d57::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CDAF0B1B0F; Wed, 8 Mar 2023 00:20:39 -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 EC788164F; Wed, 8 Mar 2023 09:20:30 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2022082101; t=1678263631; 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=yET4dLTaObig7qd5g7VQ441qs/AE4iGVqJGo9VFvELM=; b=Yw7ZU0D5aF0J5rT2eBxLrjCuBMRUKxNw2f+XWYKNJolrx44g2bHUFHE8p3PGmKRaiK3NjO EhKRVtHDeFCLbpwJ0BLElXf5IF0cet5xBPnWy7122aUZap0x1redtfRJOvsND7Wv70hYMs z3u4FPQfw/s9iHjZvkskAPldMNDfByx9nA5lbmlUpZJz+K1MyELdIVxqVhPtCfdrnscyHl Vq/j/WslG4eHXZn0QuLaq+t8Uwcks9Uuu80N4RltNqlA/MhnFm4/wtSEgUIxbNicOewKZu a3oTbl6c89VhTkeHI70u/KeKpPvxxMaUdL4bhyfhr3Zxmlfm3+ajcskYaf3M4A== 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 v2 1/4] mtd: core: provide unique name for nvmem device, take two Date: Wed, 8 Mar 2023 09:20:18 +0100 Message-Id: <20230308082021.870459-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, URIBL_BLOCKED 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?1759788480550509695?= 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 --- v2: - actually use NVMEM_DEVID_AUTO as described in the commit message drivers/mtd/mtdcore.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c index 0feacb9fbdac..8fc66cda4a09 100644 --- a/drivers/mtd/mtdcore.c +++ b/drivers/mtd/mtdcore.c @@ -888,8 +888,8 @@ 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.id = NVMEM_DEVID_AUTO; config.owner = THIS_MODULE; config.type = NVMEM_TYPE_OTP; config.root_only = true; @@ -905,7 +905,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 Wed Mar 8 08:20:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 66094 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp211902wrd; Wed, 8 Mar 2023 00:40:49 -0800 (PST) X-Google-Smtp-Source: AK7set+S0WYAc23HPx5MOaonoGCIvF6MPAXJG1PEQQtMWlyJgGWVZpAfIwrsb4HaK+KGIqLCsQgI X-Received: by 2002:a17:907:392:b0:8b1:32dd:3b0 with SMTP id ss18-20020a170907039200b008b132dd03b0mr18924513ejb.57.1678264849174; Wed, 08 Mar 2023 00:40:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678264849; cv=none; d=google.com; s=arc-20160816; b=kaU4bjeYaS78Jmp9CAyFog4Htcm28ldHlTDnQ23JABJMpjW+Ku74RxBJ2HDc5JWAP5 DJlVMrX1F/MPTxKLS4oN5GzD7lmgsR7E2yI2pZbXbFKYWeh96iUH6bIum3VTQbDSlHUc JiruJjdqrhEEAiryhcXcyIqBW/6WP8Q0ZMZPBm5MdqmjG4CH7Q67/igC+sgczBbxhfoD dq6gKVF6H7CoY5R3toUBGpIi+IGVgrgPj+N0sG66KHEDqAln0jnn6lcGxF8MNBA/1Sn9 8sMSNZ9LuTPhIiyPJCvNDnvJBe8SECv1FH89kgp3EFKhnnptbzuu6g8UrfeLIjiv1EH/ ULKw== 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=wAMTuERNi5qJ5J2h23oJyeBeqJlcNnQwXiDuZ+qFEoo=; b=OEGFYxzztDgi6pbLZXlKVaIIxStMk4WGyf9yfiNmH9KHdvT5osEDh7x16JXvB3NjoG 8T6ooXiVWopyXxy8pID7xkEcLbyJtN5kEcfYkEYK/VG/xNIPYw6YY8EtSI8Zpz5Gv+11 6+s2+46m5inVMjp2x6O5bM0Lb//gTY0oU7lfFBzaZiezW5FsiW+nKwYf7t9kaWvrwWhS PBbKNwQrTQ3EW9C/HeQpVBsCsU0ZfURQtIf04aZHAc1LbVfsXUOZCpr2H22ptuK9GwhC pmx3gA/gbNZii7UO9cmc6hm61TpzCEPqBFB7g595PIZbtipYwYB3Q/8HkgpnU5ipzBqk xYxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2022082101 header.b=PKL5PtYz; 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 dm14-20020a170907948e00b009146960af95si4255822ejc.698.2023.03.08.00.40.25; Wed, 08 Mar 2023 00:40:49 -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=PKL5PtYz; 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 S230173AbjCHIWE (ORCPT + 99 others); Wed, 8 Mar 2023 03:22:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39656 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230192AbjCHIVW (ORCPT ); Wed, 8 Mar 2023 03:21:22 -0500 Received: from mail.3ffe.de (0001.3ffe.de [159.69.201.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3FFC850FB5; Wed, 8 Mar 2023 00:20:52 -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 9B5CA1682; Wed, 8 Mar 2023 09:20:31 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2022082101; t=1678263631; 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=wAMTuERNi5qJ5J2h23oJyeBeqJlcNnQwXiDuZ+qFEoo=; b=PKL5PtYz/bMjz4cxIcC8vIUdQ4+Jm10yyo3BPNlL6qIwlzqBZWnL7WnS/uPoNMvNZMUS+J rBEDvg8HzmWRea8GK1Mex6fjBqAFse89WwuT+U1MuBBFmdKjnXXft1ldkzyoAAeg81ac5s crYfufJ4eca0J5ltVqMIZJA+aBYd+eEH86LhOd4eVZDsLWvKfSKhLtE7Osnry4V77ANvoF 2GajLhZZEtY/6YHAR9IkQyKyNs7nxaVyT1uflo5GtJPEybtU5D23NhchnwJ1UTDdIcngKq Cp/WNzTiax8PWJH+n8UIYGbl3Ni775RvqA8XMAFEBTvNWM7ewkZ/1Vqbvtg36A== 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 v2 2/4] mtd: core: fix nvmem error reporting Date: Wed, 8 Mar 2023 09:20:19 +0100 Message-Id: <20230308082021.870459-2-michael@walle.cc> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230308082021.870459-1-michael@walle.cc> References: <20230308082021.870459-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, URIBL_BLOCKED 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?1759788242331161834?= X-GMAIL-MSGID: =?utf-8?q?1759788242331161834?= 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 --- v2: - none 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 8fc66cda4a09..c38a13cb8d5e 100644 --- a/drivers/mtd/mtdcore.c +++ b/drivers/mtd/mtdcore.c @@ -939,6 +939,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; @@ -952,7 +953,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; @@ -970,7 +971,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 Wed Mar 8 08:20:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 66103 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp212842wrd; Wed, 8 Mar 2023 00:43:59 -0800 (PST) X-Google-Smtp-Source: AK7set/AtPEYDbrY3jx5fwH+6WN5ZYX659G0V++L2upz/xzEIjbJRyhEvBoxZMcYrNGmUJMf+zu+ X-Received: by 2002:a17:906:fe0c:b0:8b3:b74:aeb5 with SMTP id wy12-20020a170906fe0c00b008b30b74aeb5mr22059466ejb.30.1678265039080; Wed, 08 Mar 2023 00:43:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678265039; cv=none; d=google.com; s=arc-20160816; b=cf5WN2Fo8gAi/9WzrjjwEhE5+OZ1FBWjJRALT6eAxpeWUsCvs+Hbw3SseKJhee0CQZ TsgYaR22kjqkjy8TePS7MTTyRpuxUGUsDWXE0sXBUeO7g7OCd7crhd7AojhqEkTelnGb d+eGm5EpPZbc6zYITP59wWfDC9CqKCy2avqgGZ7pHK8x5FQETzbvWmE1iPJn9NcJ84Rn TOU3xrbKhS3XB7l+Ykf5livycNCec3GUBGEBIg6k+tqBYFfdj7CRCa3lFh35PET3WIyr UyNmVscLYnaTiulFGIzhGu6OF9Y49aL8mC7tMT1m5OQ6NrqcTgCWl6pK1uOjy4D+IWWl TMrA== 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=pQro8lAsxYdfyKtXuzQP2F4xpI7uvYsRP5+6tnRPfKk=; b=YbiF4UQ0XhYYwSsIdukxemESU2ZU5x+RckIrAnIomM2y/G2YXqlSWtTXZJrA39LUgv ZW87tpcKJWr3Sq0v+QprDcdLEbLOA8SVtKjpZxm0qWSDUhww7eWNHY6ruahW+uyOkZSr T+4eI4KsG+MucMCZEE+uq2TXxwSdOCR36i4rJSsC2zuNI0MKcZ02Kj2nqUUl1SEZXq+J 462et5azBUTMpKvzN28BSW84TfP2bz+9IHoX8mjnOUiEEDUoDjGO+vIewJ8HuIeFgBro Nlo4ka0yKrtxqBhiqf67oQI6TiAymyytD/rYRlR083hK6iy3DA3gQmMajGEm9fD90QGR h+Zw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2022082101 header.b=QFTk0YH6; 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 kg16-20020a17090776f000b008d9d55885e3si14734731ejc.456.2023.03.08.00.43.35; Wed, 08 Mar 2023 00:43:59 -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=QFTk0YH6; 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 S229565AbjCHIWH (ORCPT + 99 others); Wed, 8 Mar 2023 03:22:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230193AbjCHIVW (ORCPT ); Wed, 8 Mar 2023 03:21:22 -0500 Received: from mail.3ffe.de (0001.3ffe.de [159.69.201.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 41D04B06D6; Wed, 8 Mar 2023 00:20:52 -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 2768516DE; Wed, 8 Mar 2023 09:20:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2022082101; t=1678263632; 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=pQro8lAsxYdfyKtXuzQP2F4xpI7uvYsRP5+6tnRPfKk=; b=QFTk0YH6t7zZMfpisKd1d1db9X237jRHj3oezB+gQ69KGAq+FeRGnktvA8Eo6mJGOd7b2/ AEjC/DbAD1os8B0YfEkDU9n/RIZjz+FD+A2rDwBSICQqoDIJLXNa2X66DbmiymyZDYHhpi zdjIuvQR1S1ynay7zaGTHw0/6Tso0HEsFV4mbOcTMuKHNvSAbMO2EHBvOX8aVJRXwP6Bnw K6m8MdVzc5QAHjWyWr+SP55SLwAORXhekigxg7KwvyZ4eOlo2ORSIC4dt0F5UuwNsnaJhJ n8Wm6siWFaXBn1gh3AGdWFtf+8cG+a9zzZqwNVTn+J/sDEU0Z1q/1thSUGaGxw== 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 v2 3/4] mtd: core: fix error path for nvmem provider Date: Wed, 8 Mar 2023 09:20:20 +0100 Message-Id: <20230308082021.870459-3-michael@walle.cc> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230308082021.870459-1-michael@walle.cc> References: <20230308082021.870459-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, URIBL_BLOCKED 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?1759788441904627521?= X-GMAIL-MSGID: =?utf-8?q?1759788441904627521?= 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 --- v2: - none 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 c38a13cb8d5e..0bc9676fe029 100644 --- a/drivers/mtd/mtdcore.c +++ b/drivers/mtd/mtdcore.c @@ -1023,10 +1023,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 */ @@ -1061,9 +1065,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 Wed Mar 8 08:20:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 66109 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp213320wrd; Wed, 8 Mar 2023 00:45:35 -0800 (PST) X-Google-Smtp-Source: AK7set9dP74XfMXXn0X4JlnEpF7bufD4ghncDa63JLBtszBf1Q1dsL4j+6DE98FnpwISFRPS9Twx X-Received: by 2002:a17:907:869f:b0:8a6:5720:9101 with SMTP id qa31-20020a170907869f00b008a657209101mr20797837ejc.4.1678265135757; Wed, 08 Mar 2023 00:45:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678265135; cv=none; d=google.com; s=arc-20160816; b=GvCOxjOKLYDbQUcNbTPJ0bGbUitfA/TpYFB8EGxFj0hlOJTuij2UQ474+akNqSbWj6 FrabaUHK+Hzz0F0xM+ILbvnNkn2aim4gw0A/ne0uvnhPMPkRLPLuX7un7g2Q+CVqMANH SHxD35RT8DlUr9Sci1Qm3g+/fWPu4LCaz9FvpQkQKyrA68P71ZA0aKO5k0wVyPtcGo/J KIIYBN9XWZtIwCYEZXkXhML6AKdVIlkAx64SdqbpdMlYd6zNTZ5mwI0TO5GLRJD/RVXn T1lgyS2IjxGHdnyhXGFo+tv/hqdljG5u6U9xbjZINXewG8SXqMRPuN4KQS8oe3kC8Ul6 B5lQ== 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=ktfcqSBRe8eRK5A5gzbgUANLuCVChHFFCI/4vtIw9Fw=; b=WCwib0INlWguHtTEUzDUCyP/okQTXx114pLAgvK0zh1HcU1uzU8+KEOLqgbLenylth TShJW2nXwpcl7J4Eqsm1YTz7ulGSZF2ZPYk+iMuGQ/he/HNiqqbjdH7coZZPNh5TqsLB X4pZGLc+RZrH9cCl4U4JWLezsdc0kgYQSSxoWh2ZUYzOgzuMoFZCFd4vkU5wPBJD7d6R Ogq0YptYorzw5zEXPh2Vg2YtrTQQagw2zimnOpnNaI69/yQeR16EpLJZPenAx7hXWCJK RxjSQzjDqxr4Pxk2WdXKv7KtUWkXclkE26fkBoLxWf7KqoGSIu5vOdHWR5ni/wJhh/h9 KUWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2022082101 header.b=Z8xfJu6e; 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 m24-20020a1709062ad800b008dd8491f9f8si11916610eje.118.2023.03.08.00.45.12; Wed, 08 Mar 2023 00:45:35 -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=Z8xfJu6e; 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 S229687AbjCHIWK (ORCPT + 99 others); Wed, 8 Mar 2023 03:22:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229717AbjCHIVW (ORCPT ); Wed, 8 Mar 2023 03:21:22 -0500 Received: from mail.3ffe.de (0001.3ffe.de [159.69.201.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 660B3144AF for ; Wed, 8 Mar 2023 00:20:53 -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 A73E216FE; Wed, 8 Mar 2023 09:20:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2022082101; t=1678263632; 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=ktfcqSBRe8eRK5A5gzbgUANLuCVChHFFCI/4vtIw9Fw=; b=Z8xfJu6e78pT1XFtaYdWug4JDZB8LYDQj0qyNdu9780y1EN7Z/O9wigVQ0VR07GfTzM1Q5 wFdBO7Q+0X8DzEbai2KJusBhyyGVU7Ikai4M8417Vm00dFkOhhHlrpNFjVVu6enyNQYz2P y3YShXURejpkbG+Xc7dUWobXW62+5wEJSVkZLn+5t3FMa91V8B7uKuzEAr5I30iwbQMNNF yOzj5NQ0NWOBUf4tT4OBoBJ7SK+cDMxwjJ5LJB8GNfSFG0UvlKOPYiTDsnZXNDnIWMUunz XroHmi+w1bpARuCpoio/PtboD11Prcfx5fPB8L70F8IIQEH4KuFbdVG1rpjEHg== 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 v2 4/4] mtd: core: prepare mtd_otp_nvmem_add() to handle -EPROBE_DEFER Date: Wed, 8 Mar 2023 09:20:21 +0100 Message-Id: <20230308082021.870459-4-michael@walle.cc> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230308082021.870459-1-michael@walle.cc> References: <20230308082021.870459-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, URIBL_BLOCKED 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?1759788543156978237?= X-GMAIL-MSGID: =?utf-8?q?1759788543156978237?= 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 --- v2: - none 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 0bc9676fe029..83a22566a8ce 100644 --- a/drivers/mtd/mtdcore.c +++ b/drivers/mtd/mtdcore.c @@ -953,8 +953,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; } @@ -971,7 +971,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; } @@ -983,7 +982,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"); } /**