Commit a6fbaacf authored by Sachin Kamat's avatar Sachin Kamat Committed by Jiri Kosina

HID: Fix return values in open_collection()

Return -ENOMEM instead of -1 if memory allocation fails.
Return -EINVAL instead of -1 for stack overflow and
underflow errors.
Signed-off-by: default avatarSachin Kamat <sachin.kamat@linaro.org>
Signed-off-by: default avatarJiri Kosina <jkosina@suse.cz>
parent 832fbeae
...@@ -126,7 +126,7 @@ static int open_collection(struct hid_parser *parser, unsigned type) ...@@ -126,7 +126,7 @@ static int open_collection(struct hid_parser *parser, unsigned type)
if (parser->collection_stack_ptr == HID_COLLECTION_STACK_SIZE) { if (parser->collection_stack_ptr == HID_COLLECTION_STACK_SIZE) {
hid_err(parser->device, "collection stack overflow\n"); hid_err(parser->device, "collection stack overflow\n");
return -1; return -EINVAL;
} }
if (parser->device->maxcollection == parser->device->collection_size) { if (parser->device->maxcollection == parser->device->collection_size) {
...@@ -134,7 +134,7 @@ static int open_collection(struct hid_parser *parser, unsigned type) ...@@ -134,7 +134,7 @@ static int open_collection(struct hid_parser *parser, unsigned type)
parser->device->collection_size * 2, GFP_KERNEL); parser->device->collection_size * 2, GFP_KERNEL);
if (collection == NULL) { if (collection == NULL) {
hid_err(parser->device, "failed to reallocate collection array\n"); hid_err(parser->device, "failed to reallocate collection array\n");
return -1; return -ENOMEM;
} }
memcpy(collection, parser->device->collection, memcpy(collection, parser->device->collection,
sizeof(struct hid_collection) * sizeof(struct hid_collection) *
...@@ -170,7 +170,7 @@ static int close_collection(struct hid_parser *parser) ...@@ -170,7 +170,7 @@ static int close_collection(struct hid_parser *parser)
{ {
if (!parser->collection_stack_ptr) { if (!parser->collection_stack_ptr) {
hid_err(parser->device, "collection stack underflow\n"); hid_err(parser->device, "collection stack underflow\n");
return -1; return -EINVAL;
} }
parser->collection_stack_ptr--; parser->collection_stack_ptr--;
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment