From: Dan Carpenter <error27@gmail.com>
To: Oliver Endriss <o.endriss@gmx.de>
Cc: Mauro Carvalho Chehab <mchehab@infradead.org>,
Manu Abraham <manu@linuxtv.org>,
Andreas Regel <andreas.regel@gmx.de>,
linux-media@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: [patch v2] [media] stv090x: handle allocation failures
Date: Tue, 15 Feb 2011 10:10:08 +0000 [thread overview]
Message-ID: <20110215101008.GO4384@bicker> (raw)
In-Reply-To: <201102150300.19650@orion.escape-edv.de>
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.
Also Oliver Endriss pointed out an additional leak that I missed in the
first version of this patch.
Signed-off-by: Dan Carpenter <error27@gmail.com>
---
v2: Fix the leak Oliver noticed.
diff --git a/drivers/media/dvb/frontends/stv090x.c b/drivers/media/dvb/frontends/stv090x.c
index d3362d0..41d0f0a 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,9 @@ struct dvb_frontend *stv090x_attach(const struct stv090x_config *config,
return &state->frontend;
+err_remove:
+ remove_dev(state->internal);
+ kfree(state->internal);
error:
kfree(state);
return NULL;
WARNING: multiple messages have this Message-ID (diff)
From: Dan Carpenter <error27@gmail.com>
To: Oliver Endriss <o.endriss@gmx.de>
Cc: Mauro Carvalho Chehab <mchehab@infradead.org>,
Manu Abraham <manu@linuxtv.org>,
Andreas Regel <andreas.regel@gmx.de>,
linux-media@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: [patch v2] [media] stv090x: handle allocation failures
Date: Tue, 15 Feb 2011 13:10:08 +0300 [thread overview]
Message-ID: <20110215101008.GO4384@bicker> (raw)
In-Reply-To: <201102150300.19650@orion.escape-edv.de>
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.
Also Oliver Endriss pointed out an additional leak that I missed in the
first version of this patch.
Signed-off-by: Dan Carpenter <error27@gmail.com>
---
v2: Fix the leak Oliver noticed.
diff --git a/drivers/media/dvb/frontends/stv090x.c b/drivers/media/dvb/frontends/stv090x.c
index d3362d0..41d0f0a 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,9 @@ struct dvb_frontend *stv090x_attach(const struct stv090x_config *config,
return &state->frontend;
+err_remove:
+ remove_dev(state->internal);
+ kfree(state->internal);
error:
kfree(state);
return NULL;
next prev parent reply other threads:[~2011-02-15 10:10 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-02-07 16:56 [patch] [media] stv090x: handle allocation failures Dan Carpenter
2011-02-07 16:56 ` Dan Carpenter
2011-02-15 2:00 ` Oliver Endriss
2011-02-15 2:00 ` Oliver Endriss
2011-02-15 10:10 ` Dan Carpenter [this message]
2011-02-15 10:10 ` [patch v2] " Dan Carpenter
2011-02-27 14:36 ` Oliver Endriss
2011-02-27 14:36 ` Oliver Endriss
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20110215101008.GO4384@bicker \
--to=error27@gmail.com \
--cc=andreas.regel@gmx.de \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=manu@linuxtv.org \
--cc=mchehab@infradead.org \
--cc=o.endriss@gmx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.