Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[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>

authored by

Jonathan Nieder and committed by
Mauro Carvalho Chehab
579b2b45 344d6c6b

+14 -11
+14 -11
drivers/media/video/cx88/cx88-blackbird.c
··· 1060 1060 1061 1061 /* Make sure we can acquire the hardware */ 1062 1062 drv = cx8802_get_driver(dev, CX88_MPEG_BLACKBIRD); 1063 - if (drv) { 1064 - err = drv->request_acquire(drv); 1065 - if(err != 0) { 1066 - dprintk(1,"%s: Unable to acquire hardware, %d\n", __func__, err); 1067 - mutex_unlock(&dev->core->lock); 1068 - return err; 1069 - } 1063 + if (!drv) { 1064 + dprintk(1, "%s: blackbird driver is not loaded\n", __func__); 1065 + mutex_unlock(&dev->core->lock); 1066 + return -ENODEV; 1067 + } 1068 + 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 1076 if (!atomic_read(&dev->core->mpeg_users) && blackbird_initialize_codec(dev) < 0) { 1073 - if (drv) 1074 - drv->request_release(drv); 1077 + drv->request_release(drv); 1075 1078 mutex_unlock(&dev->core->lock); 1076 1079 return -EINVAL; 1077 1080 } ··· 1083 1080 /* allocate + initialize per filehandle data */ 1084 1081 fh = kzalloc(sizeof(*fh),GFP_KERNEL); 1085 1082 if (NULL == fh) { 1086 - if (drv) 1087 - drv->request_release(drv); 1083 + drv->request_release(drv); 1088 1084 mutex_unlock(&dev->core->lock); 1089 1085 return -ENOMEM; 1090 1086 } ··· 1127 1125 1128 1126 /* Make sure we release the hardware */ 1129 1127 drv = cx8802_get_driver(dev, CX88_MPEG_BLACKBIRD); 1128 + WARN_ON(!drv); 1130 1129 if (drv) 1131 1130 drv->request_release(drv); 1132 1131