Skip to content

Commit

Permalink
usb: gadget: android: Don't allow changing the functions list if enabled
Browse files Browse the repository at this point in the history
Change-Id: I3ad39b420ce79a8602a7eca1daac1f56b30bad5c
Signed-off-by: Benoit Goby <[email protected]>

Conflicts:

	drivers/usb/gadget/android.c
  • Loading branch information
benoitgoby authored and rmcc committed Jan 18, 2013
1 parent 26065d5 commit b661946
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion drivers/usb/gadget/android.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ struct android_dev {
struct device *dev;

bool enabled;
int disable_depth;
struct mutex mutex;
int disable_depth;
bool connected;
bool sw_connected;
struct work_struct work;
Expand Down Expand Up @@ -886,8 +887,11 @@ functions_show(struct device *pdev, struct device_attribute *attr, char *buf)
struct android_usb_function *f;
char *buff = buf;

mutex_lock(&dev->mutex);

list_for_each_entry(f, &dev->enabled_functions, enabled_list)
buff += sprintf(buff, "%s,", f->name);
mutex_unlock(&dev->mutex);
if (buff != buf)
*(buff-1) = '\n';
return buff - buf;
Expand All @@ -902,6 +906,13 @@ functions_store(struct device *pdev, struct device_attribute *attr,
char buf[256], *b;
int err;

mutex_lock(&dev->mutex);

if (dev->enabled) {
mutex_unlock(&dev->mutex);
return -EBUSY;
}

INIT_LIST_HEAD(&dev->enabled_functions);

strncpy(buf, buff, sizeof(buf));
Expand All @@ -915,6 +926,7 @@ functions_store(struct device *pdev, struct device_attribute *attr,
pr_err("android_usb: Cannot enable '%s'", name);
}
}
mutex_unlock(&dev->mutex);

return size;
}
Expand All @@ -934,6 +946,7 @@ static ssize_t enable_store(struct device *pdev, struct device_attribute *attr,
struct android_usb_function *f;
int enabled = 0;

mutex_lock(&dev->mutex);
sscanf(buff, "%d", &enabled);
if (enabled && !dev->enabled) {
cdev->next_string_id = 0;
Expand Down Expand Up @@ -963,6 +976,7 @@ static ssize_t enable_store(struct device *pdev, struct device_attribute *attr,
pr_err("android_usb: already %s\n",
dev->enabled ? "enabled" : "disabled");
}
mutex_unlock(&dev->mutex);
return size;
}

Expand Down Expand Up @@ -1254,6 +1268,7 @@ static int __init init(void)
dev->functions = supported_functions;
INIT_LIST_HEAD(&dev->enabled_functions);
INIT_WORK(&dev->work, android_work);
mutex_init(&dev->mutex);

err = android_create_device(dev);
if (err) {
Expand Down

0 comments on commit b661946

Please sign in to comment.