On 25-04-14, Ahmad Fatoum wrote:
> We currently support bootsource.2, but not bootsource.root-A.
> Fix this and while at it, factor out the logic for general reuse.
> 
> Signed-off-by: Ahmad Fatoum <a.fat...@pengutronix.de>
> ---
>  common/cdev-alias.c | 22 +++-------------------
>  fs/devfs-core.c     | 29 +++++++++++++++++++++++++++++
>  include/driver.h    |  1 +
>  3 files changed, 33 insertions(+), 19 deletions(-)
> 
> diff --git a/common/cdev-alias.c b/common/cdev-alias.c
> index 5c37c2e58bf3..09e6770f5dea 100644
> --- a/common/cdev-alias.c
> +++ b/common/cdev-alias.c
> @@ -17,22 +17,6 @@ struct cdev_alias {
>                      cdev_alias_processor_t fn, void *data);
>  };
>  
> -static struct cdev *resolve_partition(struct cdev *cdev,
> -                                   const char *partname)
> -{
> -     struct cdev *partcdev;
> -
> -     if (!partname)
> -             return cdev;
> -
> -     for_each_cdev_partition(partcdev, cdev) {
> -             if (streq_ptr(partcdev->partname, partname))
> -                     return partcdev;
> -     }
> -
> -     return ERR_PTR(-ENODEV);
> -}
> -
>  static int cdev_alias_resolve_bootsource(struct cdev_alias *cdev_alias,
>                                        const char *partname,
>                                        cdev_alias_processor_t fn,
> @@ -44,9 +28,9 @@ static int cdev_alias_resolve_bootsource(struct cdev_alias 
> *cdev_alias,
>       if (!cdev)
>               return -ENODEV;
>  
> -     cdev = resolve_partition(cdev, partname);
> -     if (IS_ERR(cdev))
> -             return PTR_ERR(cdev);
> +     cdev = cdev_find_partition(cdev, partname);
> +     if (!cdev)
> +             return -ENODEV;
>  
>       return fn(cdev, data);
>  }
> diff --git a/fs/devfs-core.c b/fs/devfs-core.c
> index c69c38d6506e..e32bce9e307e 100644
> --- a/fs/devfs-core.c
> +++ b/fs/devfs-core.c
> @@ -21,6 +21,7 @@
>  #include <malloc.h>
>  #include <ioctl.h>
>  #include <nand.h>
> +#include <string.h>
>  #include <linux/err.h>
>  #include <linux/fs.h>
>  #include <linux/mtd/mtd.h>
> @@ -149,6 +150,34 @@ cdev_find_child_by_gpt_typeuuid(struct cdev *cdev, const 
> guid_t *typeuuid)
>       return ERR_PTR(-ENOENT);
>  }
>  
> +/**
> + * cdev_find_partition - find a partition belonging to a physical device
> + *
> + * @cdev: the cdev which should be searched for partitions
> + * @name: the partition name
> + */
> +struct cdev *cdev_find_partition(struct cdev *cdevm, const char *name)
> +{
> +     struct cdev *partcdev;
> +
> +     if (!name)
> +             return cdevm;

                return ERR_PTR(-EINVAL) ?

Regards,
  Marco

> +
> +     for_each_cdev_partition(partcdev, cdevm) {
> +             struct cdev *cdevl;
> +
> +             if (streq_ptr(partcdev->partname, name))
> +                     return partcdev;
> +
> +             list_for_each_entry(cdevl, &partcdev->links, link_entry) {
> +                     if (streq_ptr(cdevl->partname, name))
> +                             return cdevl;
> +             }
> +     }
> +
> +     return NULL;
> +}
> +
>  /**
>   * device_find_partition - find a partition belonging to a physical device
>   *
> diff --git a/include/driver.h b/include/driver.h
> index 3f2c681c0e80..ca002c5164c2 100644
> --- a/include/driver.h
> +++ b/include/driver.h
> @@ -503,6 +503,7 @@ int devfs_create(struct cdev *);
>  int devfs_create_link(struct cdev *, const char *name);
>  int devfs_remove(struct cdev *);
>  int cdev_find_free_index(const char *);
> +struct cdev *cdev_find_partition(struct cdev *cdevm, const char *name);
>  struct cdev *device_find_partition(struct device *dev, const char *name);
>  struct cdev *lcdev_by_name(const char *filename);
>  struct cdev *cdev_readlink(struct cdev *cdev);
> -- 
> 2.39.5
> 
> 
> 

Reply via email to