Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp4528061ybb; Tue, 14 Apr 2020 09:01:48 -0700 (PDT) X-Google-Smtp-Source: APiQypIG80xoSSUYbXoBnq5OFER5PaepHqOgEoyH9cfYqbgNZZqkw8MpXoJvmy8Apv8+XQ7A82fj X-Received: by 2002:a17:906:e098:: with SMTP id gh24mr881183ejb.44.1586880107918; Tue, 14 Apr 2020 09:01:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586880107; cv=none; d=google.com; s=arc-20160816; b=UL2HUWAcpFAg5LRHsHz8Rkea2AewBCdMYR1qliKRwELX1JPt4laV6mv7yD8eP+faYS nFeMXFTweX6sOJca6LfRCgeEwt1r8ZdGG0n7ND7brG1DTsgOdDHkA+VSrrhIkR5oAIgd U3MN3b5VoPHikFzwd1a+LeAi12H+YJi0bCsrVZQJT4gzTATFXXYGoE0tZACnzVO0z+hp UG7xbIeycaPOUvzc1OeSQrZba141XwI8kt+OSM9XhOL2dWFTvCi1pMjEQO8Q9BrtTGda RfNy/lOnGZhSZGq8FIlVGdGvwzUK0LrpeR5X0kZ3i1rXh6tNwbr2QFiRhdyzrMUFLqR7 776A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=J2YgFVTdqWTx53/KvMEkRUTg4JW/OzshuM2bWIQT7g4=; b=R53uxFF0/OH9DvRW5iBN6wn19nfq8RkX/fW3mvPnw6sMg66KKBtVr6k60+VuhdFuLf OzfNCzI2DA2OhJuthQyqq3WeuyLBLRHLk4xidgQm5nf4gtMec7+fCc87XdKvAghiddIV 43Njhq9fFa4DHt2SyRFqPVi4MlRgTr+J0bdHaGRC+bZYd6CtIU7hFbrXYokYlFFEPSnr 0GjS/eWxWAnDnz+0WJgKcYh4XGs8wyTrot5hk8rtzoDMyouavbmMNK/pzzEAelt44p/1 IXkdjvMB+zaglADyuDsmWlSJ5HWD5OmNP2Pn/IyjZd1jK51oj06CtMTs8k4yf/s+HzJv y+KA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=HRMb8Jjd; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m10si7851493ejb.93.2020.04.14.09.01.22; Tue, 14 Apr 2020 09:01:47 -0700 (PDT) Received-SPF: pass (google.com: best guess record for 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=@kernel.org header.s=default header.b=HRMb8Jjd; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732802AbgDNNrt (ORCPT + 99 others); Tue, 14 Apr 2020 09:47:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:33704 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732790AbgDNNrm (ORCPT ); Tue, 14 Apr 2020 09:47:42 -0400 Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 553C72078B for ; Tue, 14 Apr 2020 13:47:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1586872061; bh=zPGc63UmWLc/+H/vjVjMmsftRUnohKoZ25/OzLAX5q0=; h=References:In-Reply-To:From:Date:Subject:To:From; b=HRMb8JjdVUWax/yRhGpGbsXJtWA0MwsXbW5hdYtmysQU0jyHCuyXJUqnSyIuwOjhh saVHqWredVkvYW0WSYQHrXBHg+oS/u8bANzIjtXP42QCBKNS7BMMYtH2MnBm9y+iFX Dr9wWT0Ih9G62vdBgNLHljzN1U4Cil7VH86QZa/I= Received: by mail-lf1-f52.google.com with SMTP id l11so9423854lfc.5 for ; Tue, 14 Apr 2020 06:47:41 -0700 (PDT) X-Gm-Message-State: AGi0PuYlgS+G3o9T1PfeJff+l6IFMnf4YBYapyTmxwxPyjx77WcJZ3ij bxUoarGF6Fu7TtZwf2PgH3O7gdsRnxFOPGRZ11U= X-Received: by 2002:ac2:551e:: with SMTP id j30mr14307830lfk.179.1586872059357; Tue, 14 Apr 2020 06:47:39 -0700 (PDT) MIME-Version: 1.0 References: <20200401100240.445447-1-ribalda@kernel.org> <20200402065953.9974-1-ribalda@kernel.org> In-Reply-To: <20200402065953.9974-1-ribalda@kernel.org> From: Ricardo Ribalda Delgado Date: Tue, 14 Apr 2020 15:47:23 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2] mtd: Fix mtd not the same name not registered if nvmem To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , linux-mtd@lists.infradead.org, LKML , Boris Brezillon , Tudor Ambarus Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Ping? On Thu, Apr 2, 2020 at 8:59 AM Ricardo Ribalda Delgado wrote: > > When the nvmem framework is enabled, a nvmem device is created per mtd > device/partition. > > It is not uncommon that a device can have multiple mtd devices with > partitions that have the same name. Eg, when there DT overlay is allowed > and the same device with mtd is attached twice. > > Under that circumstances, the mtd fails to register due to a name > duplication on the nvmem framework. > > With this patch we add a _1, _2, _X to the subsequent names if there is > a collition, and throw a warning, instead of not starting the mtd > device. > > [ 8.948991] sysfs: cannot create duplicate filename '/bus/nvmem/devices/Production Data' > [ 8.948992] CPU: 7 PID: 246 Comm: systemd-udevd Not tainted 5.5.0-qtec-standard #13 > [ 8.948993] Hardware name: AMD Dibbler/Dibbler, BIOS 05.22.04.0019 10/26/2019 > [ 8.948994] Call Trace: > [ 8.948996] dump_stack+0x50/0x70 > [ 8.948998] sysfs_warn_dup.cold+0x17/0x2d > [ 8.949000] sysfs_do_create_link_sd.isra.0+0xc2/0xd0 > [ 8.949002] bus_add_device+0x74/0x140 > [ 8.949004] device_add+0x34b/0x850 > [ 8.949006] nvmem_register.part.0+0x1bf/0x640 > ... > [ 8.948926] mtd mtd8: Failed to register NVMEM device > > Signed-off-by: Ricardo Ribalda Delgado > --- > v2: I left behind on my patch a > > mtd->nvmem = NULL; > > from my tests. Sorry. > > drivers/mtd/mtdcore.c | 35 ++++++++++++++++++++++++++++++++++- > 1 file changed, 34 insertions(+), 1 deletion(-) > > diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c > index 5fac4355b9c2..7a4b520ef3b0 100644 > --- a/drivers/mtd/mtdcore.c > +++ b/drivers/mtd/mtdcore.c > @@ -28,6 +28,7 @@ > #include > #include > #include > +#include > > #include > #include > @@ -545,13 +546,34 @@ static int mtd_nvmem_reg_read(void *priv, unsigned int offset, > return retlen == bytes ? 0 : -EIO; > } > > +static int nvmem_next_name(const char *init_name, char *name, size_t len) > +{ > + unsigned int i = 0; > + int ret = 0; > + struct nvmem_device *dev = NULL; > + > + strlcpy(name, init_name, len); > + > + while ((ret < len) && > + !IS_ERR(dev = nvmem_device_find(name, device_match_name))) { > + nvmem_device_put(dev); > + ret = snprintf(name, len, "%s_%u", init_name, ++i); > + } > + > + if (ret >= len) > + return -ENOMEM; > + > + return i; > +} > + > static int mtd_nvmem_add(struct mtd_info *mtd) > { > struct nvmem_config config = {}; > + char name[128]; > + int ret = 0; > > config.id = -1; > config.dev = &mtd->dev; > - config.name = mtd->name; > config.owner = THIS_MODULE; > config.reg_read = mtd_nvmem_reg_read; > config.size = mtd->size; > @@ -562,6 +584,13 @@ static int mtd_nvmem_add(struct mtd_info *mtd) > config.no_of_node = true; > config.priv = mtd; > > + if (mtd->name) { > + ret = nvmem_next_name(mtd->name, name, sizeof(name)); > + if (ret < 0) > + return ret; > + config.name = name; > + } > + > mtd->nvmem = nvmem_register(&config); > if (IS_ERR(mtd->nvmem)) { > /* Just ignore if there is no NVMEM support in the kernel */ > @@ -573,6 +602,10 @@ static int mtd_nvmem_add(struct mtd_info *mtd) > } > } > > + if (ret) > + dev_warn(&mtd->dev, "mtdev %s renamed to %s due to name collision", > + mtd->name, nvmem_dev_name(mtd->nvmem)); > + > return 0; > } > > -- > 2.25.1 >