aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesper Juhl <jj@chaosbits.net>2011-02-17 15:33:56 -0500
committerMauro Carvalho Chehab <mchehab@redhat.com>2011-03-22 05:51:55 -0400
commit7e270941c8f0a11224e383d3d38946451f66fbbf (patch)
tree8cd6d401c30d854c355c13bbd992a712a30e34d0
parent35d9f510b67b10338161aba6229d4f55b4000f5b (diff)
[media] Zarlink zl10036 DVB-S: Fix mem leak in zl10036_attach
On Thu, 17 Feb 2011, Matthias Schwarzott wrote: > On Sunday 06 February 2011, Jesper Juhl wrote: > > If the memory allocation to 'state' succeeds but we jump to the 'error' > > label before 'state' is assigned to fe->tuner_priv, then the call to > > 'zl10036_release(fe)' at the 'error:' label will not free 'state', but > > only what was previously assigned to 'tuner_priv', thus leaking the memory > > allocated to 'state'. > > There are may ways to fix this, including assigning the allocated memory > > directly to 'fe->tuner_priv', but I did not go for that since the > > additional pointer derefs are more expensive than the local variable, so I > > just added a 'kfree(state)' call. I guess the call to 'zl10036_release' > > might not even be needed in this case, but I wasn't sure, so I left it in. > > > Yeah, that call to zl10036_release can be completely eleminated. > Another thing is: jumping to the error label only makes sense when memory was > already allocated. So the jump in line 471 can be replaced by "return NULL", > as the other error handling before allocation: > if (NULL == config) { > printk(KERN_ERR "%s: no config specified", __func__); > goto error; > } > > I suggest to improve the patch to clean the code up when changing that. > > But I am fine with commiting this patch also if you do not want to change it. > Thank you for your feedback. It makes a lot of sense. Changing it is not a problem :) How about the updated patch below? If the memory allocation to 'state' succeeds but we jump to the 'error' label before 'state' is assigned to fe->tuner_priv, then the call to 'zl10036_release(fe)' at the 'error:' label will not free 'state', but only what was previously assigned to 'tuner_priv', thus leaking the memory allocated to 'state'. This patch fixes the leak and also does not jump to 'error:' before mem has been allocated but instead just returns. Also some small style cleanups. Signed-off-by: Jesper Juhl <jj@chaosbits.net> Signed-off-by: Matthias Schwarzott <zzam@gentoo.org> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
-rw-r--r--drivers/media/dvb/frontends/zl10036.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/drivers/media/dvb/frontends/zl10036.c b/drivers/media/dvb/frontends/zl10036.c
index 4627f491656b..81aa984c551f 100644
--- a/drivers/media/dvb/frontends/zl10036.c
+++ b/drivers/media/dvb/frontends/zl10036.c
@@ -463,16 +463,16 @@ struct dvb_frontend *zl10036_attach(struct dvb_frontend *fe,
463 const struct zl10036_config *config, 463 const struct zl10036_config *config,
464 struct i2c_adapter *i2c) 464 struct i2c_adapter *i2c)
465{ 465{
466 struct zl10036_state *state = NULL; 466 struct zl10036_state *state;
467 int ret; 467 int ret;
468 468
469 if (NULL == config) { 469 if (!config) {
470 printk(KERN_ERR "%s: no config specified", __func__); 470 printk(KERN_ERR "%s: no config specified", __func__);
471 goto error; 471 return NULL;
472 } 472 }
473 473
474 state = kzalloc(sizeof(struct zl10036_state), GFP_KERNEL); 474 state = kzalloc(sizeof(struct zl10036_state), GFP_KERNEL);
475 if (NULL == state) 475 if (!state)
476 return NULL; 476 return NULL;
477 477
478 state->config = config; 478 state->config = config;
@@ -507,7 +507,7 @@ struct dvb_frontend *zl10036_attach(struct dvb_frontend *fe,
507 return fe; 507 return fe;
508 508
509error: 509error:
510 zl10036_release(fe); 510 kfree(state);
511 return NULL; 511 return NULL;
512} 512}
513EXPORT_SYMBOL(zl10036_attach); 513EXPORT_SYMBOL(zl10036_attach);