aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media
diff options
context:
space:
mode:
authorTrent Piepho <xyzzy@speakeasy.org>2009-01-12 11:09:46 -0500
committerMauro Carvalho Chehab <mchehab@redhat.com>2009-01-29 05:35:38 -0500
commitfc96ab730268b8b652ae2494088e8bd4572f58aa (patch)
tree5b177aae0894b5fb738c263b624c4dd16f5ae010 /drivers/media
parent5e098b668977c85838af09005bd96c2e987654f0 (diff)
V4L/DVB (10226): zoran: Get rid of extra module ref count
The zoran driver does a module_get/put of THIS_MODULE on device open/close. This isn't necessary as the kernel does this automatically. Clean up the failure path of zoran_open() somewhat. Make the dprintk()s on open/close a higher debug level and make the user count printed take the current open/close into account. Signed-off-by: Trent Piepho <xyzzy@speakeasy.org> Acked-by: Jean Delvare <khali@linux-fr.org> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media')
-rw-r--r--drivers/media/video/zoran/zoran_driver.c82
1 files changed, 33 insertions, 49 deletions
diff --git a/drivers/media/video/zoran/zoran_driver.c b/drivers/media/video/zoran/zoran_driver.c
index 21f37a68714b..120ef235e63d 100644
--- a/drivers/media/video/zoran/zoran_driver.c
+++ b/drivers/media/video/zoran/zoran_driver.c
@@ -1200,7 +1200,10 @@ static int zoran_open(struct file *file)
1200{ 1200{
1201 struct zoran *zr = video_drvdata(file); 1201 struct zoran *zr = video_drvdata(file);
1202 struct zoran_fh *fh; 1202 struct zoran_fh *fh;
1203 int res, first_open = 0, have_module_locks = 0; 1203 int res, first_open = 0;
1204
1205 dprintk(2, KERN_INFO "%s: zoran_open(%s, pid=[%d]), users(-)=%d\n",
1206 ZR_DEVNAME(zr), current->comm, task_pid_nr(current), zr->user + 1);
1204 1207
1205 lock_kernel(); 1208 lock_kernel();
1206 1209
@@ -1208,56 +1211,39 @@ static int zoran_open(struct file *file)
1208 * so locking ourselves only causes deadlocks */ 1211 * so locking ourselves only causes deadlocks */
1209 /*mutex_lock(&zr->resource_lock);*/ 1212 /*mutex_lock(&zr->resource_lock);*/
1210 1213
1214 if (zr->user >= 2048) {
1215 dprintk(1, KERN_ERR "%s: too many users (%d) on device\n",
1216 ZR_DEVNAME(zr), zr->user);
1217 res = -EBUSY;
1218 goto fail_unlock;
1219 }
1220
1211 if (!zr->decoder) { 1221 if (!zr->decoder) {
1212 dprintk(1, 1222 dprintk(1,
1213 KERN_ERR "%s: no TV decoder loaded for device!\n", 1223 KERN_ERR "%s: no TV decoder loaded for device!\n",
1214 ZR_DEVNAME(zr)); 1224 ZR_DEVNAME(zr));
1215 res = -EIO; 1225 res = -EIO;
1216 goto open_unlock_and_return; 1226 goto fail_unlock;
1217 } 1227 }
1218 1228
1219 /* try to grab a module lock */
1220 if (!try_module_get(THIS_MODULE)) {
1221 dprintk(1,
1222 KERN_ERR
1223 "%s: failed to acquire my own lock! PANIC!\n",
1224 ZR_DEVNAME(zr));
1225 res = -ENODEV;
1226 goto open_unlock_and_return;
1227 }
1228 if (!try_module_get(zr->decoder->driver->driver.owner)) { 1229 if (!try_module_get(zr->decoder->driver->driver.owner)) {
1229 dprintk(1, 1230 dprintk(1,
1230 KERN_ERR 1231 KERN_ERR
1231 "%s: failed to grab ownership of i2c decoder\n", 1232 "%s: failed to grab ownership of video decoder\n",
1232 ZR_DEVNAME(zr)); 1233 ZR_DEVNAME(zr));
1233 res = -EIO; 1234 res = -EIO;
1234 module_put(THIS_MODULE); 1235 goto fail_unlock;
1235 goto open_unlock_and_return;
1236 } 1236 }
1237 if (zr->encoder && 1237 if (zr->encoder &&
1238 !try_module_get(zr->encoder->driver->driver.owner)) { 1238 !try_module_get(zr->encoder->driver->driver.owner)) {
1239 dprintk(1, 1239 dprintk(1,
1240 KERN_ERR 1240 KERN_ERR
1241 "%s: failed to grab ownership of i2c encoder\n", 1241 "%s: failed to grab ownership of video encoder\n",
1242 ZR_DEVNAME(zr)); 1242 ZR_DEVNAME(zr));
1243 res = -EIO; 1243 res = -EIO;
1244 module_put(zr->decoder->driver->driver.owner); 1244 goto fail_decoder;
1245 module_put(THIS_MODULE);
1246 goto open_unlock_and_return;
1247 }
1248
1249 have_module_locks = 1;
1250
1251 if (zr->user >= 2048) {
1252 dprintk(1, KERN_ERR "%s: too many users (%d) on device\n",
1253 ZR_DEVNAME(zr), zr->user);
1254 res = -EBUSY;
1255 goto open_unlock_and_return;
1256 } 1245 }
1257 1246
1258 dprintk(1, KERN_INFO "%s: zoran_open(%s, pid=[%d]), users(-)=%d\n",
1259 ZR_DEVNAME(zr), current->comm, task_pid_nr(current), zr->user);
1260
1261 /* now, create the open()-specific file_ops struct */ 1247 /* now, create the open()-specific file_ops struct */
1262 fh = kzalloc(sizeof(struct zoran_fh), GFP_KERNEL); 1248 fh = kzalloc(sizeof(struct zoran_fh), GFP_KERNEL);
1263 if (!fh) { 1249 if (!fh) {
@@ -1266,7 +1252,7 @@ static int zoran_open(struct file *file)
1266 "%s: zoran_open() - allocation of zoran_fh failed\n", 1252 "%s: zoran_open() - allocation of zoran_fh failed\n",
1267 ZR_DEVNAME(zr)); 1253 ZR_DEVNAME(zr));
1268 res = -ENOMEM; 1254 res = -ENOMEM;
1269 goto open_unlock_and_return; 1255 goto fail_encoder;
1270 } 1256 }
1271 /* used to be BUZ_MAX_WIDTH/HEIGHT, but that gives overflows 1257 /* used to be BUZ_MAX_WIDTH/HEIGHT, but that gives overflows
1272 * on norm-change! */ 1258 * on norm-change! */
@@ -1277,9 +1263,8 @@ static int zoran_open(struct file *file)
1277 KERN_ERR 1263 KERN_ERR
1278 "%s: zoran_open() - allocation of overlay_mask failed\n", 1264 "%s: zoran_open() - allocation of overlay_mask failed\n",
1279 ZR_DEVNAME(zr)); 1265 ZR_DEVNAME(zr));
1280 kfree(fh);
1281 res = -ENOMEM; 1266 res = -ENOMEM;
1282 goto open_unlock_and_return; 1267 goto fail_fh;
1283 } 1268 }
1284 1269
1285 if (zr->user++ == 0) 1270 if (zr->user++ == 0)
@@ -1304,18 +1289,19 @@ static int zoran_open(struct file *file)
1304 1289
1305 return 0; 1290 return 0;
1306 1291
1307open_unlock_and_return: 1292fail_fh:
1308 /* if we grabbed locks, release them accordingly */ 1293 kfree(fh);
1309 if (have_module_locks) { 1294fail_encoder:
1310 module_put(zr->decoder->driver->driver.owner); 1295 if (zr->encoder)
1311 if (zr->encoder) { 1296 module_put(zr->encoder->driver->driver.owner);
1312 module_put(zr->encoder->driver->driver.owner); 1297fail_decoder:
1313 } 1298 module_put(zr->decoder->driver->driver.owner);
1314 module_put(THIS_MODULE); 1299fail_unlock:
1315 }
1316
1317 unlock_kernel(); 1300 unlock_kernel();
1318 1301
1302 dprintk(2, KERN_INFO "%s: open failed (%d), users(-)=%d\n",
1303 ZR_DEVNAME(zr), res, zr->user);
1304
1319 return res; 1305 return res;
1320} 1306}
1321 1307
@@ -1325,8 +1311,8 @@ zoran_close(struct file *file)
1325 struct zoran_fh *fh = file->private_data; 1311 struct zoran_fh *fh = file->private_data;
1326 struct zoran *zr = fh->zr; 1312 struct zoran *zr = fh->zr;
1327 1313
1328 dprintk(1, KERN_INFO "%s: zoran_close(%s, pid=[%d]), users(+)=%d\n", 1314 dprintk(2, KERN_INFO "%s: zoran_close(%s, pid=[%d]), users(+)=%d\n",
1329 ZR_DEVNAME(zr), current->comm, task_pid_nr(current), zr->user); 1315 ZR_DEVNAME(zr), current->comm, task_pid_nr(current), zr->user - 1);
1330 1316
1331 /* kernel locks (fs/device.c), so don't do that ourselves 1317 /* kernel locks (fs/device.c), so don't do that ourselves
1332 * (prevents deadlocks) */ 1318 * (prevents deadlocks) */
@@ -1372,10 +1358,8 @@ zoran_close(struct file *file)
1372 1358
1373 /* release locks on the i2c modules */ 1359 /* release locks on the i2c modules */
1374 module_put(zr->decoder->driver->driver.owner); 1360 module_put(zr->decoder->driver->driver.owner);
1375 if (zr->encoder) { 1361 if (zr->encoder)
1376 module_put(zr->encoder->driver->driver.owner); 1362 module_put(zr->encoder->driver->driver.owner);
1377 }
1378 module_put(THIS_MODULE);
1379 1363
1380 /*mutex_unlock(&zr->resource_lock);*/ 1364 /*mutex_unlock(&zr->resource_lock);*/
1381 1365