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

Commit 75e91fe9 authored by Manu Gautam's avatar Manu Gautam
Browse files

USB: android: Fix crash when F_FS gets descriptors before it is enabled



If F_FS (or ADB) function is selected in the composition, android
gadget driver keeps USB gadget disabled until it receives function
descriptors from userspace. This is signalled by F_FS when it calls
functionfs_ready_callback.
There could be a scenario (mainly due to userspace ignorance) that
before enabling F_FS (ADB) in the composition, descriptors are already
passed to F_FS. This results in a crash later on cable connection
in ffs_set_alt due to missing contexts initialization as functionfs_bind
never got called.

Fix this by calling functionfs_bind when F_FS is enabled by user and
it already has received the descriptors.

CRs-fixed: 585542
Change-Id: I52d680cdcd7f5d4a3eb90eb64785ea176c832849
Signed-off-by: default avatarManu Gautam <mgautam@codeaurora.org>
parent 012fce15
Loading
Loading
Loading
Loading
+12 −1
Original line number Diff line number Diff line
@@ -444,12 +444,23 @@ static void ffs_function_enable(struct android_usb_function *f)
{
	struct android_dev *dev = f->android_dev;
	struct functionfs_config *config = f->config;
	int ret = 0;

	config->enabled = true;

	/* Disable the gadget until the function is ready */
	if (!config->opened)
	if (!config->opened) {
		android_disable(dev);
	} else {
		/*
		 * Call functionfs_bind to handle the case where userspace
		 * passed descriptors before updating enabled functions list
		 */
		ret = functionfs_bind(config->data, dev->cdev);
		if (ret)
			pr_err("%s: functionfs_bind failed (%d)\n", __func__,
									ret);
	}
}

static void ffs_function_disable(struct android_usb_function *f)