struct device *dev;
bool enabled;
+ struct mutex mutex;
bool connected;
bool sw_connected;
struct work_struct work;
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;
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));
}
}
+ mutex_unlock(&dev->mutex);
+
return size;
}
struct usb_composite_dev *cdev = dev->cdev;
int enabled = 0;
+ mutex_lock(&dev->mutex);
+
sscanf(buff, "%d", &enabled);
if (enabled && !dev->enabled) {
cdev->next_string_id = 0;
pr_err("android_usb: already %s\n",
dev->enabled ? "enabled" : "disabled");
}
+
+ mutex_unlock(&dev->mutex);
return size;
}
} \
static ssize_t \
field ## _store(struct device *dev, struct device_attribute *attr, \
- const char *buf, size_t size) \
+ const char *buf, size_t size) \
{ \
- int value; \
+ int value; \
if (sscanf(buf, format_string, &value) == 1) { \
device_desc.field = value; \
return size; \
} \
static ssize_t \
field ## _store(struct device *dev, struct device_attribute *attr, \
- const char *buf, size_t size) \
+ const char *buf, size_t size) \
{ \
if (size >= sizeof(buffer)) return -EINVAL; \
- if (sscanf(buf, "%s", buffer) == 1) { \
+ if (sscanf(buf, "%s", buffer) == 1) { \
return size; \
} \
return -1; \
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) {