Skip to content

Commit

Permalink
drivers: usb: gadget: Revert to Nougat fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Lunarixus <[email protected]>
  • Loading branch information
Lunarixus authored and Lunarixus committed Mar 24, 2020
1 parent 52e8ea9 commit 3b7ded4
Show file tree
Hide file tree
Showing 14 changed files with 428 additions and 319 deletions.
53 changes: 39 additions & 14 deletions drivers/usb/gadget/android.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ static void android_work(struct work_struct *data)
char **uevent_envp = NULL;
unsigned long flags;

printk(KERN_DEBUG "usb: %s config=%pK,connected=%d,sw_connected=%d\n",
printk(KERN_DEBUG "usb: %s config=%p,connected=%d,sw_connected=%d\n",
__func__, cdev->config, dev->connected,
dev->sw_connected);
spin_lock_irqsave(&cdev->lock, flags);
Expand All @@ -230,7 +230,7 @@ static void android_work(struct work_struct *data)
printk(KERN_DEBUG "usb: %s sent uevent %s\n",
__func__, uevent_envp[0]);
} else {
printk(KERN_DEBUG "usb: %s did not send uevent (%d %d %pK)\n",
printk(KERN_DEBUG "usb: %s did not send uevent (%d %d %p)\n",
__func__, dev->connected, dev->sw_connected, cdev->config);
}
}
Expand Down Expand Up @@ -268,6 +268,7 @@ struct functionfs_config {
bool opened;
bool enabled;
struct ffs_data *data;
struct android_dev *dev;
};

static int ffs_function_init(struct android_usb_function *f,
Expand Down Expand Up @@ -375,39 +376,65 @@ static int functionfs_ready_callback(struct ffs_data *ffs)
struct functionfs_config *config = ffs_function.config;
int ret = 0;

mutex_lock(&dev->mutex);

ret = functionfs_bind(ffs, dev->cdev);
if (ret)
goto err;
/* dev is null in case ADB is not in the composition */
if (dev) {
mutex_lock(&dev->mutex);
ret = functionfs_bind(ffs, dev->cdev);
if (ret) {
mutex_unlock(&dev->mutex);
return ret;
}
} else {
/* android ffs_func requires daemon to start only after enable*/
pr_debug("start adbd only in ADB composition\n");
return -ENODEV;
}

config->data = ffs;
config->opened = true;
/* Save dev in case the adb function will get disabled */
config->dev = dev;

if (config->enabled)
android_enable(dev);

err:
mutex_unlock(&dev->mutex);
return ret;

return 0;

}

static void functionfs_closed_callback(struct ffs_data *ffs)
{
struct android_dev *dev = _android_dev;
struct functionfs_config *config = ffs_function.config;

mutex_lock(&dev->mutex);
/*
* In case new composition is without ADB or ADB got disabled by the
* time ffs_daemon was stopped then use saved one
*/
if (!dev)
dev = config->dev;

if (config->enabled)
/* fatal-error: It should never happen */
if (!dev)
pr_err("adb_closed_callback: config->dev is NULL");

if (dev)
mutex_lock(&dev->mutex);

if (config->enabled && dev)
android_disable(dev);

config->dev = NULL;

config->opened = false;
config->data = NULL;

functionfs_unbind(ffs);

mutex_unlock(&dev->mutex);
if (dev)
mutex_unlock(&dev->mutex);
}

static void *functionfs_acquire_dev_callback(const char *dev_name)
Expand Down Expand Up @@ -1808,8 +1835,6 @@ functions_store(struct device *pdev, struct device_attribute *attr,
#endif
while (b) {
name = strsep(&b, ",");
if (!name)
continue;

is_ffs = 0;
strlcpy(aliases, dev->ffs_aliases, sizeof(aliases));
Expand Down
11 changes: 1 addition & 10 deletions drivers/usb/gadget/composite.c
Original file line number Diff line number Diff line change
Expand Up @@ -638,15 +638,6 @@ static int set_config(struct usb_composite_dev *cdev,
unsigned power = gadget_is_otg(gadget) ? 8 : 100;
int tmp;

/*
* ignore if SET_CONFIGURATION
* is sent again for same config value.
*/
if (cdev->config && (cdev->config->bConfigurationValue == number)) {
DBG(cdev, "already in the same config with value %d\n",
number);
return 0;
}
if (number) {
list_for_each_entry(c, &cdev->configs, list) {
#ifdef CONFIG_USB_ANDROID_SAMSUNG_COMPOSITE
Expand Down Expand Up @@ -1333,7 +1324,7 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
cdev->desc.bcdUSB = cpu_to_le16(0x0300);
cdev->desc.bMaxPacketSize0 = 9;
} else {
cdev->desc.bcdUSB = cpu_to_le16(0x0210);
cdev->desc.bcdUSB = cpu_to_le16(0x0201);
}
}

Expand Down
22 changes: 10 additions & 12 deletions drivers/usb/gadget/configfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,28 +87,21 @@ struct gadget_config_name {
struct list_head list;
};

#define MAX_USB_STRING_LEN 126
#define MAX_USB_STRING_WITH_NULL_LEN (MAX_USB_STRING_LEN+1)

static int usb_string_copy(const char *s, char **s_copy)
{
int ret;
char *str;
char *copy = *s_copy;
ret = strlen(s);
if (ret > MAX_USB_STRING_LEN)
if (ret > 126)
return -EOVERFLOW;

if (copy) {
str = copy;
} else {
str = kmalloc(MAX_USB_STRING_WITH_NULL_LEN, GFP_KERNEL);
if (!str)
return -ENOMEM;
}
strncpy(str, s, MAX_USB_STRING_WITH_NULL_LEN);
str = kstrdup(s, GFP_KERNEL);
if (!str)
return -ENOMEM;
if (str[ret - 1] == '\n')
str[ret - 1] = '\0';
kfree(copy);
*s_copy = str;
return 0;
}
Expand Down Expand Up @@ -400,6 +393,11 @@ static int config_usb_cfg_link(
}

f = usb_get_function(fi);
if (f == NULL) {
/* Are we trying to symlink PTP without MTP function? */
ret = -EINVAL; /* Invalid Configuration */
goto out;
}
if (IS_ERR(f)) {
ret = PTR_ERR(f);
goto out;
Expand Down
Loading

0 comments on commit 3b7ded4

Please sign in to comment.