lists.openwall.net | lists / announce owl-users owl-dev john-users john-dev passwdqc-users yescrypt popa3d-users / oss-security kernel-hardening musl sabotage tlsify passwords / crypt-dev xvendor / Bugtraq Full-Disclosure linux-kernel linux-netdev linux-ext4 linux-hardening linux-cve-announce PHC | |
Open Source and information security mailing list archives
| ||
|
Date: Fri, 7 Sep 2018 19:35:13 +0200 From: Bernhard Frauendienst <kernel@...pam.obeliks.de> To: David Woodhouse <dwmw2@...radead.org>, Brian Norris <computersforpeace@...il.com>, Boris Brezillon <boris.brezillon@...tlin.com>, Marek Vasut <marek.vasut@...il.com>, Richard Weinberger <richard@....at> Cc: Miquel Raynal <miquel.raynal@...tlin.com>, linux-mtd@...ts.infradead.org, linux-kernel@...r.kernel.org Subject: [PATCH v2 1/3] mtd: core: add get_mtd_device_by_node Add function to retrieve a mtd device by its OF node. Since drivers can assign arbitrary names to mtd devices in the absence of a label property, there is no other reliable way to retrieve a mtd device for a given OF node. Signed-off-by: Bernhard Frauendienst <kernel@...pam.obeliks.de> Reviewed-by: Miquel Raynal <miquel.raynal@...tlin.com> --- 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 97ac219c082e..87dd63926bc9 100644 --- a/drivers/mtd/mtdcore.c +++ b/drivers/mtd/mtdcore.c @@ -926,6 +926,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 MTD device description structure in case of + * success and an error code in case of failure. + */ +struct mtd_info *get_mtd_device_by_node(const struct device_node *of_node) +{ + int err = -ENODEV; + struct mtd_info *mtd = NULL, *other; + + mutex_lock(&mtd_table_mutex); + + mtd_for_each_device(other) { + if (of_node == other->dev.of_node) { + mtd = other; + break; + } + } + + if (!mtd) + goto out_unlock; + + err = __get_mtd_device(mtd); + if (err) + goto out_unlock; + + mutex_unlock(&mtd_table_mutex); + return mtd; + +out_unlock: + mutex_unlock(&mtd_table_mutex); + return ERR_PTR(err); +} +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 cd0be91bdefa..fe71358f8eaa 100644 --- a/include/linux/mtd/mtd.h +++ b/include/linux/mtd/mtd.h @@ -570,6 +570,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.17.1
Powered by blists - more mailing lists