mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH master 1/2] file_list: factor out file_list_new
@ 2022-07-30  9:46 Ahmad Fatoum
  2022-07-30  9:46 ` [PATCH master 2/2] USB: gadget: fastboot: allow exporting only barebox update handler Ahmad Fatoum
  2022-08-08 13:13 ` [PATCH master 1/2] file_list: factor out file_list_new Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2022-07-30  9:46 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

We have the sequence for creating a new file_list at two places and
follow-up commit will add a third one outside of the file, so it's a
good occasion to use a common helper. No functional change.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 common/file-list.c  | 19 +++++++++++++------
 include/file-list.h |  1 +
 2 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/common/file-list.c b/common/file-list.c
index 407b31283373..11db7c6e44c7 100644
--- a/common/file-list.c
+++ b/common/file-list.c
@@ -130,16 +130,25 @@ static const char *flags_to_str(int flags)
 	return str;
 }
 
-struct file_list *file_list_parse(const char *str)
+struct file_list *file_list_new(void)
 {
 	struct file_list *files;
-	int ret;
-	const char *endptr;
 
 	files = xzalloc(sizeof(*files));
 
 	INIT_LIST_HEAD(&files->list);
 
+	return files;
+}
+
+struct file_list *file_list_parse(const char *str)
+{
+	struct file_list *files;
+	int ret;
+	const char *endptr;
+
+	files = file_list_new();
+
 	while (*str) {
 		ret = file_list_parse_one(files, str, &endptr);
 		if (ret) {
@@ -195,9 +204,7 @@ struct file_list *file_list_dup(struct file_list *old)
 	struct file_list_entry *old_entry;
 	struct file_list *new;
 
-	new = xzalloc(sizeof(*new));
-
-	INIT_LIST_HEAD(&new->list);
+	new = file_list_new();
 
 	list_for_each_entry(old_entry, &old->list, list) {
 		(void)file_list_add_entry(new, old_entry->name, old_entry->filename,
diff --git a/include/file-list.h b/include/file-list.h
index 5090313739b8..af0dd7bbf108 100644
--- a/include/file-list.h
+++ b/include/file-list.h
@@ -29,6 +29,7 @@ void file_list_free(struct file_list *);
 int file_list_add_entry(struct file_list *files, const char *name, const char *filename,
 			unsigned long flags);
 
+struct file_list *file_list_new(void);
 struct file_list *file_list_dup(struct file_list *old);
 
 int file_list_detect_all(const struct file_list *files);
-- 
2.30.2




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

* [PATCH master 2/2] USB: gadget: fastboot: allow exporting only barebox update handler
  2022-07-30  9:46 [PATCH master 1/2] file_list: factor out file_list_new Ahmad Fatoum
@ 2022-07-30  9:46 ` Ahmad Fatoum
  2022-08-08 13:13 ` [PATCH master 1/2] file_list: factor out file_list_new Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2022-07-30  9:46 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

Exporting only the bbu handler and nothing else over fastboot
via usbgadget -A '' -b used to work. Restore this.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 common/fastboot.c          |  2 ++
 drivers/usb/gadget/multi.c | 15 ++++++++++-----
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/common/fastboot.c b/common/fastboot.c
index 330a06f5a32f..72e6ba3c402a 100644
--- a/common/fastboot.c
+++ b/common/fastboot.c
@@ -171,6 +171,8 @@ int fastboot_generic_init(struct fastboot *fb, bool export_bbu)
 	if (!fb->tempname)
 		return -ENOMEM;
 
+	if (!fb->files)
+		fb->files = file_list_new();
 	if (export_bbu)
 		bbu_append_handlers_to_file_list(fb->files);
 
diff --git a/drivers/usb/gadget/multi.c b/drivers/usb/gadget/multi.c
index 102d8714f86d..6225e9a313a1 100644
--- a/drivers/usb/gadget/multi.c
+++ b/drivers/usb/gadget/multi.c
@@ -137,6 +137,12 @@ static int multi_bind_fastboot(struct usb_composite_dev *cdev)
 	return usb_add_function(&config, f_fastboot);
 }
 
+static bool fastboot_has_exports(struct f_multi_opts *opts)
+{
+	return !file_list_empty(opts->fastboot_opts.files) ||
+		opts->fastboot_opts.export_bbu;
+}
+
 static int multi_bind_ums(struct usb_composite_dev *cdev)
 {
 	int ret;
@@ -179,7 +185,7 @@ static int multi_unbind(struct usb_composite_dev *cdev)
 		usb_put_function_instance(fi_dfu);
 	}
 
-	if (gadget_multi_opts->fastboot_opts.files) {
+	if (fastboot_has_exports(gadget_multi_opts)) {
 		usb_put_function(f_fastboot);
 		usb_put_function_instance(fi_fastboot);
 	}
@@ -219,7 +225,7 @@ static int multi_bind(struct usb_composite_dev *cdev)
 	if (ret)
 		return ret;
 
-	if (gadget_multi_opts->fastboot_opts.files) {
+	if (fastboot_has_exports(gadget_multi_opts)) {
 		printf("%s: creating Fastboot function\n", __func__);
 		ret = multi_bind_fastboot(cdev);
 		if (ret)
@@ -259,7 +265,7 @@ unbind_dfu:
 	if (gadget_multi_opts->dfu_opts.files)
 		usb_put_function_instance(fi_dfu);
 unbind_fastboot:
-	if (gadget_multi_opts->fastboot_opts.files)
+	if (fastboot_has_exports(gadget_multi_opts))
 		usb_put_function_instance(fi_fastboot);
 
 	return ret;
@@ -312,8 +318,7 @@ unsigned usb_multi_count_functions(struct f_multi_opts *opts)
 {
 	unsigned count = 0;
 
-	count += !file_list_empty(opts->fastboot_opts.files) ||
-		opts->fastboot_opts.export_bbu;
+	count += fastboot_has_exports(opts);
 	count += !file_list_empty(opts->dfu_opts.files);
 	count += !file_list_empty(opts->ums_opts.files);
 	count += opts->create_acm;
-- 
2.30.2




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

* Re: [PATCH master 1/2] file_list: factor out file_list_new
  2022-07-30  9:46 [PATCH master 1/2] file_list: factor out file_list_new Ahmad Fatoum
  2022-07-30  9:46 ` [PATCH master 2/2] USB: gadget: fastboot: allow exporting only barebox update handler Ahmad Fatoum
@ 2022-08-08 13:13 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2022-08-08 13:13 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox

On Sat, Jul 30, 2022 at 11:46:14AM +0200, Ahmad Fatoum wrote:
> We have the sequence for creating a new file_list at two places and
> follow-up commit will add a third one outside of the file, so it's a
> good occasion to use a common helper. No functional change.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
>  common/file-list.c  | 19 +++++++++++++------
>  include/file-list.h |  1 +
>  2 files changed, 14 insertions(+), 6 deletions(-)

Applied, thanks

Sascha

> 
> diff --git a/common/file-list.c b/common/file-list.c
> index 407b31283373..11db7c6e44c7 100644
> --- a/common/file-list.c
> +++ b/common/file-list.c
> @@ -130,16 +130,25 @@ static const char *flags_to_str(int flags)
>  	return str;
>  }
>  
> -struct file_list *file_list_parse(const char *str)
> +struct file_list *file_list_new(void)
>  {
>  	struct file_list *files;
> -	int ret;
> -	const char *endptr;
>  
>  	files = xzalloc(sizeof(*files));
>  
>  	INIT_LIST_HEAD(&files->list);
>  
> +	return files;
> +}
> +
> +struct file_list *file_list_parse(const char *str)
> +{
> +	struct file_list *files;
> +	int ret;
> +	const char *endptr;
> +
> +	files = file_list_new();
> +
>  	while (*str) {
>  		ret = file_list_parse_one(files, str, &endptr);
>  		if (ret) {
> @@ -195,9 +204,7 @@ struct file_list *file_list_dup(struct file_list *old)
>  	struct file_list_entry *old_entry;
>  	struct file_list *new;
>  
> -	new = xzalloc(sizeof(*new));
> -
> -	INIT_LIST_HEAD(&new->list);
> +	new = file_list_new();
>  
>  	list_for_each_entry(old_entry, &old->list, list) {
>  		(void)file_list_add_entry(new, old_entry->name, old_entry->filename,
> diff --git a/include/file-list.h b/include/file-list.h
> index 5090313739b8..af0dd7bbf108 100644
> --- a/include/file-list.h
> +++ b/include/file-list.h
> @@ -29,6 +29,7 @@ void file_list_free(struct file_list *);
>  int file_list_add_entry(struct file_list *files, const char *name, const char *filename,
>  			unsigned long flags);
>  
> +struct file_list *file_list_new(void);
>  struct file_list *file_list_dup(struct file_list *old);
>  
>  int file_list_detect_all(const struct file_list *files);
> -- 
> 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 |



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

end of thread, other threads:[~2022-08-08 13:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-30  9:46 [PATCH master 1/2] file_list: factor out file_list_new Ahmad Fatoum
2022-07-30  9:46 ` [PATCH master 2/2] USB: gadget: fastboot: allow exporting only barebox update handler Ahmad Fatoum
2022-08-08 13:13 ` [PATCH master 1/2] file_list: factor out file_list_new Sascha Hauer

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