HID: Fix return value in hid-core.c

Started by Sachin Kamat on Sep 14, 2012 · 3 messages from 2 authors · Last reply Sep 17, 2012

Subsystems (2)

Maintainers (3)

STALE5167d

open the first message on its own page

Message details and related content
Return -ENOMEM instead of -1 if memory allocation fails.

Signed-off-by: Sachin Kamat <redacted>
---
 drivers/hid/hid-core.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index 16d6454..1011a22 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -134,7 +134,7 @@ static int open_collection(struct hid_parser *parser, unsigned type)
 				parser->device->collection_size * 2, GFP_KERNEL);
 		if (collection == NULL) {
 			hid_err(parser->device, "failed to reallocate collection array\n");
-			return -1;
+			return -ENOMEM;
 		}
 		memcpy(collection, parser->device->collection,
 			sizeof(struct hid_collection) *
-- 
1.7.4.1
Message details and related content
On Fri, 14 Sep 2012, Sachin Kamat wrote:
quoted hunk
Return -ENOMEM instead of -1 if memory allocation fails.

Signed-off-by: Sachin Kamat <redacted>
---
 drivers/hid/hid-core.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index 16d6454..1011a22 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -134,7 +134,7 @@ static int open_collection(struct hid_parser *parser, unsigned type)
 				parser->device->collection_size * 2, GFP_KERNEL);
 		if (collection == NULL) {
 			hid_err(parser->device, "failed to reallocate collection array\n");
-			return -1;
+			return -ENOMEM;
While you are at it, could you please update the return value in case the 
collection stack overflows? I'd go with EINVAL. Thanks.
 		}
 		memcpy(collection, parser->device->collection,
 			sizeof(struct hid_collection) *
-- 
1.7.4.1
-- 
Jiri Kosina
SUSE Labs
Message details and related content
On 17 September 2012 16:32, Jiri Kosina [off-list ref] wrote:
On Fri, 14 Sep 2012, Sachin Kamat wrote:
quoted
Return -ENOMEM instead of -1 if memory allocation fails.

Signed-off-by: Sachin Kamat <redacted>
---
 drivers/hid/hid-core.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index 16d6454..1011a22 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -134,7 +134,7 @@ static int open_collection(struct hid_parser *parser, unsigned type)
                              parser->device->collection_size * 2, GFP_KERNEL);
              if (collection == NULL) {
                      hid_err(parser->device, "failed to reallocate collection array\n");
-                     return -1;
+                     return -ENOMEM;
While you are at it, could you please update the return value in case the
collection stack overflows? I'd go with EINVAL. Thanks.
Sure. I will update and re-send the patch.
quoted
              }
              memcpy(collection, parser->device->collection,
                      sizeof(struct hid_collection) *
--
1.7.4.1
--
Jiri Kosina
SUSE Labs


-- 
With warm regards,
Sachin
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help