[PATCH] UWB: Return UWB_RSV_ALLOC_NOT_FOUND rather than crashing onNULL dereference if kzalloc fails

From: Jesper Juhl
Date: Sun Nov 07 2010 - 16:16:08 EST


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@xxxxxxxxxxxxx>
---
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@xxxxxxxxxxxxx> http://www.chaosbits.net/
Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/