public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
* [patch] [media] stv090x: handle allocation failures
@ 2011-02-07 16:56 Dan Carpenter
  2011-02-15  2:00 ` Oliver Endriss
  0 siblings, 1 reply; 4+ messages in thread
From: Dan Carpenter @ 2011-02-07 16:56 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Manu Abraham, Andreas Regel, Oliver Endriss, linux-media,
	kernel-janitors

kmalloc() can fail so check whether state->internal is NULL.
append_internal() can return NULL on allocation failures so check that.
Also if we hit the error condition later in the function then there is
a memory leak and we need to call remove_dev() to fix it.

Signed-off-by: Dan Carpenter <error27@gmail.com>
---
Compile tested only.  I'm not very familiar with this code.

diff --git a/drivers/media/dvb/frontends/stv090x.c b/drivers/media/dvb/frontends/stv090x.c
index d3362d0..85101e8 100644
--- a/drivers/media/dvb/frontends/stv090x.c
+++ b/drivers/media/dvb/frontends/stv090x.c
@@ -4783,7 +4783,13 @@ struct dvb_frontend *stv090x_attach(const struct stv090x_config *config,
 	} else {
 		state->internal = kmalloc(sizeof(struct stv090x_internal),
 					  GFP_KERNEL);
+		if (!state->internal)
+			goto error;
 		temp_int = append_internal(state->internal);
+		if (!temp_int) {
+			kfree(state->internal);
+			goto error;
+		}
 		state->internal->num_used = 1;
 		state->internal->mclk = 0;
 		state->internal->dev_ver = 0;
@@ -4796,7 +4802,7 @@ struct dvb_frontend *stv090x_attach(const struct stv090x_config *config,
 
 		if (stv090x_setup(&state->frontend) < 0) {
 			dprintk(FE_ERROR, 1, "Error setting up device");
-			goto error;
+			goto err_remove;
 		}
 	}
 
@@ -4811,6 +4817,8 @@ struct dvb_frontend *stv090x_attach(const struct stv090x_config *config,
 
 	return &state->frontend;
 
+err_remove:
+	remove_dev(state->internal);
 error:
 	kfree(state);
 	return NULL;

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

end of thread, other threads:[~2011-02-27 14:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-02-07 16:56 [patch] [media] stv090x: handle allocation failures Dan Carpenter
2011-02-15  2:00 ` Oliver Endriss
2011-02-15 10:10   ` [patch v2] " Dan Carpenter
2011-02-27 14:36     ` Oliver Endriss

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