Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp676288iog; Mon, 13 Jun 2022 10:23:53 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uttmtED7kFQsVmPZhxdXx52IgpKfXyHHNEHtucg59cN2yB4HMEjgP20Zq4diyGd281gIFH X-Received: by 2002:a17:902:e8d6:b0:161:ea52:cd52 with SMTP id v22-20020a170902e8d600b00161ea52cd52mr337243plg.71.1655141033739; Mon, 13 Jun 2022 10:23:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655141033; cv=none; d=google.com; s=arc-20160816; b=X7s+ipaLOuvzx+ZSuHecwT760q2MOOXqdNmIABnr5PVOx2uBSxTq6qr9BGtsKVlyzy WtdLqTBpfY2W/1KeLHrY6KciJgO7vmz6p8QsHRZSwEa4nM+vW5L8o58IUEGkoC1T+wll g78cLuvYbylhXAIn7b1TaW6sDmpsQKWeVzn9T+Dp8muARXwXy1Aqz2LhVXtwb77nnr2d 4aubDnSYx8lGwIsGpl7wYbwvurTT/+1D6NkRksogAH02eRRFGsZ2fCeQ3zQLAoQrzcAi nLVKT9VH8eRI8RMp15iIOmuPDq3YPOEoBPWnZbOnz7yD/IFieK0INOfRUcuXbzpqkRIv VtAA== 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 :organization:references:in-reply-to:message-id:subject:cc:to:from :date:dkim-signature; bh=vgP4W2WcGLch0G1Z/a9d2JFCittPWMEM8INjyTTlF+o=; b=EJgravUhtvNWbS/PMM6H3Su3yWBeZ/B4YL3xojMkYw6OHOzR7UzL3ZZcEEAXkVBBIU PLOBaSiMMnUyT5fbyLeSjrLaL6c457IUzr+u+6/EOcpVf7HgIQglIf388DhZZ8rpu2V3 bKu+r+40vCLdmMNU/ziHfA8gFuTVwbkQOl3UBn71aFV0GEZ75ScgzHqIk5PswvkcOiVN KBeQKDMRGbf4cng5QcVCMYlzxaqWG1bis2CBEsdn5bjYY2iYSNy0UWahvf4RnPULobdF Qi4EtczpeGxvaqnIfWaBa690xXrw1Q1WPHVgh59E3blbw+F8ypHLRvYEdSLv3Eu3HX8X YwFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b="RHeR1FQ/"; 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=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ch9-20020a17090af40900b001ea9218215bsi8651013pjb.67.2022.06.13.10.23.40; Mon, 13 Jun 2022 10:23:53 -0700 (PDT) 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=@bootlin.com header.s=gm1 header.b="RHeR1FQ/"; 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=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244819AbiFMQNJ (ORCPT + 99 others); Mon, 13 Jun 2022 12:13:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244865AbiFMQMU (ORCPT ); Mon, 13 Jun 2022 12:12:20 -0400 Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6FFFD2314C; Mon, 13 Jun 2022 07:04:18 -0700 (PDT) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 732A81BF204; Mon, 13 Jun 2022 14:04:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1655129056; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vgP4W2WcGLch0G1Z/a9d2JFCittPWMEM8INjyTTlF+o=; b=RHeR1FQ/oaGkFKglO95swbvRFaOAhB3zVTr+Iu4qezNsX0NWdqd7VE7g+YxKY7iFNIVvpD MRpE2qdYhxKxv4prc6X1uYby+AmIMIrmMKOW5nDMKrbDKLpjCe34ppD9oFa07wgsvyE3DY EohfY0giovrsbV8ylO/1gDQjesMK33L6IoOhYAVGPb6Ei/9+SDN7Gl5sAqQ406fyQ5FcbH TjZcAVfd5btd9c2VyMjB3W2zfTCFIfEiC47EM29IDqY0fopU4MX4Bp+YwiRGWOH3cYXBTi a6JfGmL63vnILBbjFDpLHbGSBRhUAqJf0GRIE95tXyPs5qDjFuE4VPDITSQZhw== Date: Mon, 13 Jun 2022 16:04:11 +0200 From: Miquel Raynal To: =?UTF-8?B?UmFmYcWCIE1pxYJlY2tp?= Cc: Srinivas Kandagatla , Richard Weinberger , Vignesh Raghavendra , Tom Rini , Ahmad Fatoum , linux-arm-kernel@lists.infradead.org, u-boot@lists.denx.de, devicetree@vger.kernel.org, linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, =?UTF-8?B?UmFmYcWCIE1pxYJlY2tp?= Subject: Re: [PATCH V3 1/2] mtd: allow getting MTD device associated with a specific DT node Message-ID: <20220613160411.48b07515@xps-13> In-Reply-To: <20220611204651.19947-1-zajec5@gmail.com> References: <20220611204651.19947-1-zajec5@gmail.com> Organization: Bootlin X-Mailer: Claws Mail 4.0.0 (GTK+ 3.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE 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 Hi Rafa=C5=82, zajec5@gmail.com wrote on Sat, 11 Jun 2022 22:46:50 +0200: > From: Rafa=C5=82 Mi=C5=82ecki >=20 > MTD subsystem API allows interacting with MTD devices (e.g. reading, > writing, handling bad blocks). So far a random driver could get MTD > device only by its name (get_mtd_device_nm()). This change allows > getting them also by a DT node. >=20 > This API is required for drivers handling DT defined MTD partitions in a > specific way (e.g. U-Boot (sub)partition with environment variables). >=20 > Signed-off-by: Rafa=C5=82 Mi=C5=82ecki > --- > V3: First introduction of of_get_mtd_device_by_node() >=20 > mtd maintainers: please let know how would you like this patch > processed. Would that be OK for you to Review/Ack it and let it go > through NVMEM tree? Yes > --- > drivers/mtd/mtdcore.c | 28 ++++++++++++++++++++++++++++ > include/linux/mtd/mtd.h | 1 + > 2 files changed, 29 insertions(+) >=20 > diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c > index 9eb0680db312..7dc214271c85 100644 > --- a/drivers/mtd/mtdcore.c > +++ b/drivers/mtd/mtdcore.c > @@ -1154,6 +1154,34 @@ int __get_mtd_device(struct mtd_info *mtd) > } > EXPORT_SYMBOL_GPL(__get_mtd_device); > =20 > +/** > + * of_get_mtd_device_by_node - obtain an MTD device associated with a gi= ven node > + * > + * @np: device tree node > + */ > +struct mtd_info *of_get_mtd_device_by_node(struct device_node *np) Shall we try to use a more of-agnostic syntax or is it too complex here? > +{ > + struct mtd_info *mtd =3D NULL; > + struct mtd_info *tmp; > + int err; > + > + mutex_lock(&mtd_table_mutex); > + > + err =3D -ENODEV; > + mtd_for_each_device(tmp) { > + if (mtd_get_of_node(tmp) =3D=3D np) { > + mtd =3D tmp; > + err =3D __get_mtd_device(mtd); > + break; > + } > + } > + > + mutex_unlock(&mtd_table_mutex); > + > + return err ? ERR_PTR(err) : mtd; > +} > +EXPORT_SYMBOL_GPL(of_get_mtd_device_by_node); > + > /** > * get_mtd_device_nm - obtain a validated handle for an MTD device by > * device name > diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h > index 955aee14b0f7..6fc841ceef31 100644 > --- a/include/linux/mtd/mtd.h > +++ b/include/linux/mtd/mtd.h > @@ -677,6 +677,7 @@ extern int mtd_device_unregister(struct mtd_info *mas= ter); > extern struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num); > extern int __get_mtd_device(struct mtd_info *mtd); > extern void __put_mtd_device(struct mtd_info *mtd); > +extern struct mtd_info *of_get_mtd_device_by_node(struct device_node *np= ); > extern struct mtd_info *get_mtd_device_nm(const char *name); > extern void put_mtd_device(struct mtd_info *mtd); > =20 Thanks, Miqu=C3=A8l