On Wed, Sep 28, 2022 at 10:56:22AM +0200, Ahmad Fatoum wrote:
> handler->devicefile for i.MX NAND is nand0.barebox, which lacks a /dev/
> prefix. This is ok for detection, as device_detect_by_name expects the
> cdev name and devpath_to_name() will strip a /dev/ if available.
> 
> For stat() however, we need to add back /dev/, otherwise the file can't
> be found. Rework the code to do that.
> 
> This fixes an issue where usbgadget -A '' -b would not export a i.MX
> NAND barebox update handler.
> 
> Fixes: 726a802456bc ("common: bbu: only add available handlers")
> Signed-off-by: Ahmad Fatoum <[email protected]>
> ---
>  common/bbu.c | 37 ++++++++++++++++++-------------------
>  1 file changed, 18 insertions(+), 19 deletions(-)

Applied, thanks

Sascha

> 
> diff --git a/common/bbu.c b/common/bbu.c
> index d243ac89dd9f..3ec17216cb15 100644
> --- a/common/bbu.c
> +++ b/common/bbu.c
> @@ -24,43 +24,42 @@
>  
>  static LIST_HEAD(bbu_image_handlers);
>  
> -static void append_bbu_entry(struct bbu_handler *handler, struct file_list 
> *files)
> +static void append_bbu_entry(const char *_name,
> +                          const char *devicefile,
> +                          struct file_list *files)
>  {
>       char *name;
>  
> -     name = basprintf("bbu-%s", handler->name);
> +     name = basprintf("bbu-%s", _name);
>  
> -     if (file_list_add_entry(files, name, handler->devicefile, 0))
> +     if (file_list_add_entry(files, name, devicefile, 0))
>               pr_warn("duplicate partition name %s\n", name);
>  
>       free(name);
>  }
>  
> -static bool bbu_handler_is_available(struct bbu_handler *handler)
> -{
> -     struct stat s;
> -     int ret;
> -
> -     device_detect_by_name(devpath_to_name(handler->devicefile));
> -
> -     ret = stat(handler->devicefile, &s);
> -     if (ret)
> -             return false;
> -
> -     return true;
> -}
> -
>  void bbu_append_handlers_to_file_list(struct file_list *files)
>  {
>       struct bbu_handler *handler;
>  
>       list_for_each_entry(handler, &bbu_image_handlers, list) {
> -             if (bbu_handler_is_available(handler)) {
> -                     append_bbu_entry(handler, files);
> +             const char *cdevname;
> +             struct stat s;
> +             char *devpath;
> +
> +             cdevname = devpath_to_name(handler->devicefile);
> +             device_detect_by_name(cdevname);
> +
> +             devpath = basprintf("/dev/%s", cdevname);
> +
> +             if (stat(devpath, &s) == 0) {
> +                     append_bbu_entry(handler->name, devpath, files);
>               } else {
>                       pr_info("Skipping unavailable handler bbu-%s\n",
>                               handler->name);
>               }
> +
> +             free(devpath);
>       }
>  }
>  
> -- 
> 2.30.2
> 
> 
> 

-- 
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 |

Reply via email to