From 775f85f9f968985c9b5c9e6df137575a118fdf76 Mon Sep 17 00:00:00 2001 From: Michael Krufky Date: Mon, 4 Jun 2007 13:40:27 -0400 Subject: tuner: add release callback From: Michael Krufky Individual tuner drivers are now allocating memory themselves for their own private data structures. This changeset adds a release callback to the tuner operations, so that newer drivers that may require more complex data structures may release this private data themselves. Signed-off-by: Michael Krufky --- linux/drivers/media/video/tuner-core.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'linux/drivers') diff --git a/linux/drivers/media/video/tuner-core.c b/linux/drivers/media/video/tuner-core.c index 969890f90..d2c946e2a 100644 --- a/linux/drivers/media/video/tuner-core.c +++ b/linux/drivers/media/video/tuner-core.c @@ -204,11 +204,12 @@ static void set_type(struct i2c_client *c, unsigned int type, } #endif -#if 1 /* discard private data, in case set_type() was previously called */ + if (t->release) + t->release(c); kfree(t->priv); t->priv = NULL; -#endif + switch (t->type) { case TUNER_MT2032: microtune_init(c); @@ -620,6 +621,8 @@ static int tuner_detach(struct i2c_client *client) #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) MOD_DEC_USE_COUNT; #endif + if (t->release) + t->release(client); kfree(t->priv); #if 0 t->priv = NULL; -- cgit v1.2.3 From 9ee5949a70d76f5d85edf7d5571af93917eeff0a Mon Sep 17 00:00:00 2001 From: Michael Krufky Date: Mon, 4 Jun 2007 14:20:11 -0400 Subject: tuner: define release callback for mt20xx, tda9887 and tda8290 From: Michael Krufky Define tuner release callbacks for mt20xx, tda9887 and tda8290, so that these drivers can release their own private structures themselves. Signed-off-by: Michael Krufky --- linux/drivers/media/video/mt20xx.c | 9 +++++++++ linux/drivers/media/video/tda8290.c | 9 +++++++++ linux/drivers/media/video/tda9887.c | 9 +++++++++ 3 files changed, 27 insertions(+) (limited to 'linux/drivers') diff --git a/linux/drivers/media/video/mt20xx.c b/linux/drivers/media/video/mt20xx.c index b73c3e42f..775d57f5d 100644 --- a/linux/drivers/media/video/mt20xx.c +++ b/linux/drivers/media/video/mt20xx.c @@ -499,6 +499,14 @@ static int mt2050_init(struct i2c_client *c) return 0; } +static void microtune_release(struct i2c_client *c) +{ + struct tuner *t = i2c_get_clientdata(c); + + kfree(t->priv); + t->priv = NULL; +} + int microtune_init(struct i2c_client *c) { struct microtune_priv *priv = NULL; @@ -518,6 +526,7 @@ int microtune_init(struct i2c_client *c) t->set_tv_freq = NULL; t->set_radio_freq = NULL; t->standby = NULL; + t->release = microtune_release; if (t->std & V4L2_STD_525_60) { tuner_dbg("pinnacle ntsc\n"); priv->radio_if2 = 41300 * 1000; diff --git a/linux/drivers/media/video/tda8290.c b/linux/drivers/media/video/tda8290.c index f375eb6b8..63d76b925 100644 --- a/linux/drivers/media/video/tda8290.c +++ b/linux/drivers/media/video/tda8290.c @@ -599,6 +599,14 @@ static void tda8290_init_tuner(struct i2c_client *c) /*---------------------------------------------------------------------*/ +static void tda8290_release(struct i2c_client *c) +{ + struct tuner *t = i2c_get_clientdata(c); + + kfree(t->priv); + t->priv = NULL; +} + int tda8290_init(struct i2c_client *c) { struct tda8290_priv *priv = NULL; @@ -667,6 +675,7 @@ int tda8290_init(struct i2c_client *c) t->set_radio_freq = set_radio_freq; t->has_signal = has_signal; t->standby = standby; + t->release = tda8290_release; priv->tda827x_lpsel = 0; t->mode = V4L2_TUNER_ANALOG_TV; diff --git a/linux/drivers/media/video/tda9887.c b/linux/drivers/media/video/tda9887.c index cce1defd3..38c57a838 100644 --- a/linux/drivers/media/video/tda9887.c +++ b/linux/drivers/media/video/tda9887.c @@ -602,6 +602,14 @@ static void tda9887_set_freq(struct i2c_client *client, unsigned int freq) tda9887_configure(client); } +static void tda9887_release(struct i2c_client *c) +{ + struct tuner *t = i2c_get_clientdata(c); + + kfree(t->priv); + t->priv = NULL; +} + int tda9887_tuner_init(struct i2c_client *c) { struct tda9887_priv *priv = NULL; @@ -622,6 +630,7 @@ int tda9887_tuner_init(struct i2c_client *c) t->standby = tda9887_standby; t->tuner_status = tda9887_tuner_status; t->get_afc = tda9887_get_afc; + t->release = tda9887_release; return 0; } -- cgit v1.2.3 From 86d97675ab308eedbdf3547b6d52dc716f778991 Mon Sep 17 00:00:00 2001 From: Michael Krufky Date: Mon, 4 Jun 2007 15:00:45 -0400 Subject: tuner: clean up kfree() after release From: Michael Krufky Although it is safe to kfree(NULL), We only need to kfree(priv) if the release callback is undefined. As it stands now, there is some redundancy in the operation of releasing the priv data structures. This patch will call kfree(priv) and set priv to NULL, if the release callback isnt defined. Otherwise, let the release callback handle this itself. Thanks to Mauro Carvalho Chehab for suggesting this. Signed-off-by: Michael Krufky --- linux/drivers/media/video/tuner-core.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'linux/drivers') diff --git a/linux/drivers/media/video/tuner-core.c b/linux/drivers/media/video/tuner-core.c index d2c946e2a..e00c59873 100644 --- a/linux/drivers/media/video/tuner-core.c +++ b/linux/drivers/media/video/tuner-core.c @@ -207,8 +207,10 @@ static void set_type(struct i2c_client *c, unsigned int type, /* discard private data, in case set_type() was previously called */ if (t->release) t->release(c); - kfree(t->priv); - t->priv = NULL; + else { + kfree(t->priv); + t->priv = NULL; + } switch (t->type) { case TUNER_MT2032: @@ -623,10 +625,12 @@ MOD_DEC_USE_COUNT; #endif if (t->release) t->release(client); - kfree(t->priv); + else { + kfree(t->priv); #if 0 - t->priv = NULL; + t->priv = NULL; #endif + } kfree(t); return 0; } -- cgit v1.2.3