public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drivers/usb/gadget: Use ERR_PTR/IS_ERR
@ 2009-12-09 13:23 Julia Lawall
  2009-12-11  3:20 ` David Brownell
  0 siblings, 1 reply; 2+ messages in thread
From: Julia Lawall @ 2009-12-09 13:23 UTC (permalink / raw)
  To: David Brownell, Greg Kroah-Hartman, linux-usb, linux-kernel,
	kernel-janitors

From: Julia Lawall <julia@diku.dk>

Use ERR_PTR and IS_ERR rather than mixing integers and pointers.

The semantic match that finds this problem is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@@
expression *E;
@@

* E < 0
// </smpl>

Signed-off-by: Julia Lawall <julia@diku.dk>

---
 drivers/usb/gadget/f_audio.c        |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/gadget/f_audio.c b/drivers/usb/gadget/f_audio.c
index c43c89f..0f2eee1 100644
--- a/drivers/usb/gadget/f_audio.c
+++ b/drivers/usb/gadget/f_audio.c
@@ -252,12 +252,12 @@ static struct f_audio_buf *f_audio_buffer_alloc(int buf_size)
 
 	copy_buf = kzalloc(sizeof *copy_buf, GFP_ATOMIC);
 	if (!copy_buf)
-		return (struct f_audio_buf *)-ENOMEM;
+		return ERR_PTR(-ENOMEM);
 
 	copy_buf->buf = kzalloc(buf_size, GFP_ATOMIC);
 	if (!copy_buf->buf) {
 		kfree(copy_buf);
-		return (struct f_audio_buf *)-ENOMEM;
+		return ERR_PTR(-ENOMEM);
 	}
 
 	return copy_buf;
@@ -332,7 +332,7 @@ static int f_audio_out_ep_complete(struct usb_ep *ep, struct usb_request *req)
 		list_add_tail(&copy_buf->list, &audio->play_queue);
 		schedule_work(&audio->playback_work);
 		copy_buf = f_audio_buffer_alloc(audio_buf_size);
-		if (copy_buf < 0)
+		if (IS_ERR(copy_buf))
 			return -ENOMEM;
 	}
 
@@ -576,6 +576,8 @@ static int f_audio_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
 			usb_ep_enable(out_ep, audio->out_desc);
 			out_ep->driver_data = audio;
 			audio->copy_buf = f_audio_buffer_alloc(audio_buf_size);
+			if (IS_ERR(audio->copy_buf))
+				return -ENOMEM;
 
 			/*
 			 * allocate a bunch of read buffers

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] drivers/usb/gadget: Use ERR_PTR/IS_ERR
  2009-12-09 13:23 [PATCH] drivers/usb/gadget: Use ERR_PTR/IS_ERR Julia Lawall
@ 2009-12-11  3:20 ` David Brownell
  0 siblings, 0 replies; 2+ messages in thread
From: David Brownell @ 2009-12-11  3:20 UTC (permalink / raw)
  To: Julia Lawall; +Cc: Greg Kroah-Hartman, linux-usb, linux-kernel, kernel-janitors

On Wednesday 09 December 2009, Julia Lawall wrote:
> From: Julia Lawall <julia@diku.dk>
> 
> Use ERR_PTR and IS_ERR rather than mixing integers and pointers.
> 
> The semantic match that finds this problem is as follows:
> (http://coccinelle.lip6.fr/)
> 
> // <smpl>
> @@
> expression *E;
> @@
> 
> * E < 0
> // </smpl>
> 
> Signed-off-by: Julia Lawall <julia@diku.dk>

Acked-by: David Brownell <dbrownell@users.sourceforge.net>

> 
> ---
>  drivers/usb/gadget/f_audio.c        |    8 +++++---
>  1 files changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/usb/gadget/f_audio.c b/drivers/usb/gadget/f_audio.c
> index c43c89f..0f2eee1 100644
> --- a/drivers/usb/gadget/f_audio.c
> +++ b/drivers/usb/gadget/f_audio.c
> @@ -252,12 +252,12 @@ static struct f_audio_buf *f_audio_buffer_alloc(int buf_size)
>  
>  	copy_buf = kzalloc(sizeof *copy_buf, GFP_ATOMIC);
>  	if (!copy_buf)
> -		return (struct f_audio_buf *)-ENOMEM;
> +		return ERR_PTR(-ENOMEM);
>  
>  	copy_buf->buf = kzalloc(buf_size, GFP_ATOMIC);
>  	if (!copy_buf->buf) {
>  		kfree(copy_buf);
> -		return (struct f_audio_buf *)-ENOMEM;
> +		return ERR_PTR(-ENOMEM);
>  	}
>  
>  	return copy_buf;
> @@ -332,7 +332,7 @@ static int f_audio_out_ep_complete(struct usb_ep *ep, struct usb_request *req)
>  		list_add_tail(&copy_buf->list, &audio->play_queue);
>  		schedule_work(&audio->playback_work);
>  		copy_buf = f_audio_buffer_alloc(audio_buf_size);
> -		if (copy_buf < 0)
> +		if (IS_ERR(copy_buf))
>  			return -ENOMEM;
>  	}
>  
> @@ -576,6 +576,8 @@ static int f_audio_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
>  			usb_ep_enable(out_ep, audio->out_desc);
>  			out_ep->driver_data = audio;
>  			audio->copy_buf = f_audio_buffer_alloc(audio_buf_size);
> +			if (IS_ERR(audio->copy_buf))
> +				return -ENOMEM;
>  
>  			/*
>  			 * allocate a bunch of read buffers
> 
> 



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-12-11  3:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-12-09 13:23 [PATCH] drivers/usb/gadget: Use ERR_PTR/IS_ERR Julia Lawall
2009-12-11  3:20 ` David Brownell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox