greybus: Merge branch 'es1-fixes' into master
Merge the es1 log file fixes into master.
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
diff --git a/drivers/staging/greybus/gpb.c b/drivers/staging/greybus/gpb.c
index 931d739..33bbe79 100644
--- a/drivers/staging/greybus/gpb.c
+++ b/drivers/staging/greybus/gpb.c
@@ -72,6 +72,7 @@
error_gpio:
return -EPROTO;
}
+module_init(gpbridge_init);
static void __exit gpbridge_exit(void)
{
@@ -84,8 +85,6 @@
gb_pwm_protocol_exit();
gb_gpio_protocol_exit();
}
-
-module_init(gpbridge_init);
module_exit(gpbridge_exit);
MODULE_LICENSE("GPL");
diff --git a/drivers/staging/greybus/interface.c b/drivers/staging/greybus/interface.c
index d2b2e3d..b687908 100644
--- a/drivers/staging/greybus/interface.c
+++ b/drivers/staging/greybus/interface.c
@@ -132,7 +132,7 @@
intf = kzalloc(sizeof(*intf), GFP_KERNEL);
if (!intf)
- return NULL;
+ goto put_module;
intf->hd = hd; /* XXX refcount? */
intf->module = module;
@@ -151,10 +151,7 @@
if (retval) {
pr_err("failed to add module device for id 0x%02hhx\n",
module_id);
- put_device(&intf->dev);
- put_device(&module->dev);
- kfree(intf);
- return NULL;
+ goto free_intf;
}
spin_lock_irq(&gb_interfaces_lock);
@@ -162,6 +159,13 @@
spin_unlock_irq(&gb_interfaces_lock);
return intf;
+
+free_intf:
+ put_device(&intf->dev);
+ kfree(intf);
+put_module:
+ put_device(&module->dev);
+ return NULL;
}
/*
diff --git a/drivers/staging/greybus/manifest.c b/drivers/staging/greybus/manifest.c
index 8b61b34..1b9edbc 100644
--- a/drivers/staging/greybus/manifest.c
+++ b/drivers/staging/greybus/manifest.c
@@ -13,6 +13,27 @@
#include "greybus.h"
+static const char *get_descriptor_type_string(u8 type)
+{
+ switch(type) {
+ case GREYBUS_TYPE_INVALID:
+ return "invalid";
+ case GREYBUS_TYPE_MODULE:
+ return "module";
+ case GREYBUS_TYPE_STRING:
+ return "string";
+ case GREYBUS_TYPE_INTERFACE:
+ return "interface";
+ case GREYBUS_TYPE_CPORT:
+ return "cport";
+ case GREYBUS_TYPE_CLASS:
+ return "class";
+ default:
+ WARN_ON(1);
+ return "unknown";
+ }
+}
+
/*
* We scan the manifest once to identify where all the descriptors
* are. The result is a list of these manifest_desc structures. We
@@ -72,32 +93,21 @@
return -EINVAL;
}
+ /* Descriptor needs to at least have a header */
+ expected_size = sizeof(*desc_header);
+
switch (desc_header->type) {
case GREYBUS_TYPE_MODULE:
- if (desc_size < sizeof(struct greybus_descriptor_module)) {
- pr_err("module descriptor too small (%u)\n",
- desc_size);
- return -EINVAL;
- }
+ expected_size += sizeof(struct greybus_descriptor_module);
break;
case GREYBUS_TYPE_STRING:
- expected_size = sizeof(*desc_header);
expected_size += sizeof(struct greybus_descriptor_string);
- expected_size += (size_t)desc->string.length;
- if (desc_size < expected_size) {
- pr_err("string descriptor too small (%u)\n",
- desc_size);
- return -EINVAL;
- }
+ expected_size += desc->string.length;
break;
case GREYBUS_TYPE_INTERFACE:
break;
case GREYBUS_TYPE_CPORT:
- if (desc_size < sizeof(struct greybus_descriptor_cport)) {
- pr_err("cport descriptor too small (%u)\n",
- desc_size);
- return -EINVAL;
- }
+ expected_size += sizeof(struct greybus_descriptor_cport);
break;
case GREYBUS_TYPE_CLASS:
pr_warn("class descriptor found (ignoring)\n");
@@ -108,6 +118,13 @@
return -EINVAL;
}
+ if (desc_size < expected_size) {
+ pr_err("%s descriptor too small (%u < %zu)\n",
+ get_descriptor_type_string(desc_header->type),
+ desc_size, expected_size);
+ return -EINVAL;
+ }
+
descriptor = kzalloc(sizeof(*descriptor), GFP_KERNEL);
if (!descriptor)
return -ENOMEM;
@@ -366,9 +383,7 @@
int desc_size;
desc_size = identify_descriptor(intf, desc, size);
- if (desc_size <= 0) {
- if (!desc_size)
- pr_err("zero-sized manifest descriptor\n");
+ if (desc_size < 0) {
result = false;
goto out;
}
diff --git a/drivers/staging/greybus/vibrator.c b/drivers/staging/greybus/vibrator.c
index c92c69e..2943a9b 100644
--- a/drivers/staging/greybus/vibrator.c
+++ b/drivers/staging/greybus/vibrator.c
@@ -185,14 +185,13 @@
return gb_protocol_register(&vibrator_protocol);
}
+module_init(protocol_init);
static __exit void protocol_exit(void)
{
gb_protocol_deregister(&vibrator_protocol);
class_unregister(&vibrator_class);
}
-
-module_init(protocol_init);
module_exit(protocol_exit);
MODULE_LICENSE("GPL v2");