Skip to contentSkip to conversation

Input: evdev: correct handling of memory allocation failure of evdev_client

PATCH In review Aniroop Mathur 2 participants 2 messages Jan 25, 2016 – Jan 27, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Input: evdev: correct handling of memory allocation failure of evdev_client

Lets fix twice checking of memory allocation failure of evdev_client structure when allocated successfully.

---
 drivers/input/evdev.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/input/evdev.c +4 -3
index e9ae3d5..102b5d9 100644
@@ -503,10 +503,11 @@ static int evdev_open(struct inode *inode, struct file *file)
 	int error;
 
 	client = kzalloc(size, GFP_KERNEL | __GFP_NOWARN);
-	if (!client)
+	if (!client) {
 		client = vzalloc(size);
-	if (!client)
-		return -ENOMEM;
+		if (!client)
+			return -ENOMEM;
+	}
 
 	client->bufsize = bufsize;
 	spin_lock_init(&client->buffer_lock);
Signature · 1 line
2.6.2
maintainer
#1 lore raw

Hi Aniroop,

Quoted 2 lines · Aniroop Mathur

Lets fix twice checking of memory allocation failure of evdev_client structure when allocated successfully.

I think compiler will take care of optimizing away the 2nd check, so I'd leave the code as is.

Thanks.

Quoted 28 lines
---
 drivers/input/evdev.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/input/evdev.c +4 -3
index e9ae3d5..102b5d9 100644
@@ -503,10 +503,11 @@ static int evdev_open(struct inode *inode, struct file *file)
 	int error;
 
 	client = kzalloc(size, GFP_KERNEL | __GFP_NOWARN);
-	if (!client)
+	if (!client) {
 		client = vzalloc(size);
-	if (!client)
-		return -ENOMEM;
+		if (!client)
+			return -ENOMEM;
+	}
 
 	client->bufsize = bufsize;
 	spin_lock_init(&client->buffer_lock);
Signature · 1 line
2.6.2
Signature · 1 line
Dmitry