drivers/media: Removes useless kfree()
Subsystems (4)
PATCH 1/1 drivers/media: Removes useless kfree()
From: Peter Senna Tschudin <[email protected]>
The semantic patch that finds this problem is as follows:
(http://coccinelle.lip6.fr/)
// <smpl>
@r exists@
position p1,p2;
expression x;
@@
if (x@p1 = NULL) { ... kfree@p2(x); ... return ...; }
@unchanged exists@
position r.p1,r.p2;
expression e <= r.x,x,e1;
iterator I;
statement S;
@@
if (x@p1 = NULL) { ... when != I(x,...) S
when != e = e1
when != e += e1
when != e -= e1
when != ++e
when != --e
when != e++
when != e--
when != &ekfree@p2(x); ... return ...; }
@ok depends on unchanged exists@
position any r.p1;
position r.p2;
expression x;
@@
... when != true x@p1 = NULL
kfree@p2(x);
@depends on !ok && unchanged@
position r.p2;
expression x;
@@
*kfree@p2(x);
// </smpl>
--- drivers/media/dvb-frontends/dvb_dummy_fe.c | 21 ++++++--------------- drivers/media/dvb-frontends/lg2160.c | 1 - drivers/media/dvb-frontends/s5h1432.c | 6 +----- drivers/media/dvb-frontends/s921.c | 7 +------ drivers/media/dvb-frontends/stb6100.c | 6 +----- drivers/media/dvb-frontends/tda665x.c | 6 +----- drivers/media/platform/davinci/vpbe.c | 1 - drivers/media/tuners/mt2063.c | 6 +----- 8 files changed, 11 insertions(+), 43 deletions(-)
drivers/media/dvb-frontends/dvb_dummy_fe.c +6 -15
@@ -121,16 +121,13 @@ struct dvb_frontend* dvb_dummy_fe_ofdm_attach(void)/* allocate memory for the internal state */ state =kzalloc (sizeof (struct dvb_dummy_fe_state ),GFP_KERNEL ); -if (state =NULL ) goto error; +if (state =NULL ) +return NULL ;/* create dvb_frontend */ memcpy (&state->frontend.ops, &dvb_dummy_fe_ofdm_ops,sizeof (struct dvb_frontend_ops )); state->frontend.demodulator_priv = state;return &state->frontend; - -error: -kfree (state); -return NULL ; }static struct dvb_frontend_ops dvb_dummy_fe_qpsk_ops;
@@ -141,16 +138,13 @@ struct dvb_frontend *dvb_dummy_fe_qpsk_attach(void)/* allocate memory for the internal state */ state =kzalloc (sizeof (struct dvb_dummy_fe_state ),GFP_KERNEL ); -if (state =NULL ) goto error; +if (state =NULL ) +return NULL ;/* create dvb_frontend */ memcpy (&state->frontend.ops, &dvb_dummy_fe_qpsk_ops,sizeof (struct dvb_frontend_ops )); state->frontend.demodulator_priv = state;return &state->frontend; - -error: -kfree (state); -return NULL ; }static struct dvb_frontend_ops dvb_dummy_fe_qam_ops;
@@ -161,16 +155,13 @@ struct dvb_frontend *dvb_dummy_fe_qam_attach(void)/* allocate memory for the internal state */ state =kzalloc (sizeof (struct dvb_dummy_fe_state ),GFP_KERNEL ); -if (state =NULL ) goto error; +if (state =NULL ) +return NULL ;/* create dvb_frontend */ memcpy (&state->frontend.ops, &dvb_dummy_fe_qam_ops,sizeof (struct dvb_frontend_ops )); state->frontend.demodulator_priv = state;return &state->frontend; - -error: -kfree (state); -return NULL ; }static struct dvb_frontend_ops dvb_dummy_fe_ofdm_ops = {
drivers/media/dvb-frontends/lg2160.c +0 -1
@@ -1451,7 +1451,6 @@ struct dvb_frontend *lg2160_attach(const struct lg2160_config *config,return &state->frontend; fail:lg_warn ("unable to detect LG216x hardware\n" ); -kfree (state);return NULL ; }EXPORT_SYMBOL (lg2160_attach);
drivers/media/dvb-frontends/s5h1432.c +1 -5
@@ -352,7 +352,7 @@ struct dvb_frontend *s5h1432_attach(const struct s5h1432_config *config,/* allocate memory for the internal state */ state =kmalloc (sizeof (struct s5h1432_state ),GFP_KERNEL );if (state =NULL ) - goto error; +return NULL ;/* setup the state */ state->config = config;
@@ -367,10 +367,6 @@ struct dvb_frontend *s5h1432_attach(const struct s5h1432_config *config, state->frontend.demodulator_priv = state;return &state->frontend; - -error: -kfree (state); -return NULL ; }EXPORT_SYMBOL (s5h1432_attach);
drivers/media/dvb-frontends/s921.c +1 -6
@@ -489,7 +489,7 @@ struct dvb_frontend *s921_attach(const struct s921_config *config,dprintk ("\n" );if (state =NULL ) {rc ("Unable to kzalloc\n" ); - goto rcor; +return NULL ; }/* setup the state */
@@ -502,11 +502,6 @@ struct dvb_frontend *s921_attach(const struct s921_config *config, state->frontend.demodulator_priv = state;return &state->frontend; - -rcor: -kfree (state); - -return NULL ; }EXPORT_SYMBOL (s921_attach);
drivers/media/dvb-frontends/stb6100.c +1 -5
@@ -576,7 +576,7 @@ struct dvb_frontend *stb6100_attach(struct dvb_frontend *fe, state =kzalloc (sizeof (struct stb6100_state ),GFP_KERNEL );if (state =NULL ) - goto error; +return NULL ; state->config = config; state->i2c = i2c;
@@ -587,10 +587,6 @@ struct dvb_frontend *stb6100_attach(struct dvb_frontend *fe,printk ("%s: Attaching STB6100 \n" , __func__);return fe; - -error: -kfree (state); -return NULL ; }static int stb6100_release (struct dvb_frontend *fe)
drivers/media/dvb-frontends/tda665x.c +1 -5
@@ -229,7 +229,7 @@ struct dvb_frontend *tda665x_attach(struct dvb_frontend *fe, state =kzalloc (sizeof (struct tda665x_state ),GFP_KERNEL );if (state =NULL ) - goto exit; +return NULL ; state->config = config; state->i2c = i2c;
@@ -246,10 +246,6 @@ struct dvb_frontend *tda665x_attach(struct dvb_frontend *fe,printk (KERN_DEBUG "%s: Attaching TDA665x (%s) tuner\n" , __func__, info->name);return fe; - -exit: -kfree (state); -return NULL ; }EXPORT_SYMBOL (tda665x_attach);
drivers/media/platform/davinci/vpbe.c +0 -1
@@ -771,7 +771,6 @@ static int vpbe_initialize(struct device *dev, struct vpbe_device *vpbe_dev)return 0 ; vpbe_fail_amp_register: -kfree (vpbe_dev->amp); vpbe_fail_sd_register:kfree (vpbe_dev->encoders); vpbe_fail_v4l2_device:
drivers/media/tuners/mt2063.c +1 -5
@@ -2250,7 +2250,7 @@ struct dvb_frontend *mt2063_attach(struct dvb_frontend *fe, state =kzalloc (sizeof (struct mt2063_state ),GFP_KERNEL );if (state =NULL ) - goto error; +return NULL ; state->config = config; state->i2c = i2c;
@@ -2261,10 +2261,6 @@ struct dvb_frontend *mt2063_attach(struct dvb_frontend *fe,printk (KERN_INFO "%s: Attaching MT2063\n" , __func__);return fe; - -error: -kfree (state); -return NULL ; }EXPORT_SYMBOL_GPL (mt2063_attach);
2012/9/11 Peter Senna Tschudin <[email protected]>:
Quoted 66 lines
From: Peter Senna Tschudin <[email protected]>
The semantic patch that finds this problem is as follows:
(http://coccinelle.lip6.fr/)// <smpl>
@r exists@
position p1,p2;
expression x;
@@if (x@p1 = NULL) { ... kfree@p2(x); ... return ...; }
@unchanged exists@
position r.p1,r.p2;
expression e <= r.x,x,e1;
iterator I;
statement S;
@@if (x@p1 = NULL) { ... when !=
I(x,...)Swhen != e = e1 when != e += e1 when != e -= e1 when != ++e when != --e when != e++ when != e-- when != &ekfree@p2(x); ... return ...; }
@ok depends on unchanged exists@
position any r.p1;
position r.p2;
expression x;
@@... when != true x@p1 = NULL
kfree@p2(x);@depends on !ok && unchanged@
position r.p2;
expression x;
@@*kfree@p2(x);
// </smpl>Signed-off-by Peter Senna Tschudin <[email protected]>--- drivers/media/dvb-frontends/dvb_dummy_fe.c | 21 ++++++--------------- drivers/media/dvb-frontends/lg2160.c | 1 - drivers/media/dvb-frontends/s5h1432.c | 6 +----- drivers/media/dvb-frontends/s921.c | 7 +------ drivers/media/dvb-frontends/stb6100.c | 6 +----- drivers/media/dvb-frontends/tda665x.c | 6 +----- drivers/media/platform/davinci/vpbe.c | 1 - drivers/media/tuners/mt2063.c | 6 +----- 8 files changed, 11 insertions(+), 43 deletions(-)drivers/media/dvb-frontends/dvb_dummy_fe.c +0
-0
drivers/media/dvb-frontends/dvb_dummy_fe.c struct dvb_frontend* dvb_dummy_fe_ofdm_attach(void) · line 125
Quoted 6 lines
drivers/media/dvb-frontends/dvb_dummy_fe.c +2
-1@@ -121,16 +121,13 @@ struct dvb_frontend* dvb_dummy_fe_ofdm_attach(void)/* allocate memory for the internal state */ state =kzalloc (sizeof (struct dvb_dummy_fe_state ),GFP_KERNEL ); -if (state =NULL ) goto error; +if (state =NULL ) +return NULL ;
I know that is not the scope here but, what do you think to change
if (state = NULL)
for
if (!state)
?
maybe you can send another patch for simplify these.
Just my 2 cents :)
Quoted 199 lines
drivers/media/dvb-frontends/dvb_dummy_fe.c +4
-14/* create dvb_frontend */ memcpy (&state->frontend.ops, &dvb_dummy_fe_ofdm_ops,sizeof (struct dvb_frontend_ops )); state->frontend.demodulator_priv = state;return &state->frontend; - -error: -kfree (state); -return NULL ; }static struct dvb_frontend_ops dvb_dummy_fe_qpsk_ops;@@ -141,16 +138,13 @@ struct dvb_frontend *dvb_dummy_fe_qpsk_attach(void)/* allocate memory for the internal state */ state =kzalloc (sizeof (struct dvb_dummy_fe_state ),GFP_KERNEL ); -if (state =NULL ) goto error; +if (state =NULL ) +return NULL ;/* create dvb_frontend */ memcpy (&state->frontend.ops, &dvb_dummy_fe_qpsk_ops,sizeof (struct dvb_frontend_ops )); state->frontend.demodulator_priv = state;return &state->frontend; - -error: -kfree (state); -return NULL ; }static struct dvb_frontend_ops dvb_dummy_fe_qam_ops;@@ -161,16 +155,13 @@ struct dvb_frontend *dvb_dummy_fe_qam_attach(void)/* allocate memory for the internal state */ state =kzalloc (sizeof (struct dvb_dummy_fe_state ),GFP_KERNEL ); -if (state =NULL ) goto error; +if (state =NULL ) +return NULL ;/* create dvb_frontend */ memcpy (&state->frontend.ops, &dvb_dummy_fe_qam_ops,sizeof (struct dvb_frontend_ops )); state->frontend.demodulator_priv = state;return &state->frontend; - -error: -kfree (state); -return NULL ; }static struct dvb_frontend_ops dvb_dummy_fe_ofdm_ops = {drivers/media/dvb-frontends/lg2160.c +0
-1@@ -1451,7 +1451,6 @@ struct dvb_frontend *lg2160_attach(const struct lg2160_config *config,return &state->frontend; fail:lg_warn ("unable to detect LG216x hardware\n" ); -kfree (state);return NULL ; }EXPORT_SYMBOL (lg2160_attach);drivers/media/dvb-frontends/s5h1432.c +1
-5@@ -352,7 +352,7 @@ struct dvb_frontend *s5h1432_attach(const struct s5h1432_config *config,/* allocate memory for the internal state */ state =kmalloc (sizeof (struct s5h1432_state ),GFP_KERNEL );if (state =NULL ) - goto error; +return NULL ;/* setup the state */ state->config = config;@@ -367,10 +367,6 @@ struct dvb_frontend *s5h1432_attach(const struct s5h1432_config *config, state->frontend.demodulator_priv = state;return &state->frontend; - -error: -kfree (state); -return NULL ; }EXPORT_SYMBOL (s5h1432_attach);drivers/media/dvb-frontends/s921.c +1
-6@@ -489,7 +489,7 @@ struct dvb_frontend *s921_attach(const struct s921_config *config,dprintk ("\n" );if (state =NULL ) {rc ("Unable to kzalloc\n" ); - goto rcor; +return NULL ; }/* setup the state */ @@ -502,11 +502,6 @@ struct dvb_frontend *s921_attach(const struct s921_config *config, state->frontend.demodulator_priv = state;return &state->frontend; - -rcor: -kfree (state); - -return NULL ; }EXPORT_SYMBOL (s921_attach);drivers/media/dvb-frontends/stb6100.c +1
-5@@ -576,7 +576,7 @@ struct dvb_frontend *stb6100_attach(struct dvb_frontend *fe, state =kzalloc (sizeof (struct stb6100_state ),GFP_KERNEL );if (state =NULL ) - goto error; +return NULL ; state->config = config; state->i2c = i2c;@@ -587,10 +587,6 @@ struct dvb_frontend *stb6100_attach(struct dvb_frontend *fe,printk ("%s: Attaching STB6100 \n" , __func__);return fe; - -error: -kfree (state); -return NULL ; }static int stb6100_release (struct dvb_frontend *fe)drivers/media/dvb-frontends/tda665x.c +1
-5@@ -229,7 +229,7 @@ struct dvb_frontend *tda665x_attach(struct dvb_frontend *fe, state =kzalloc (sizeof (struct tda665x_state ),GFP_KERNEL );if (state =NULL ) - goto exit; +return NULL ; state->config = config; state->i2c = i2c;@@ -246,10 +246,6 @@ struct dvb_frontend *tda665x_attach(struct dvb_frontend *fe,printk (KERN_DEBUG "%s: Attaching TDA665x (%s) tuner\n" , __func__, info->name);return fe; - -exit: -kfree (state); -return NULL ; }EXPORT_SYMBOL (tda665x_attach);drivers/media/platform/davinci/vpbe.c +0
-1@@ -771,7 +771,6 @@ static int vpbe_initialize(struct device *dev, struct vpbe_device *vpbe_dev)return 0 ; vpbe_fail_amp_register: -kfree (vpbe_dev->amp); vpbe_fail_sd_register:kfree (vpbe_dev->encoders); vpbe_fail_v4l2_device:drivers/media/tuners/mt2063.c +1
-6@@ -2250,7 +2250,7 @@ struct dvb_frontend *mt2063_attach(struct dvb_frontend *fe, state =kzalloc (sizeof (struct mt2063_state ),GFP_KERNEL );if (state =NULL ) - goto error; +return NULL ; state->config = config; state->i2c = i2c;@@ -2261,10 +2261,6 @@ struct dvb_frontend *mt2063_attach(struct dvb_frontend *fe,printk (KERN_INFO "%s: Attaching MT2063\n" , __func__);return fe; - -error: -kfree (state); -return NULL ; }EXPORT_SYMBOL_GPL (mt2063_attach); --To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 10 lines
Att, Marcos Paulo de Souza Acadêmico de Ciencia da Computação - FURB - SC "Uma vida sem desafios é uma vida sem razão" "A life without challenges, is a non reason life" -- To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
drivers/media/dvb-frontends/lg2160.c struct dvb_frontend *lg2160_attach(const struct lg2160_config *config, · line 1455
Quoted 11 lines · Peter Senna Tschudin
drivers/media/dvb-frontends/lg2160.c +0
-1@@ -1451,7 +1451,6 @@ struct dvb_frontend *lg2160_attach(const struct lg2160_config *config,return &state->frontend; fail:lg_warn ("unable to detect LG216x hardware\n" ); -kfree (state);return NULL ; }
I wish you had fixed this the same as the others and removed the goto. Also the printk is redundant and wrong. Remove it too.
regards,
dan carpenter
I'll split this patch in one patch for file and resend.
Quoted 19 lines · Dan Carpenter
drivers/media/dvb-frontends/lg2160.c struct dvb_frontend *lg2160_attach(const struct lg2160_config *config, · line 1455
Quoted 11 lines · Peter Senna Tschudin
drivers/media/dvb-frontends/lg2160.c +0
-1@@ -1451,7 +1451,6 @@ struct dvb_frontend *lg2160_attach(const struct lg2160_config *config,return &state->frontend; fail:lg_warn ("unable to detect LG216x hardware\n" ); -kfree (state);return NULL ; }I wish you had fixed this the same as the others and removed the goto. Also the printk is redundant and wrong. Remove it too.
regards,
dan carpenter
Signature · 1 line
Peter