Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit af068e4b authored by Mayank Rana's avatar Mayank Rana
Browse files

USB: android: Add check before calling function's unbind_config()



In some of cases when function's bind() is failing, we are trying to call
each function's unbind_config() API if function supports that even if that
function is not bound yet. Fix this issue by adding bound variable with
android_usb_function and using when function's bind_config() and bind()
are successfully called.

example:
USB composition: diag,adb,mass_storage
if adb function's bind() is failing, then unbind_config() of mass_storage
function is being called as part of error handling which results into
crash as mass storage function's bind_config() and bind() are not yet
called.

CRs-Fixed: 853742
Change-Id: Ib8246c4f830ecffca633f6c1ab763f03c44de0a9
Signed-off-by: default avatarMayank Rana <mrana@codeaurora.org>
parent a48f5ed1
Loading
Loading
Loading
Loading
+10 −4
Original line number Diff line number Diff line
@@ -85,6 +85,8 @@ static const char longname[] = "Gadget Android";
struct android_usb_function {
	char *name;
	void *config;
	/* set only when function's bind_config() is called. */
	bool bound;

	struct device *dev;
	char *dev_name;
@@ -2912,14 +2914,17 @@ android_bind_enabled_functions(struct android_dev *dev,

				f = list_first_entry(&c->functions,
					struct usb_function, list);
				if (f->config) {
					list_del(&f->list);
					if (f->unbind)
						f->unbind(c, f);
				}
			}
			if (c->unbind)
				c->unbind(c);
			return ret;
		}
		f_holder->f->bound = true;
	}
	return 0;
}
@@ -2933,8 +2938,9 @@ android_unbind_enabled_functions(struct android_dev *dev,
		container_of(c, struct android_configuration, usb_config);

	list_for_each_entry(f_holder, &conf->enabled_functions, enabled_list) {
		if (f_holder->f->unbind_config)
		if (f_holder->f->bound && f_holder->f->unbind_config)
			f_holder->f->unbind_config(f_holder->f, c);
		f_holder->f->bound = false;
	}
}
static inline void check_streaming_func(struct usb_gadget *gadget,