* [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
* Re: [patch] [media] stv090x: handle allocation failures
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
0 siblings, 1 reply; 4+ messages in thread
From: Oliver Endriss @ 2011-02-15 2:00 UTC (permalink / raw)
To: Dan Carpenter
Cc: Mauro Carvalho Chehab, Manu Abraham, Andreas Regel, linux-media,
kernel-janitors
On Monday 07 February 2011 17:56:50 Dan Carpenter wrote:
> 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.
> ...
Thanks for the patch. See my comment below.
> --- 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);
AFAICS
kfree(state->internal);
must be added here, as we allocated state->internal, state and temp_int.
> error:
> kfree(state);
> return NULL;
CU
Oliver
--
----------------------------------------------------------------
VDR Remote Plugin 0.4.0: http://www.escape-edv.de/endriss/vdr/
4 MByte Mod: http://www.escape-edv.de/endriss/dvb-mem-mod/
Full-TS Mod: http://www.escape-edv.de/endriss/dvb-full-ts-mod/
----------------------------------------------------------------
^ permalink raw reply [flat|nested] 4+ messages in thread
* [patch v2] [media] stv090x: handle allocation failures
2011-02-15 2:00 ` Oliver Endriss
@ 2011-02-15 10:10 ` Dan Carpenter
2011-02-27 14:36 ` Oliver Endriss
0 siblings, 1 reply; 4+ messages in thread
From: Dan Carpenter @ 2011-02-15 10:10 UTC (permalink / raw)
To: Oliver Endriss
Cc: Mauro Carvalho Chehab, Manu Abraham, Andreas Regel, 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.
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;
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [patch v2] [media] stv090x: handle allocation failures
2011-02-15 10:10 ` [patch v2] " Dan Carpenter
@ 2011-02-27 14:36 ` Oliver Endriss
0 siblings, 0 replies; 4+ messages in thread
From: Oliver Endriss @ 2011-02-27 14:36 UTC (permalink / raw)
To: Dan Carpenter
Cc: Mauro Carvalho Chehab, Manu Abraham, Andreas Regel, linux-media,
kernel-janitors
On Tuesday 15 February 2011 11:10:08 Dan Carpenter wrote:
> 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
> ...
Acked-by: Oliver Endriss <o.endriss@gmx.de>
CU
Oliver
--
----------------------------------------------------------------
VDR Remote Plugin 0.4.0: http://www.escape-edv.de/endriss/vdr/
4 MByte Mod: http://www.escape-edv.de/endriss/dvb-mem-mod/
Full-TS Mod: http://www.escape-edv.de/endriss/dvb-full-ts-mod/
----------------------------------------------------------------
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2011-02-27 14:36 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;
as well as URLs for NNTP newsgroup(s).