Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp160296iog; Fri, 17 Jun 2022 00:42:09 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vSDE4/f2m3V1SJZUzIIA27mD4GalXvuscM+VoG3Xg7uMjOAS4ZSvFPjFKsqRwzzOC867jW X-Received: by 2002:a17:902:8e8b:b0:168:a135:d636 with SMTP id bg11-20020a1709028e8b00b00168a135d636mr7955078plb.140.1655451729656; Fri, 17 Jun 2022 00:42:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655451729; cv=none; d=google.com; s=arc-20160816; b=KyyCk0qhfuYbFwgE+oEczbbxOkyk/PL5+/zIbunHFz4tB9cgm5LZCuVMWV5EGLb5gA coNR57WXNCo/ZhaKMNTtLqBSpYFP9lJqUag5iTw2zIHB1FYLKTwFegc7uiFczSMPB7K8 f65Rt01eEqmEsrSOsddVKHZ8KaFRSCqS37jEfG2oZrYS/8BxOkp2CQj5MTqSuUMTHPo9 yXrKzSUfdtXeRMG8wjjHzvB+gEsnl8DTP/2l5CtOjxHbDz2QLB1q4UfBMJEaznh5xoAh ZeF3dGZvl06gm0alO4bUfczQLgNCrcpUUq7JirYsgk48LpnjLsnBeimuIx/H3n3OJjII t0PQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=TntuMMycs9b4KDYma/dfab8qPSs0azHP3OUYBMJJwLM=; b=Ww7yVj22OWGYtONKALARA50s92VP6Gt3PxK9BeXrysNTjBffcKfTjhzyXOpx3s9b0P Ymr6GmTUpf7T1zpv41rMzuyI4IECkERQImCbbXPCoTCuTCuuK1h6FSauGdaNU4nNsJIP eqovwYsQ7pGjwG6laIMMecv5uvj7qC/p4oeHvf43/eNRP+1Ari9Ud0mMMYSmdoV1gtyD IopssD7g0YbnW23DrDl7bmPhmXlQfD6X3fpbMvZiuBvloE12kZ27PG0OwHE49xy+G6Ll ohuLHpKgOtR2ouZiTEmkjbmRyJ0nhflvpvVO8TfbZuA86EvVD6te2o09y2uOhWugydbd PGpA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j3-20020a170903028300b0015ce8cd5066si6084358plr.246.2022.06.17.00.41.54; Fri, 17 Jun 2022 00:42:09 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378731AbiFQHBO (ORCPT + 99 others); Fri, 17 Jun 2022 03:01:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38524 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234203AbiFQHBN (ORCPT ); Fri, 17 Jun 2022 03:01:13 -0400 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7985F4F457 for ; Fri, 17 Jun 2022 00:01:12 -0700 (PDT) Received: from ptz.office.stw.pengutronix.de ([2a0a:edc0:0:900:1d::77] helo=[127.0.0.1]) by metis.ext.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1o25yW-00017n-Lh; Fri, 17 Jun 2022 09:01:00 +0200 Message-ID: <45432169-5f9d-0913-6cf9-06dc821d1c65@pengutronix.de> Date: Fri, 17 Jun 2022 09:00:57 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.0 Subject: Re: [PATCH V4 1/2] mtd: allow getting MTD device associated with a specific DT node Content-Language: en-US To: =?UTF-8?B?UmFmYcWCIE1pxYJlY2tp?= , Srinivas Kandagatla , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra Cc: Tom Rini , 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?= , Pengutronix Kernel Team References: <20220615194300.13358-1-zajec5@gmail.com> From: Ahmad Fatoum In-Reply-To: <20220615194300.13358-1-zajec5@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 2a0a:edc0:0:900:1d::77 X-SA-Exim-Mail-From: a.fatoum@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 On 15.06.22 21:42, Rafał Miłecki wrote: > From: Rafał Miłecki > > 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. > > This API is required for drivers handling DT defined MTD partitions in a > specific way (e.g. U-Boot (sub)partition with environment variables). > > Signed-off-by: Rafał Miłecki > Acked-by: Miquel Raynal Reviewed-by: Ahmad Fatoum > --- > V3: First introduction of of_get_mtd_device_by_node() > V4: Use EPROBE_DEFER > > Srinivas: in V3 Miquel said it's OK to push this patch through NVMEM > --- > drivers/mtd/mtdcore.c | 28 ++++++++++++++++++++++++++++ > include/linux/mtd/mtd.h | 1 + > 2 files changed, 29 insertions(+) > > diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c > index 9eb0680db312..3613cc142f25 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); > > +/** > + * of_get_mtd_device_by_node - obtain an MTD device associated with a given node > + * > + * @np: device tree node > + */ > +struct mtd_info *of_get_mtd_device_by_node(struct device_node *np) > +{ > + struct mtd_info *mtd = NULL; > + struct mtd_info *tmp; > + int err; > + > + mutex_lock(&mtd_table_mutex); > + > + err = -EPROBE_DEFER; > + mtd_for_each_device(tmp) { > + if (mtd_get_of_node(tmp) == np) { > + mtd = tmp; > + err = __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 *master); > 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); > -- Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |