mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] file_list: add file_list_parse_null()
@ 2021-07-21  8:40 Rouven Czerwinski
  2021-07-21  8:40 ` [PATCH 2/2] fastboot: use file_list_parse_null() Rouven Czerwinski
  0 siblings, 1 reply; 4+ messages in thread
From: Rouven Czerwinski @ 2021-07-21  8:40 UTC (permalink / raw)
  To: barebox; +Cc: Rouven Czerwinski

Move the usbgadget parse() function to file_list and rename it to
file_list_parse_null() which will return a NULL pointer instead of an
error. Also adjust the callers in the usbgadget code.

Signed-off-by: Rouven Czerwinski <r.czerwinski@pengutronix.de>
---
 common/file-list.c  | 16 ++++++++++++++++
 common/usbgadget.c  | 22 +++-------------------
 include/file-list.h |  1 +
 3 files changed, 20 insertions(+), 19 deletions(-)

diff --git a/common/file-list.c b/common/file-list.c
index 05f44514fb..407b312833 100644
--- a/common/file-list.c
+++ b/common/file-list.c
@@ -158,6 +158,22 @@ out:
 	return ERR_PTR(ret);
 }
 
+struct file_list *file_list_parse_null(const char *files)
+{
+	struct file_list *list;
+
+	if (!files)
+		return NULL;
+
+	list = file_list_parse(files);
+	if (IS_ERR(list)) {
+		pr_err("Parsing file list \"%s\" failed: %pe\n", files, list);
+		return NULL;
+	}
+
+	return list;
+}
+
 void file_list_free(struct file_list *files)
 {
 	struct file_list_entry *entry, *tmp;
diff --git a/common/usbgadget.c b/common/usbgadget.c
index d4437b5169..2d7323282d 100644
--- a/common/usbgadget.c
+++ b/common/usbgadget.c
@@ -23,26 +23,10 @@ static int autostart;
 static int acm;
 static char *dfu_function;
 
-static struct file_list *parse(const char *files)
-{
-	struct file_list *list;
-
-	if (!files)
-		return NULL;
-
-	list = file_list_parse(files);
-	if (IS_ERR(list)) {
-		pr_err("Parsing file list \"%s\" failed: %pe\n", files, list);
-		return NULL;
-	}
-
-	return list;
-}
-
 static inline struct file_list *get_dfu_function(void)
 {
 	if (dfu_function && *dfu_function)
-		return file_list_parse(dfu_function);
+		return file_list_parse_null(dfu_function);
 	if (!system_partitions_empty())
 		return system_partitions_get();
 	return NULL;
@@ -60,7 +44,7 @@ int usbgadget_register(bool dfu, const char *dfu_opts,
 	opts->release = usb_multi_opts_release;
 
 	if (dfu) {
-		opts->dfu_opts.files = parse(dfu_opts);
+		opts->dfu_opts.files = file_list_parse_null(dfu_opts);
 		if (IS_ENABLED(CONFIG_USB_GADGET_DFU) && file_list_empty(opts->dfu_opts.files)) {
 			file_list_free(opts->dfu_opts.files);
 			opts->dfu_opts.files = get_dfu_function();
@@ -68,7 +52,7 @@ int usbgadget_register(bool dfu, const char *dfu_opts,
 	}
 
 	if (fastboot) {
-		opts->fastboot_opts.files = parse(fastboot_opts);
+		opts->fastboot_opts.files = file_list_parse_null(fastboot_opts);
 		if (IS_ENABLED(CONFIG_FASTBOOT_BASE) && file_list_empty(opts->fastboot_opts.files)) {
 			file_list_free(opts->fastboot_opts.files);
 			opts->fastboot_opts.files = get_fastboot_partitions();
diff --git a/include/file-list.h b/include/file-list.h
index 7e2a4d9205..5090313739 100644
--- a/include/file-list.h
+++ b/include/file-list.h
@@ -22,6 +22,7 @@ struct file_list {
 };
 
 struct file_list *file_list_parse(const char *str);
+struct file_list *file_list_parse_null(const char *str);
 char *file_list_to_str(const struct file_list *files);
 void file_list_free(struct file_list *);
 
-- 
2.32.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 2/2] fastboot: use file_list_parse_null()
  2021-07-21  8:40 [PATCH 1/2] file_list: add file_list_parse_null() Rouven Czerwinski
@ 2021-07-21  8:40 ` Rouven Czerwinski
  2021-07-21  8:43   ` Rouven Czerwinski
  0 siblings, 1 reply; 4+ messages in thread
From: Rouven Czerwinski @ 2021-07-21  8:40 UTC (permalink / raw)
  To: barebox; +Cc: Rouven Czerwinski

In case an invalid file list is passed to file_list_parse(), it will
return an error, i.e. by passing "/dev/mmc1(emmc) /dev/mmc1.1(root)",
the error here being that the entries are not comma separated and
file_list_parse will try to parse ' ' as a flag. The fastboot code
didn't handle this, leading to the following error:

  ERROR: file_list: Unknown flag ' '
  ERROR: file_list: parse error
  unable to handle paging request at address 0xfffffff2
  pc : [<8fe26a20>]    lr : [<8fe0f965>]
  sp : 8ffeff50  ip : 8ffef714  fp : 00079bda
  r10: 001b9ff8  r9 : 8fea7eec  r8 : 00000001
  r7 : 00000000  r6 : 00000001  r5 : 00000000  r4 : 8813eab0
  r3 : ffffffea  r2 : 00020000  r1 : 00000001  r0 : 8813eab0
  Flags: nzCv  IRQs off  FIQs off  Mode SVC_32
  WARNING: [<8fe26a20>] (usb_multi_count_functions+0xc/0x2a) from [<8fe0f965>] (usbgadget_register+0x79/0xf4)
  WARNING: [<8fe0f965>] (usbgadget_register+0x79/0xf4) from [<8fe0fa13>] (usbgadget_autostart_set+0x33/0x4c)
  WARNING: [<8fe0fa13>] (usbgadget_autostart_set+0x33/0x4c) from [<8fe4d437>] (param_int_set+0x4b/0xb0)
  WARNING: [<8fe4d437>] (param_int_set+0x4b/0xb0) from [<8fe4d899>] (dev_set_param+0x4d/0x64)
  WARNING: [<8fe4d899>] (dev_set_param+0x4d/0x64) from [<8fe066f1>] (globalvar_add_bool+0x49/0x54)
  WARNING: [<8fe066f1>] (globalvar_add_bool+0x49/0x54) from [<8fe0f8dd>] (usbgadget_autostart_init+0x15/0x24)
  WARNING: [<8fe0f8dd>] (usbgadget_autostart_init+0x15/0x24) from [<8fe01081>] (start_barebox+0x35/0x6c)
  WARNING: [<8fe01081>] (start_barebox+0x35/0x6c) from [<8fe62ed9>] (barebox_non_pbl_start+0x121/0x164)
  WARNING: [<8fe62ed9>] (barebox_non_pbl_start+0x121/0x164) from [<8fe00005>] (__bare_init_start+0x1/0xc)

  WARNING: [<8fe64e3d>] (unwind_backtrace+0x1/0x78) from [<8fe01385>] (panic+0x1d/0x34)
  WARNING: [<8fe01385>] (panic+0x1d/0x34) from [<8fe62723>] (do_exception+0xf/0x14)
  WARNING: [<8fe62723>] (do_exception+0xf/0x14) from [<8fe62791>] (do_data_abort+0x21/0x34)
  WARNING: [<8fe62791>] (do_data_abort+0x21/0x34) from [<8fe624d4>] (do_abort_6+0x48/0x54)

Use file_list_parse_null instead of file_list_parse to get a NULL
pointer if there is a parse error.

Signed-off-by: Rouven Czerwinski <r.czerwinski@pengutronix.de>
---
 common/fastboot.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/common/fastboot.c b/common/fastboot.c
index 75f6691b08..00a50813a7 100644
--- a/common/fastboot.c
+++ b/common/fastboot.c
@@ -918,8 +918,9 @@ bool get_fastboot_bbu(void)
 
 struct file_list *get_fastboot_partitions(void)
 {
-	if (fastboot_partitions && *fastboot_partitions)
-		return file_list_parse(fastboot_partitions);
+	if (fastboot_partitions && *fastboot_partitions) {
+		return file_list_parse_null(fastboot_partitions);
+	}
 	if (!system_partitions_empty())
 		return system_partitions_get();
 	return NULL;
-- 
2.32.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/2] fastboot: use file_list_parse_null()
  2021-07-21  8:40 ` [PATCH 2/2] fastboot: use file_list_parse_null() Rouven Czerwinski
@ 2021-07-21  8:43   ` Rouven Czerwinski
  2021-08-09 18:48     ` Sascha Hauer
  0 siblings, 1 reply; 4+ messages in thread
From: Rouven Czerwinski @ 2021-07-21  8:43 UTC (permalink / raw)
  To: barebox

On Wed, 2021-07-21 at 10:40 +0200, Rouven Czerwinski wrote:
> In case an invalid file list is passed to file_list_parse(), it will
> return an error, i.e. by passing "/dev/mmc1(emmc) /dev/mmc1.1(root)",
> the error here being that the entries are not comma separated and
> file_list_parse will try to parse ' ' as a flag. The fastboot code
> didn't handle this, leading to the following error:
> 
>   ERROR: file_list: Unknown flag ' '
>   ERROR: file_list: parse error
>   unable to handle paging request at address 0xfffffff2
>   pc : [<8fe26a20>]    lr : [<8fe0f965>]
>   sp : 8ffeff50  ip : 8ffef714  fp : 00079bda
>   r10: 001b9ff8  r9 : 8fea7eec  r8 : 00000001
>   r7 : 00000000  r6 : 00000001  r5 : 00000000  r4 : 8813eab0
>   r3 : ffffffea  r2 : 00020000  r1 : 00000001  r0 : 8813eab0
>   Flags: nzCv  IRQs off  FIQs off  Mode SVC_32
>   WARNING: [<8fe26a20>] (usb_multi_count_functions+0xc/0x2a) from [<8fe0f965>] (usbgadget_register+0x79/0xf4)
>   WARNING: [<8fe0f965>] (usbgadget_register+0x79/0xf4) from [<8fe0fa13>] (usbgadget_autostart_set+0x33/0x4c)
>   WARNING: [<8fe0fa13>] (usbgadget_autostart_set+0x33/0x4c) from [<8fe4d437>] (param_int_set+0x4b/0xb0)
>   WARNING: [<8fe4d437>] (param_int_set+0x4b/0xb0) from [<8fe4d899>] (dev_set_param+0x4d/0x64)
>   WARNING: [<8fe4d899>] (dev_set_param+0x4d/0x64) from [<8fe066f1>] (globalvar_add_bool+0x49/0x54)
>   WARNING: [<8fe066f1>] (globalvar_add_bool+0x49/0x54) from [<8fe0f8dd>] (usbgadget_autostart_init+0x15/0x24)
>   WARNING: [<8fe0f8dd>] (usbgadget_autostart_init+0x15/0x24) from [<8fe01081>] (start_barebox+0x35/0x6c)
>   WARNING: [<8fe01081>] (start_barebox+0x35/0x6c) from [<8fe62ed9>] (barebox_non_pbl_start+0x121/0x164)
>   WARNING: [<8fe62ed9>] (barebox_non_pbl_start+0x121/0x164) from [<8fe00005>] (__bare_init_start+0x1/0xc)
> 
>   WARNING: [<8fe64e3d>] (unwind_backtrace+0x1/0x78) from [<8fe01385>] (panic+0x1d/0x34)
>   WARNING: [<8fe01385>] (panic+0x1d/0x34) from [<8fe62723>] (do_exception+0xf/0x14)
>   WARNING: [<8fe62723>] (do_exception+0xf/0x14) from [<8fe62791>] (do_data_abort+0x21/0x34)
>   WARNING: [<8fe62791>] (do_data_abort+0x21/0x34) from [<8fe624d4>] (do_abort_6+0x48/0x54)
> 
> Use file_list_parse_null instead of file_list_parse to get a NULL
> pointer if there is a parse error.
> 
> Signed-off-by: Rouven Czerwinski <r.czerwinski@pengutronix.de>
> ---
>  common/fastboot.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/common/fastboot.c b/common/fastboot.c
> index 75f6691b08..00a50813a7 100644
> --- a/common/fastboot.c
> +++ b/common/fastboot.c
> @@ -918,8 +918,9 @@ bool get_fastboot_bbu(void)
>  
>  struct file_list *get_fastboot_partitions(void)
>  {
> -	if (fastboot_partitions && *fastboot_partitions)
> -		return file_list_parse(fastboot_partitions);
> +	if (fastboot_partitions && *fastboot_partitions) {
> +		return file_list_parse_null(fastboot_partitions);
> +	}

I missed the no longer required braces, do you want to fixup locally or
should I send a v2?


Regards,
Rouven


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/2] fastboot: use file_list_parse_null()
  2021-07-21  8:43   ` Rouven Czerwinski
@ 2021-08-09 18:48     ` Sascha Hauer
  0 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2021-08-09 18:48 UTC (permalink / raw)
  To: Rouven Czerwinski; +Cc: barebox

On Wed, Jul 21, 2021 at 10:43:04AM +0200, Rouven Czerwinski wrote:
> On Wed, 2021-07-21 at 10:40 +0200, Rouven Czerwinski wrote:
> > In case an invalid file list is passed to file_list_parse(), it will
> > return an error, i.e. by passing "/dev/mmc1(emmc) /dev/mmc1.1(root)",
> > the error here being that the entries are not comma separated and
> > file_list_parse will try to parse ' ' as a flag. The fastboot code
> > didn't handle this, leading to the following error:
> > 
> >   ERROR: file_list: Unknown flag ' '
> >   ERROR: file_list: parse error
> >   unable to handle paging request at address 0xfffffff2
> >   pc : [<8fe26a20>]    lr : [<8fe0f965>]
> >   sp : 8ffeff50  ip : 8ffef714  fp : 00079bda
> >   r10: 001b9ff8  r9 : 8fea7eec  r8 : 00000001
> >   r7 : 00000000  r6 : 00000001  r5 : 00000000  r4 : 8813eab0
> >   r3 : ffffffea  r2 : 00020000  r1 : 00000001  r0 : 8813eab0
> >   Flags: nzCv  IRQs off  FIQs off  Mode SVC_32
> >   WARNING: [<8fe26a20>] (usb_multi_count_functions+0xc/0x2a) from [<8fe0f965>] (usbgadget_register+0x79/0xf4)
> >   WARNING: [<8fe0f965>] (usbgadget_register+0x79/0xf4) from [<8fe0fa13>] (usbgadget_autostart_set+0x33/0x4c)
> >   WARNING: [<8fe0fa13>] (usbgadget_autostart_set+0x33/0x4c) from [<8fe4d437>] (param_int_set+0x4b/0xb0)
> >   WARNING: [<8fe4d437>] (param_int_set+0x4b/0xb0) from [<8fe4d899>] (dev_set_param+0x4d/0x64)
> >   WARNING: [<8fe4d899>] (dev_set_param+0x4d/0x64) from [<8fe066f1>] (globalvar_add_bool+0x49/0x54)
> >   WARNING: [<8fe066f1>] (globalvar_add_bool+0x49/0x54) from [<8fe0f8dd>] (usbgadget_autostart_init+0x15/0x24)
> >   WARNING: [<8fe0f8dd>] (usbgadget_autostart_init+0x15/0x24) from [<8fe01081>] (start_barebox+0x35/0x6c)
> >   WARNING: [<8fe01081>] (start_barebox+0x35/0x6c) from [<8fe62ed9>] (barebox_non_pbl_start+0x121/0x164)
> >   WARNING: [<8fe62ed9>] (barebox_non_pbl_start+0x121/0x164) from [<8fe00005>] (__bare_init_start+0x1/0xc)
> > 
> >   WARNING: [<8fe64e3d>] (unwind_backtrace+0x1/0x78) from [<8fe01385>] (panic+0x1d/0x34)
> >   WARNING: [<8fe01385>] (panic+0x1d/0x34) from [<8fe62723>] (do_exception+0xf/0x14)
> >   WARNING: [<8fe62723>] (do_exception+0xf/0x14) from [<8fe62791>] (do_data_abort+0x21/0x34)
> >   WARNING: [<8fe62791>] (do_data_abort+0x21/0x34) from [<8fe624d4>] (do_abort_6+0x48/0x54)
> > 
> > Use file_list_parse_null instead of file_list_parse to get a NULL
> > pointer if there is a parse error.
> > 
> > Signed-off-by: Rouven Czerwinski <r.czerwinski@pengutronix.de>
> > ---
> >  common/fastboot.c | 5 +++--
> >  1 file changed, 3 insertions(+), 2 deletions(-)
> > 
> > diff --git a/common/fastboot.c b/common/fastboot.c
> > index 75f6691b08..00a50813a7 100644
> > --- a/common/fastboot.c
> > +++ b/common/fastboot.c
> > @@ -918,8 +918,9 @@ bool get_fastboot_bbu(void)
> >  
> >  struct file_list *get_fastboot_partitions(void)
> >  {
> > -	if (fastboot_partitions && *fastboot_partitions)
> > -		return file_list_parse(fastboot_partitions);
> > +	if (fastboot_partitions && *fastboot_partitions) {
> > +		return file_list_parse_null(fastboot_partitions);
> > +	}
> 
> I missed the no longer required braces, do you want to fixup locally or
> should I send a v2?

I would clean this up locally, but the series doesn't apply on current
master, so could you resend a v2?

Sascha

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

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-08-09 18:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-21  8:40 [PATCH 1/2] file_list: add file_list_parse_null() Rouven Czerwinski
2021-07-21  8:40 ` [PATCH 2/2] fastboot: use file_list_parse_null() Rouven Czerwinski
2021-07-21  8:43   ` Rouven Czerwinski
2021-08-09 18:48     ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox