linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] UWB: Return UWB_RSV_ALLOC_NOT_FOUND rather than crashing on NULL dereference if kzalloc fails
@ 2010-11-07 21:04 Jesper Juhl
  2010-11-08 12:43 ` David Vrabel
  0 siblings, 1 reply; 3+ messages in thread
From: Jesper Juhl @ 2010-11-07 21:04 UTC (permalink / raw)
  To: linux-usb; +Cc: linux-kernel

Hi,

Crashing on a null pointer deref is never a nice thing to do. It seems to 
me that it's better to simply return UWB_RSV_ALLOC_NOT_FOUND if kzalloc() 
fails in uwb_rsv_find_best_allocation().

I may be wrong since I have no way to test this (except compile test) and 
this is unknown code to me, so please review carefully.

Please CC me on replies.


Signed-off-by: Jesper Juhl <jj@chaosbits.net>
---
 allocator.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/uwb/allocator.c b/drivers/uwb/allocator.c
index 436e4f7..e45e673 100644
--- a/drivers/uwb/allocator.c
+++ b/drivers/uwb/allocator.c
@@ -326,7 +326,8 @@ int uwb_rsv_find_best_allocation(struct uwb_rsv *rsv, struct uwb_mas_bm *availab
 	int bit_index;
 
 	ai = kzalloc(sizeof(struct uwb_rsv_alloc_info), GFP_KERNEL);
-	
+	if (!ai)
+		return UWB_RSV_ALLOC_NOT_FOUND;
 	ai->min_mas = rsv->min_mas;
 	ai->max_mas = rsv->max_mas;
 	ai->max_interval = rsv->max_interval;


-- 
Jesper Juhl <jj@chaosbits.net>             http://www.chaosbits.net/
Don't top-post  http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please.


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

* Re: [PATCH] UWB: Return UWB_RSV_ALLOC_NOT_FOUND rather than crashing on NULL dereference if kzalloc fails
  2010-11-07 21:04 [PATCH] UWB: Return UWB_RSV_ALLOC_NOT_FOUND rather than crashing on NULL dereference if kzalloc fails Jesper Juhl
@ 2010-11-08 12:43 ` David Vrabel
  2010-11-08 16:41   ` Greg KH
  0 siblings, 1 reply; 3+ messages in thread
From: David Vrabel @ 2010-11-08 12:43 UTC (permalink / raw)
  To: Jesper Juhl; +Cc: linux-usb, linux-kernel, Greg KH

Jesper Juhl wrote:
> Hi,
> 
> Crashing on a null pointer deref is never a nice thing to do. It seems to 
> me that it's better to simply return UWB_RSV_ALLOC_NOT_FOUND if kzalloc() 
> fails in uwb_rsv_find_best_allocation().

This is fine.

struct uwb_rsv_alloc_info is not that large (about 414 bytes I think) so
it could possibly go on the stack and avoid the allocation.

Acked-by: David Vrabel <david.vrabel@csr.com>

Greg, seeing as I'm not maintaining the UWB subsystem any more do you
want to pick this (and future) UWB patches?

David

> I may be wrong since I have no way to test this (except compile test) and 
> this is unknown code to me, so please review carefully.
> 
> Please CC me on replies.
> 
> 
> Signed-off-by: Jesper Juhl <jj@chaosbits.net>
> ---
>  allocator.c |    3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/uwb/allocator.c b/drivers/uwb/allocator.c
> index 436e4f7..e45e673 100644
> --- a/drivers/uwb/allocator.c
> +++ b/drivers/uwb/allocator.c
> @@ -326,7 +326,8 @@ int uwb_rsv_find_best_allocation(struct uwb_rsv *rsv, struct uwb_mas_bm *availab
>  	int bit_index;
>  
>  	ai = kzalloc(sizeof(struct uwb_rsv_alloc_info), GFP_KERNEL);
> -	
> +	if (!ai)
> +		return UWB_RSV_ALLOC_NOT_FOUND;
>  	ai->min_mas = rsv->min_mas;
>  	ai->max_mas = rsv->max_mas;
>  	ai->max_interval = rsv->max_interval;
-- 
David Vrabel, Senior Software Engineer, Drivers
CSR, Churchill House, Cambridge Business Park,  Tel: +44 (0)1223 692562
Cowley Road, Cambridge, CB4 0WZ                 http://www.csr.com/


Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom

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

* Re: [PATCH] UWB: Return UWB_RSV_ALLOC_NOT_FOUND rather than crashing on NULL dereference if kzalloc fails
  2010-11-08 12:43 ` David Vrabel
@ 2010-11-08 16:41   ` Greg KH
  0 siblings, 0 replies; 3+ messages in thread
From: Greg KH @ 2010-11-08 16:41 UTC (permalink / raw)
  To: David Vrabel; +Cc: Jesper Juhl, linux-usb, linux-kernel

On Mon, Nov 08, 2010 at 12:43:02PM +0000, David Vrabel wrote:
> Jesper Juhl wrote:
> > Hi,
> > 
> > Crashing on a null pointer deref is never a nice thing to do. It seems to 
> > me that it's better to simply return UWB_RSV_ALLOC_NOT_FOUND if kzalloc() 
> > fails in uwb_rsv_find_best_allocation().
> 
> This is fine.
> 
> struct uwb_rsv_alloc_info is not that large (about 414 bytes I think) so
> it could possibly go on the stack and avoid the allocation.
> 
> Acked-by: David Vrabel <david.vrabel@csr.com>
> 
> Greg, seeing as I'm not maintaining the UWB subsystem any more do you
> want to pick this (and future) UWB patches?

Yes, I can do that, and will take this one.

thanks,

greg k-h

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

end of thread, other threads:[~2010-11-08 16:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-11-07 21:04 [PATCH] UWB: Return UWB_RSV_ALLOC_NOT_FOUND rather than crashing on NULL dereference if kzalloc fails Jesper Juhl
2010-11-08 12:43 ` David Vrabel
2010-11-08 16:41   ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).