aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Nieder <jrnieder@gmail.com>2011-05-01 05:30:46 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2011-05-20 08:29:40 -0400
commit579b2b45120fa33f750cd65150d6d8995938750b (patch)
tree8338da6519c62b3d40e486df85acf5eacce6c137
parent344d6c6ba6ba5c4fede2f07adbd26d53109a2dd8 (diff)
[media] cx88: gracefully reject attempts to use unregistered cx88-blackbird driver
It should not be possible to enter mpeg_open and acquire core->lock without the blackbird driver being registered, so just error out if it is not. This makes the code more readable and should prevent the bug fixed by the patch "hold device lock during sub-driver initialization" from resurfacing again. Similarly, if we enter mpeg_release and acquire core->lock then either the blackbird driver is registered (since open files keep it loaded) or the sysadmin forced the driver's removal. In the latter case the state will be inconsistent and this is worth a loud warning. Tested-by: Andi Huber <hobrom@gmx.at> Tested-by: Marlon de Boer <marlon@hyves.nl> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
-rw-r--r--drivers/media/video/cx88/cx88-blackbird.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/drivers/media/video/cx88/cx88-blackbird.c b/drivers/media/video/cx88/cx88-blackbird.c
index f637d34d506..fa8e347c448 100644
--- a/drivers/media/video/cx88/cx88-blackbird.c
+++ b/drivers/media/video/cx88/cx88-blackbird.c
@@ -1060,18 +1060,21 @@ static int mpeg_open(struct file *file)
1060 1060
1061 /* Make sure we can acquire the hardware */ 1061 /* Make sure we can acquire the hardware */
1062 drv = cx8802_get_driver(dev, CX88_MPEG_BLACKBIRD); 1062 drv = cx8802_get_driver(dev, CX88_MPEG_BLACKBIRD);
1063 if (drv) { 1063 if (!drv) {
1064 err = drv->request_acquire(drv); 1064 dprintk(1, "%s: blackbird driver is not loaded\n", __func__);
1065 if(err != 0) { 1065 mutex_unlock(&dev->core->lock);
1066 dprintk(1,"%s: Unable to acquire hardware, %d\n", __func__, err); 1066 return -ENODEV;
1067 mutex_unlock(&dev->core->lock); 1067 }
1068 return err; 1068
1069 } 1069 err = drv->request_acquire(drv);
1070 if (err != 0) {
1071 dprintk(1,"%s: Unable to acquire hardware, %d\n", __func__, err);
1072 mutex_unlock(&dev->core->lock);
1073 return err;
1070 } 1074 }
1071 1075
1072 if (!atomic_read(&dev->core->mpeg_users) && blackbird_initialize_codec(dev) < 0) { 1076 if (!atomic_read(&dev->core->mpeg_users) && blackbird_initialize_codec(dev) < 0) {
1073 if (drv) 1077 drv->request_release(drv);
1074 drv->request_release(drv);
1075 mutex_unlock(&dev->core->lock); 1078 mutex_unlock(&dev->core->lock);
1076 return -EINVAL; 1079 return -EINVAL;
1077 } 1080 }
@@ -1080,8 +1083,7 @@ static int mpeg_open(struct file *file)
1080 /* allocate + initialize per filehandle data */ 1083 /* allocate + initialize per filehandle data */
1081 fh = kzalloc(sizeof(*fh),GFP_KERNEL); 1084 fh = kzalloc(sizeof(*fh),GFP_KERNEL);
1082 if (NULL == fh) { 1085 if (NULL == fh) {
1083 if (drv) 1086 drv->request_release(drv);
1084 drv->request_release(drv);
1085 mutex_unlock(&dev->core->lock); 1087 mutex_unlock(&dev->core->lock);
1086 return -ENOMEM; 1088 return -ENOMEM;
1087 } 1089 }
@@ -1125,6 +1127,7 @@ static int mpeg_release(struct file *file)
1125 1127
1126 /* Make sure we release the hardware */ 1128 /* Make sure we release the hardware */
1127 drv = cx8802_get_driver(dev, CX88_MPEG_BLACKBIRD); 1129 drv = cx8802_get_driver(dev, CX88_MPEG_BLACKBIRD);
1130 WARN_ON(!drv);
1128 if (drv) 1131 if (drv)
1129 drv->request_release(drv); 1132 drv->request_release(drv);
1130 1133