diff mbox

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

Message ID 1453744205-868-1-git-send-email-a.mathur@samsung.com (mailing list archive)
State Rejected
Headers show

Commit Message

Aniroop Mathur Jan. 25, 2016, 5:50 p.m. UTC
Lets fix twice checking of memory allocation failure of evdev_client
structure when allocated successfully.

Signed-off-by: Aniroop Mathur <a.mathur@samsung.com>
---
 drivers/input/evdev.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Comments

Dmitry Torokhov Jan. 27, 2016, 11:42 p.m. UTC | #1
Hi Aniroop,

On Mon, Jan 25, 2016 at 11:20:05PM +0530, Aniroop Mathur wrote:
> 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.

> 
> Signed-off-by: Aniroop Mathur <a.mathur@samsung.com>
> ---
>  drivers/input/evdev.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c
> index e9ae3d5..102b5d9 100644
> --- a/drivers/input/evdev.c
> +++ b/drivers/input/evdev.c
> @@ -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);
> -- 
> 2.6.2
>
diff mbox

Patch

diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c
index e9ae3d5..102b5d9 100644
--- a/drivers/input/evdev.c
+++ b/drivers/input/evdev.c
@@ -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);