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

Commit 43e98b08 authored by Matthias Maennich's avatar Matthias Maennich
Browse files

ANDROID: usb: gadget: configfs: fix compiler warning



Commit 7a160e2b ("ANDROID: usb: gadget: configfs: Add Uevent to
notify userspace") introduces android_setup and android_disconnect
as alternatives to configfs_composite_setup and
configfs_composite_disconnect in case CONFIG_USB_CONFIGFS_UEVENT is set.
In case this config is set and in the presence of commit 1a1c851b
("usb: gadget: configfs: fix concurrent issue between composite APIs"),
the configfs_* functions are unused and therefore compilers complain
about that, e.g.

common/drivers/usb/gadget/configfs.c:1486:12: warning: unused function 'configfs_composite_setup' [-Wunused-function]

Fix that by conditionally compiling these functions.

Bug: 144674477
Fixes: 7a160e2b ("ANDROID: usb: gadget: configfs: Add Uevent to notify userspace")
Fixes: 1a1c851b ("usb: gadget: configfs: fix concurrent issue between composite APIs")
Change-Id: Idb6bb726d676d0d03b920375fd48fba41b60bb2d
Cc: Badhri Jagan Sridharan <Badhri@google.com>
Signed-off-by: default avatarMatthias Maennich <maennich@google.com>
parent 1026fb2f
Loading
Loading
Loading
Loading
+76 −73
Original line number Diff line number Diff line
@@ -1483,6 +1483,80 @@ static void configfs_composite_unbind(struct usb_gadget *gadget)
	spin_unlock_irqrestore(&gi->spinlock, flags);
}

#ifdef CONFIG_USB_CONFIGFS_UEVENT
static int android_setup(struct usb_gadget *gadget,
			const struct usb_ctrlrequest *c)
{
	struct usb_composite_dev *cdev = get_gadget_data(gadget);
	unsigned long flags;
	struct gadget_info *gi = container_of(cdev, struct gadget_info, cdev);
	int value = -EOPNOTSUPP;
	struct usb_function_instance *fi;

	spin_lock_irqsave(&cdev->lock, flags);
	if (!gi->connected) {
		gi->connected = 1;
		schedule_work(&gi->work);
	}
	spin_unlock_irqrestore(&cdev->lock, flags);
	list_for_each_entry(fi, &gi->available_func, cfs_list) {
		if (fi != NULL && fi->f != NULL && fi->f->setup != NULL) {
			value = fi->f->setup(fi->f, c);
			if (value >= 0)
				break;
		}
	}

#ifdef CONFIG_USB_CONFIGFS_F_ACC
	if (value < 0)
		value = acc_ctrlrequest(cdev, c);
#endif

	if (value < 0)
		value = composite_setup(gadget, c);

	spin_lock_irqsave(&cdev->lock, flags);
	if (c->bRequest == USB_REQ_SET_CONFIGURATION &&
						cdev->config) {
		schedule_work(&gi->work);
	}
	spin_unlock_irqrestore(&cdev->lock, flags);

	return value;
}

static void android_disconnect(struct usb_gadget *gadget)
{
	struct usb_composite_dev        *cdev = get_gadget_data(gadget);
	struct gadget_info *gi = container_of(cdev, struct gadget_info, cdev);

	/* FIXME: There's a race between usb_gadget_udc_stop() which is likely
	 * to set the gadget driver to NULL in the udc driver and this drivers
	 * gadget disconnect fn which likely checks for the gadget driver to
	 * be a null ptr. It happens that unbind (doing set_gadget_data(NULL))
	 * is called before the gadget driver is set to NULL and the udc driver
	 * calls disconnect fn which results in cdev being a null ptr.
	 */
	if (cdev == NULL) {
		WARN(1, "%s: gadget driver already disconnected\n", __func__);
		return;
	}

	/* accessory HID support can be active while the
		accessory function is not actually enabled,
		so we need to inform it when we are disconnected.
	*/

#ifdef CONFIG_USB_CONFIGFS_F_ACC
	acc_disconnect();
#endif
	gi->connected = 0;
	schedule_work(&gi->work);
	composite_disconnect(gadget);
}

#else // CONFIG_USB_CONFIGFS_UEVENT

static int configfs_composite_setup(struct usb_gadget *gadget,
		const struct usb_ctrlrequest *ctrl)
{
@@ -1530,6 +1604,8 @@ static void configfs_composite_disconnect(struct usb_gadget *gadget)
	spin_unlock_irqrestore(&gi->spinlock, flags);
}

#endif // CONFIG_USB_CONFIGFS_UEVENT

static void configfs_composite_suspend(struct usb_gadget *gadget)
{
	struct usb_composite_dev *cdev;
@@ -1574,79 +1650,6 @@ static void configfs_composite_resume(struct usb_gadget *gadget)
	spin_unlock_irqrestore(&gi->spinlock, flags);
}

#ifdef CONFIG_USB_CONFIGFS_UEVENT
static int android_setup(struct usb_gadget *gadget,
			const struct usb_ctrlrequest *c)
{
	struct usb_composite_dev *cdev = get_gadget_data(gadget);
	unsigned long flags;
	struct gadget_info *gi = container_of(cdev, struct gadget_info, cdev);
	int value = -EOPNOTSUPP;
	struct usb_function_instance *fi;

	spin_lock_irqsave(&cdev->lock, flags);
	if (!gi->connected) {
		gi->connected = 1;
		schedule_work(&gi->work);
	}
	spin_unlock_irqrestore(&cdev->lock, flags);
	list_for_each_entry(fi, &gi->available_func, cfs_list) {
		if (fi != NULL && fi->f != NULL && fi->f->setup != NULL) {
			value = fi->f->setup(fi->f, c);
			if (value >= 0)
				break;
		}
	}

#ifdef CONFIG_USB_CONFIGFS_F_ACC
	if (value < 0)
		value = acc_ctrlrequest(cdev, c);
#endif

	if (value < 0)
		value = composite_setup(gadget, c);

	spin_lock_irqsave(&cdev->lock, flags);
	if (c->bRequest == USB_REQ_SET_CONFIGURATION &&
						cdev->config) {
		schedule_work(&gi->work);
	}
	spin_unlock_irqrestore(&cdev->lock, flags);

	return value;
}

static void android_disconnect(struct usb_gadget *gadget)
{
	struct usb_composite_dev        *cdev = get_gadget_data(gadget);
	struct gadget_info *gi = container_of(cdev, struct gadget_info, cdev);

	/* FIXME: There's a race between usb_gadget_udc_stop() which is likely
	 * to set the gadget driver to NULL in the udc driver and this drivers
	 * gadget disconnect fn which likely checks for the gadget driver to
	 * be a null ptr. It happens that unbind (doing set_gadget_data(NULL))
	 * is called before the gadget driver is set to NULL and the udc driver
	 * calls disconnect fn which results in cdev being a null ptr.
	 */
	if (cdev == NULL) {
		WARN(1, "%s: gadget driver already disconnected\n", __func__);
		return;
	}

	/* accessory HID support can be active while the
		accessory function is not actually enabled,
		so we need to inform it when we are disconnected.
	*/

#ifdef CONFIG_USB_CONFIGFS_F_ACC
	acc_disconnect();
#endif
	gi->connected = 0;
	schedule_work(&gi->work);
	composite_disconnect(gadget);
}
#endif

static const struct usb_gadget_driver configfs_driver_template = {
	.bind           = configfs_composite_bind,
	.unbind         = configfs_composite_unbind,