Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1691782pxb; Thu, 4 Nov 2021 06:53:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJypsGUoNbtinCsLTZVdkeMAVqcyJKoLEyo67vAFi1DUI6lrOPzveuW7/nYwXF84KDofztGX X-Received: by 2002:a17:907:6da4:: with SMTP id sb36mr63964423ejc.490.1636034023442; Thu, 04 Nov 2021 06:53:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1636034023; cv=none; d=google.com; s=arc-20160816; b=d/Ej3HHZwBHUWqbt2BcqtmzPcbKVZf2jO5g2Dv+c1qbZmIKUcJvygX86oCuoLtLVIX k69ierjwKEgabDeS0pvFH6SNoUDDlNGiNzrlNbrhW6fWrNJBA9ESvuzr6D+iZkLVXFKq G1NQ1Wywh6vXzKn0TD0YIhkhVDCVF6khJSzhAO71jHFY2yeUL3h8JZRP0w8o1J3s1M9Y xrUgk7Hm3TgT4iQDimYRzyr7cESszCfKK+SpEsFPGxIx7WAaX+7Oqh4BlXNFe/wfDhrn AVcNnUMgMKfajKa/8Y++7/QkjVsDKlhVH4LalvFsnlBTlRQkoQ1aIryvB03QPawTM+2b LLNg== 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=hzn7IpexuRy/8kkxG32qAgyZ+pY82Q0NyVwXVe3onQk=; b=LzSF9Cunt9m27cIfjJTJGGQItecYM46j2lIXAD7rr3i3dEs29+TeIBHRRsnSuJElkY pFhiso4koC3N4YljLRrzGIkRS1kSFD5JYl3BVwAfTYAKzodQ9Nr3BUJqSA8duqtYlQ23 Y0hGIrK+Dy0YIA0Zg6d4h3z68tg9S9q1/X7PPwbjyKyPgpFhgoxSgZ89R/Xjwc+Ywbok bNHmPi7YI2JAXct2NWRz3p/VPn+Pu585Uhn4R5QCAYRBZXfDnnwnERGdqsSk+6DLpAoI AxJzE3SCn7MWsuR5LcdLY6cIjhnHYVGc7DQq4+d4ucqn+aimJWzbj5BNavB5XBbaPVlf b0XQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2016061301 header.b=lQaeVNL3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bd6si8302038edb.303.2021.11.04.06.53.03; Thu, 04 Nov 2021 06:53:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2016061301 header.b=lQaeVNL3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230511AbhKDNvb (ORCPT + 99 others); Thu, 4 Nov 2021 09:51:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34346 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230401AbhKDNvb (ORCPT ); Thu, 4 Nov 2021 09:51:31 -0400 Received: from ssl.serverraum.org (ssl.serverraum.org [IPv6:2a01:4f8:151:8464::1:2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 106C2C061714 for ; Thu, 4 Nov 2021 06:48:53 -0700 (PDT) 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 ECDHE (P-384) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by ssl.serverraum.org (Postfix) with ESMTPSA id 4BC0C22221; Thu, 4 Nov 2021 14:48:49 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2016061301; t=1636033729; 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=hzn7IpexuRy/8kkxG32qAgyZ+pY82Q0NyVwXVe3onQk=; b=lQaeVNL3uDl1TL6fU5DXj+vyUA7hGIo4S1NzHbOKWOPC0AI8u8P7nydtrkLZWpAYEgXApI 35xq/DpHgQ/lfWexcu/y6RtxfVdrH8U1Vz5EHpM3u6U1CuGgaYdSk3wLIsJb2iFA1DWYvp S9TcPC3W01amoupb/ePK/DG0bSTfpOY= From: Michael Walle To: linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Michael Walle Subject: [PATCH] mtd: core: provide unique name for nvmem device Date: Thu, 4 Nov 2021 14:48:43 +0100 Message-Id: <20211104134843.2642800-1-michael@walle.cc> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If there is more than one mtd device which supports OTP, there will be a kernel warning about duplicated sysfs entries and the probing will fail. This is because the nvmem device name is not unique. Make it unique by prepending the name of the mtd. E.g. before the name was "user-otp", now it will be "mtd0-user-otp". For reference the kernel splash is: [ 4.665531] sysfs: cannot create duplicate filename '/bus/nvmem/devices/user-otp' [ 4.673056] CPU: 0 PID: 1 Comm: swapper/0 Not tainted 5.15.0-next-20211101+ #1296 [ 4.680565] Hardware name: Kontron SMARC-sAL28 (Single PHY) on SMARC Eval 2.0 carrier (DT) [ 4.688856] Call trace: [ 4.691303] dump_backtrace+0x0/0x1bc [ 4.694984] show_stack+0x24/0x30 [ 4.698306] dump_stack_lvl+0x68/0x84 [ 4.701980] dump_stack+0x18/0x34 [ 4.705302] sysfs_warn_dup+0x70/0x90 [ 4.708973] sysfs_do_create_link_sd+0x144/0x150 [ 4.713603] sysfs_create_link+0x2c/0x50 [ 4.717535] bus_add_device+0x74/0x120 [ 4.721293] device_add+0x330/0x890 [ 4.724791] device_register+0x2c/0x40 [ 4.728550] nvmem_register+0x240/0x9f0 [ 4.732398] mtd_otp_nvmem_register+0xb0/0x10c [ 4.736854] mtd_device_parse_register+0x28c/0x2b4 [ 4.741659] spi_nor_probe+0x20c/0x2e0 [ 4.745418] spi_mem_probe+0x78/0xbc [ 4.749001] spi_probe+0x90/0xf0 [ 4.752237] really_probe.part.0+0xa4/0x320 .. [ 4.873936] mtd mtd1: Failed to register OTP NVMEM device [ 4.894468] spi-nor: probe of spi0.0 failed with error -17 Fixes: 4b361cfa8624 ("mtd: core: add OTP nvmem provider support") Signed-off-by: Michael Walle --- drivers/mtd/mtdcore.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c index 9186268d361b..fc0bed14bfb1 100644 --- a/drivers/mtd/mtdcore.c +++ b/drivers/mtd/mtdcore.c @@ -825,8 +825,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; - /* just reuse the compatible as name */ - config.name = compatible; + config.name = kasprintf(GFP_KERNEL, "%s-%s", dev_name(&mtd->dev), compatible); config.id = NVMEM_DEVID_NONE; config.owner = THIS_MODULE; config.type = NVMEM_TYPE_OTP; @@ -842,6 +841,7 @@ static struct nvmem_device *mtd_otp_nvmem_register(struct mtd_info *mtd, nvmem = NULL; of_node_put(np); + kfree(config.name); return nvmem; } -- 2.30.2