Re: [PATCH 6/6] EM28xx - don't sleep on disconnect

2011-08-20 Thread Mauro Carvalho Chehab
Em 20-08-2011 04:37, Chris Rankin escreveu:
 +
 + if (dev-state  DEV_DISCONNECTED) {
 + /* We cannot tell the device to sleep
 +  * once it has been unplugged. */
 + prevent_sleep(dvb-fe[0]-ops);
 + prevent_sleep(dvb-fe[1]-ops);

This will cause an OOPS if dvb-fe[n] == NULL.

 + }
 +

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 6/6] EM28xx - don't sleep on disconnect

2011-08-20 Thread Chris Rankin
--- On Sat, 20/8/11, Mauro Carvalho Chehab mche...@redhat.com wrot
 
 This will cause an OOPS if dvb-fe[n] == NULL.
 

OK, that's trivially fixable. I'll send you an updated patch. Is it safe to 
assume that dvb-fe[0] at least will always be non-NULL?

Cheers,
Chris

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 6/6] EM28xx - don't sleep on disconnect

2011-08-20 Thread Mauro Carvalho Chehab
Em 20-08-2011 06:46, Chris Rankin escreveu:
 --- On Sat, 20/8/11, Mauro Carvalho Chehab mche...@redhat.com wrot

 This will cause an OOPS if dvb-fe[n] == NULL.

 
 OK, that's trivially fixable. I'll send you an updated patch. Is it safe to 
 assume that dvb-fe[0] at least will always be non-NULL?

No, it isn't. The dvb initialization may fail or the device can be analog only,
but somebody might manually load em28xx-dvb (or two devices were plugged).

Regards,
Mauro
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 6/6] EM28xx - don't sleep on disconnect

2011-08-20 Thread Chris Rankin
Here's the updated patch that checks whether the frontend exists before 
disabling the sleep operations.


Cheers,
Chris

--- linux-3.0/drivers/media/common/tuners/tda18271-fe.c.orig2011-08-20 
18:53:48.0 +0100
+++ linux-3.0/drivers/media/common/tuners/tda18271-fe.c 2011-08-20 
19:21:34.0 +0100
@@ -1230,7 +1230,7 @@
return 0;
 }
 
-static struct dvb_tuner_ops tda18271_tuner_ops = {
+static const struct dvb_tuner_ops tda18271_tuner_ops = {
.info = {
.name = NXP TDA18271HD,
.frequency_min  =  4500,
--- linux-3.0/drivers/media/dvb/frontends/cxd2820r_core.c.orig  2011-08-20 
18:54:09.0 +0100
+++ linux-3.0/drivers/media/dvb/frontends/cxd2820r_core.c   2011-08-20 
19:22:21.0 +0100
@@ -778,7 +778,7 @@
 }
 EXPORT_SYMBOL(cxd2820r_get_tuner_i2c_adapter);
 
-static struct dvb_frontend_ops cxd2820r_ops[2];
+static const struct dvb_frontend_ops cxd2820r_ops[2];
 
 struct dvb_frontend *cxd2820r_attach(const struct cxd2820r_config *cfg,
struct i2c_adapter *i2c, struct dvb_frontend *fe)
@@ -844,7 +844,7 @@
 }
 EXPORT_SYMBOL(cxd2820r_attach);
 
-static struct dvb_frontend_ops cxd2820r_ops[2] = {
+static const struct dvb_frontend_ops cxd2820r_ops[2] = {
{
/* DVB-T/T2 */
.info = {
--- linux-3.0/drivers/media/video/em28xx/em28xx-dvb.c.orig  2011-08-20 
18:53:25.0 +0100
+++ linux-3.0/drivers/media/video/em28xx/em28xx-dvb.c   2011-08-20 
19:26:51.0 +0100
@@ -720,6 +720,13 @@
goto ret;
 }
 
+static inline void prevent_sleep(struct dvb_frontend_ops *ops)
+{
+   ops-set_voltage = NULL;
+   ops-sleep = NULL;
+   ops-tuner_ops.sleep = NULL;
+}
+
 static int dvb_fini(struct em28xx *dev)
 {
if (!dev-board.has_dvb) {
@@ -728,8 +735,19 @@
}
 
if (dev-dvb) {
-   unregister_dvb(dev-dvb);
-   kfree(dev-dvb);
+   struct em28xx_dvb *dvb = dev-dvb;
+
+   if (dev-state  DEV_DISCONNECTED) {
+   /* We cannot tell the device to sleep
+* once it has been unplugged. */
+   if (dvb-fe[0])
+   prevent_sleep(dvb-fe[0]-ops);
+   if (dvb-fe[1])
+   prevent_sleep(dvb-fe[1]-ops);
+   }
+
+   unregister_dvb(dvb);
+   kfree(dvb);
dev-dvb = NULL;
}