From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B1B48C432C3 for ; Wed, 13 Nov 2019 17:15:42 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E18E9206EC for ; Wed, 13 Nov 2019 17:15:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="cgPn/ApG" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E18E9206EC Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=bootlin.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-mtd-bounces+linux-mtd=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=XMz2lnL1aNB0BIJV4Kj+jrix9N8c3bRpZ/GVgfaKaHk=; b=cgPn/ApG4n+RXW BsqXYhl0ECBeojURbQiTnYUgD47okvVx7SprSqVjXSZacemITTcr04EpWcYmI0yPZVUoi2XhJGSyQ 07Jvx43fNv1CyZHAgSVPyutUYLs6ehiGycUWGLSfrziu88PvRdqjuoIfudLpeeHG/UtynswVjo+uf R/jLiHOpetTxN3NE5O6T4squHAc4Fp1VJyPuukKoZbgAuKm76l2yyMPuJ4oSNk9aaDjjCVHd+3H4L EPfZJ+DsQAws1S1EZCwTQUxsn+tVn95eW7h1vKioyIVCokiIijwGnyvz+vzUaiEc/NjVJFzBD7oV5 zg/lum9Bza+aF5ZjCmLg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1iUwEq-0001U6-DK; Wed, 13 Nov 2019 17:15:28 +0000 Received: from relay4-d.mail.gandi.net ([217.70.183.196]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1iUwEk-0001SK-JY for linux-mtd@lists.infradead.org; Wed, 13 Nov 2019 17:15:24 +0000 X-Originating-IP: 91.224.148.103 Received: from localhost.localdomain (unknown [91.224.148.103]) (Authenticated sender: miquel.raynal@bootlin.com) by relay4-d.mail.gandi.net (Postfix) with ESMTPSA id 06872E0011; Wed, 13 Nov 2019 17:15:12 +0000 (UTC) From: Miquel Raynal To: Richard Weinberger , Vignesh Raghavendra , Tudor Ambarus Subject: [PATCH v4 2/4] mtd: Add get_mtd_device_by_node() helper Date: Wed, 13 Nov 2019 18:15:03 +0100 Message-Id: <20191113171505.26128-3-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191113171505.26128-1-miquel.raynal@bootlin.com> References: <20191113171505.26128-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191113_091522_777124_596D9C0C X-CRM114-Status: GOOD ( 11.06 ) X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , devicetree@vger.kernel.org, Bernhard Frauendienst , Miquel Raynal , linux-kernel@vger.kernel.org, Rob Herring , Paul Kocialkowski , Mark Brown , linux-mtd@lists.infradead.org, Thomas Petazzoni , Boris Brezillon Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-mtd" Errors-To: linux-mtd-bounces+linux-mtd=archiver.kernel.org@lists.infradead.org From: Bernhard Frauendienst Add an helper to retrieve a MTD device by its OF node. Since drivers can assign arbitrary names to MTD devices in the absence of a 'label' DT property, there is no other reliable way to retrieve a MTD device for a given OF node. Signed-off-by: Bernhard Frauendienst Reviewed-by: Miquel Raynal [: light internals rework] Signed-off-by: Miquel Raynal --- drivers/mtd/mtdcore.c | 38 ++++++++++++++++++++++++++++++++++++++ include/linux/mtd/mtd.h | 2 ++ 2 files changed, 40 insertions(+) diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c index 76b4264936ff..5a94a2c0a6de 100644 --- a/drivers/mtd/mtdcore.c +++ b/drivers/mtd/mtdcore.c @@ -985,6 +985,44 @@ struct mtd_info *get_mtd_device_nm(const char *name) } EXPORT_SYMBOL_GPL(get_mtd_device_nm); +/** + * get_mtd_device_by_node - obtain a validated handle for an MTD device + * by of_node + * @of_node: OF node of MTD device to open + * + * This function returns an MTD device structure in case of success, + * an error code otherwise. + */ +struct mtd_info *get_mtd_device_by_node(const struct device_node *of_node) +{ + struct mtd_info *mtd; + bool found = false; + int ret; + + mutex_lock(&mtd_table_mutex); + + mtd_for_each_device(mtd) { + if (of_node == mtd->dev.of_node) { + found = true; + break; + } + } + + if (found) + ret = __get_mtd_device(mtd); + + mutex_unlock(&mtd_table_mutex); + + if (!found) + return ERR_PTR(-ENODEV); + + if (ret) + return ERR_PTR(ret); + + return mtd; +} +EXPORT_SYMBOL_GPL(get_mtd_device_by_node); + void put_mtd_device(struct mtd_info *mtd) { mutex_lock(&mtd_table_mutex); diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h index 677768b21a1d..0f25c476a1a3 100644 --- a/include/linux/mtd/mtd.h +++ b/include/linux/mtd/mtd.h @@ -573,6 +573,8 @@ 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 *get_mtd_device_nm(const char *name); +extern struct mtd_info *get_mtd_device_by_node( + const struct device_node *of_node); extern void put_mtd_device(struct mtd_info *mtd); -- 2.20.1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/