Hi Ahmad, another small typo. On Wed, May 31 2023 at 16:59 +0200, Ahmad Fatoum <a.fatoum@xxxxxxxxxxxxxx> wrote: > __of_find_path goes throught the hassle of determining the cdev, only to s/throught/through/ Best regards Ulrich > discard it again and return either zero or an error code. > > Follow up commits will need to get the cdev corresponding to a path in > the DT. So let's make that easier by exporting a suitable helper function. > > Signed-off-by: Ahmad Fatoum <a.fatoum@xxxxxxxxxxxxxx> > --- > drivers/of/of_path.c | 59 ++++++++++++++++++++++++++++++-------------- > include/of.h | 1 + > 2 files changed, 41 insertions(+), 19 deletions(-) > > diff --git a/drivers/of/of_path.c b/drivers/of/of_path.c > index 059690e9b8e8..4d9f7b6005af 100644 > --- a/drivers/of/of_path.c > +++ b/drivers/of/of_path.c > @@ -27,21 +27,17 @@ struct device *of_find_device_by_node_path(const char *path) > } > > /** > - * __of_find_path > + * __of_cdev_find > * > * @node: The node to find the cdev for, can be the device or a > * partition in the device > * @part: Optionally, a description of a partition of @node. See of_find_path > - * @outpath: if this function returns 0 outpath will contain the path belonging > - * to the input path description. Must be freed with free(). > - * @flags: use OF_FIND_PATH_FLAGS_BB to return the .bb device if available > * > */ > -static int __of_find_path(struct device_node *node, const char *part, char **outpath, unsigned flags) > +static struct cdev *__of_cdev_find(struct device_node *node, const char *part) > { > struct device *dev; > struct cdev *cdev; > - bool add_bb = false; > > of_partition_ensure_probed(node); > > @@ -56,24 +52,17 @@ static int __of_find_path(struct device_node *node, const char *part, char **out > > /* when partuuid is specified short-circuit the search for the cdev */ > ret = of_property_read_string(node, "partuuid", &uuid); > - if (!ret) { > - cdev = cdev_by_partuuid(uuid); > - if (!cdev) > - return -ENODEV; > - > - *outpath = basprintf("/dev/%s", cdev->name); > - > - return 0; > - } > + if (!ret) > + return cdev_by_partuuid(uuid) ?: ERR_PTR(-ENODEV); > } > > dev = of_find_device_by_node_path(devnode->full_name); > if (!dev) > - return -ENODEV; > + return ERR_PTR(-ENODEV); > } > > if (dev->bus && !dev->driver) > - return -EPROBE_DEFER; > + return ERR_PTR(-EPROBE_DEFER); > > device_detect(dev); > > @@ -82,8 +71,40 @@ static int __of_find_path(struct device_node *node, const char *part, char **out > else > cdev = cdev_by_device_node(node); > > - if (!cdev) > - return -ENOENT; > + return cdev ?: ERR_PTR(-ENOENT); > +} > + > +/** > + * of_cdev_find > + * > + * @node: The node to find the cdev for, can be the device or a > + * partition in the device > + * > + */ > +struct cdev *of_cdev_find(struct device_node *node) > +{ > + return __of_cdev_find(node, NULL); > +} > + > +/** > + * __of_find_path > + * > + * @node: The node to find the cdev for, can be the device or a > + * partition in the device > + * @part: Optionally, a description of a partition of @node. See of_find_path > + * @outpath: if this function returns 0 outpath will contain the path belonging > + * to the input path description. Must be freed with free(). > + * @flags: use OF_FIND_PATH_FLAGS_BB to return the .bb device if available > + * > + */ > +static int __of_find_path(struct device_node *node, const char *part, char **outpath, unsigned flags) > +{ > + bool add_bb = false; > + struct cdev *cdev; > + > + cdev = __of_cdev_find(node, part); > + if (IS_ERR(cdev)) > + return PTR_ERR(cdev); > > if ((flags & OF_FIND_PATH_FLAGS_BB) && cdev->mtd && > mtd_can_have_bb(cdev->mtd)) > diff --git a/include/of.h b/include/of.h > index c716f9283316..2b75ce63e185 100644 > --- a/include/of.h > +++ b/include/of.h > @@ -331,6 +331,7 @@ int of_add_memory_bank(struct device_node *node, bool dump, int r, > struct device *of_find_device_by_node_path(const char *path); > #define OF_FIND_PATH_FLAGS_BB 1 /* return .bb device if available */ > int of_find_path(struct device_node *node, const char *propname, char **outpath, unsigned flags); > +struct cdev *of_cdev_find(struct device_node *node); > int of_find_path_by_node(struct device_node *node, char **outpath, unsigned flags); > struct device_node *of_find_node_by_devpath(struct device_node *root, const char *path); > int of_register_fixup(int (*fixup)(struct device_node *, void *), void *context); -- Pengutronix e.K. | Ulrich Ölmann | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |