diff options
Diffstat (limited to 'drivers/media/video/zoran/zoran_driver.c')
-rw-r--r-- | drivers/media/video/zoran/zoran_driver.c | 105 |
1 files changed, 35 insertions, 70 deletions
diff --git a/drivers/media/video/zoran/zoran_driver.c b/drivers/media/video/zoran/zoran_driver.c index b58b9dda715c..120ef235e63d 100644 --- a/drivers/media/video/zoran/zoran_driver.c +++ b/drivers/media/video/zoran/zoran_driver.c | |||
@@ -1196,83 +1196,54 @@ zoran_close_end_session (struct file *file) | |||
1196 | * Open a zoran card. Right now the flags stuff is just playing | 1196 | * Open a zoran card. Right now the flags stuff is just playing |
1197 | */ | 1197 | */ |
1198 | 1198 | ||
1199 | static int | 1199 | static int zoran_open(struct file *file) |
1200 | zoran_open(struct file *file) | ||
1201 | { | 1200 | { |
1202 | unsigned int minor = video_devdata(file)->minor; | 1201 | struct zoran *zr = video_drvdata(file); |
1203 | struct zoran *zr = NULL; | ||
1204 | struct zoran_fh *fh; | 1202 | struct zoran_fh *fh; |
1205 | int i, res, first_open = 0, have_module_locks = 0; | 1203 | int res, first_open = 0; |
1206 | 1204 | ||
1207 | lock_kernel(); | 1205 | dprintk(2, KERN_INFO "%s: zoran_open(%s, pid=[%d]), users(-)=%d\n", |
1208 | /* find the device */ | 1206 | ZR_DEVNAME(zr), current->comm, task_pid_nr(current), zr->user + 1); |
1209 | for (i = 0; i < zoran_num; i++) { | ||
1210 | if (zoran[i]->video_dev->minor == minor) { | ||
1211 | zr = zoran[i]; | ||
1212 | break; | ||
1213 | } | ||
1214 | } | ||
1215 | 1207 | ||
1216 | if (!zr) { | 1208 | lock_kernel(); |
1217 | dprintk(1, KERN_ERR "%s: device not found!\n", ZORAN_NAME); | ||
1218 | res = -ENODEV; | ||
1219 | goto open_unlock_and_return; | ||
1220 | } | ||
1221 | 1209 | ||
1222 | /* see fs/device.c - the kernel already locks during open(), | 1210 | /* see fs/device.c - the kernel already locks during open(), |
1223 | * so locking ourselves only causes deadlocks */ | 1211 | * so locking ourselves only causes deadlocks */ |
1224 | /*mutex_lock(&zr->resource_lock);*/ | 1212 | /*mutex_lock(&zr->resource_lock);*/ |
1225 | 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 | |||
1226 | if (!zr->decoder) { | 1221 | if (!zr->decoder) { |
1227 | dprintk(1, | 1222 | dprintk(1, |
1228 | KERN_ERR "%s: no TV decoder loaded for device!\n", | 1223 | KERN_ERR "%s: no TV decoder loaded for device!\n", |
1229 | ZR_DEVNAME(zr)); | 1224 | ZR_DEVNAME(zr)); |
1230 | res = -EIO; | 1225 | res = -EIO; |
1231 | goto open_unlock_and_return; | 1226 | goto fail_unlock; |
1232 | } | 1227 | } |
1233 | 1228 | ||
1234 | /* try to grab a module lock */ | ||
1235 | if (!try_module_get(THIS_MODULE)) { | ||
1236 | dprintk(1, | ||
1237 | KERN_ERR | ||
1238 | "%s: failed to acquire my own lock! PANIC!\n", | ||
1239 | ZR_DEVNAME(zr)); | ||
1240 | res = -ENODEV; | ||
1241 | goto open_unlock_and_return; | ||
1242 | } | ||
1243 | if (!try_module_get(zr->decoder->driver->driver.owner)) { | 1229 | if (!try_module_get(zr->decoder->driver->driver.owner)) { |
1244 | dprintk(1, | 1230 | dprintk(1, |
1245 | KERN_ERR | 1231 | KERN_ERR |
1246 | "%s: failed to grab ownership of i2c decoder\n", | 1232 | "%s: failed to grab ownership of video decoder\n", |
1247 | ZR_DEVNAME(zr)); | 1233 | ZR_DEVNAME(zr)); |
1248 | res = -EIO; | 1234 | res = -EIO; |
1249 | module_put(THIS_MODULE); | 1235 | goto fail_unlock; |
1250 | goto open_unlock_and_return; | ||
1251 | } | 1236 | } |
1252 | if (zr->encoder && | 1237 | if (zr->encoder && |
1253 | !try_module_get(zr->encoder->driver->driver.owner)) { | 1238 | !try_module_get(zr->encoder->driver->driver.owner)) { |
1254 | dprintk(1, | 1239 | dprintk(1, |
1255 | KERN_ERR | 1240 | KERN_ERR |
1256 | "%s: failed to grab ownership of i2c encoder\n", | 1241 | "%s: failed to grab ownership of video encoder\n", |
1257 | ZR_DEVNAME(zr)); | 1242 | ZR_DEVNAME(zr)); |
1258 | res = -EIO; | 1243 | res = -EIO; |
1259 | module_put(zr->decoder->driver->driver.owner); | 1244 | goto fail_decoder; |
1260 | module_put(THIS_MODULE); | ||
1261 | goto open_unlock_and_return; | ||
1262 | } | 1245 | } |
1263 | 1246 | ||
1264 | have_module_locks = 1; | ||
1265 | |||
1266 | if (zr->user >= 2048) { | ||
1267 | dprintk(1, KERN_ERR "%s: too many users (%d) on device\n", | ||
1268 | ZR_DEVNAME(zr), zr->user); | ||
1269 | res = -EBUSY; | ||
1270 | goto open_unlock_and_return; | ||
1271 | } | ||
1272 | |||
1273 | dprintk(1, KERN_INFO "%s: zoran_open(%s, pid=[%d]), users(-)=%d\n", | ||
1274 | ZR_DEVNAME(zr), current->comm, task_pid_nr(current), zr->user); | ||
1275 | |||
1276 | /* now, create the open()-specific file_ops struct */ | 1247 | /* now, create the open()-specific file_ops struct */ |
1277 | fh = kzalloc(sizeof(struct zoran_fh), GFP_KERNEL); | 1248 | fh = kzalloc(sizeof(struct zoran_fh), GFP_KERNEL); |
1278 | if (!fh) { | 1249 | if (!fh) { |
@@ -1281,7 +1252,7 @@ zoran_open(struct file *file) | |||
1281 | "%s: zoran_open() - allocation of zoran_fh failed\n", | 1252 | "%s: zoran_open() - allocation of zoran_fh failed\n", |
1282 | ZR_DEVNAME(zr)); | 1253 | ZR_DEVNAME(zr)); |
1283 | res = -ENOMEM; | 1254 | res = -ENOMEM; |
1284 | goto open_unlock_and_return; | 1255 | goto fail_encoder; |
1285 | } | 1256 | } |
1286 | /* used to be BUZ_MAX_WIDTH/HEIGHT, but that gives overflows | 1257 | /* used to be BUZ_MAX_WIDTH/HEIGHT, but that gives overflows |
1287 | * on norm-change! */ | 1258 | * on norm-change! */ |
@@ -1292,9 +1263,8 @@ zoran_open(struct file *file) | |||
1292 | KERN_ERR | 1263 | KERN_ERR |
1293 | "%s: zoran_open() - allocation of overlay_mask failed\n", | 1264 | "%s: zoran_open() - allocation of overlay_mask failed\n", |
1294 | ZR_DEVNAME(zr)); | 1265 | ZR_DEVNAME(zr)); |
1295 | kfree(fh); | ||
1296 | res = -ENOMEM; | 1266 | res = -ENOMEM; |
1297 | goto open_unlock_and_return; | 1267 | goto fail_fh; |
1298 | } | 1268 | } |
1299 | 1269 | ||
1300 | if (zr->user++ == 0) | 1270 | if (zr->user++ == 0) |
@@ -1319,22 +1289,19 @@ zoran_open(struct file *file) | |||
1319 | 1289 | ||
1320 | return 0; | 1290 | return 0; |
1321 | 1291 | ||
1322 | open_unlock_and_return: | 1292 | fail_fh: |
1323 | /* if we grabbed locks, release them accordingly */ | 1293 | kfree(fh); |
1324 | if (have_module_locks) { | 1294 | fail_encoder: |
1325 | module_put(zr->decoder->driver->driver.owner); | 1295 | if (zr->encoder) |
1326 | if (zr->encoder) { | 1296 | module_put(zr->encoder->driver->driver.owner); |
1327 | module_put(zr->encoder->driver->driver.owner); | 1297 | fail_decoder: |
1328 | } | 1298 | module_put(zr->decoder->driver->driver.owner); |
1329 | module_put(THIS_MODULE); | 1299 | fail_unlock: |
1330 | } | ||
1331 | |||
1332 | /* if there's no device found, we didn't obtain the lock either */ | ||
1333 | if (zr) { | ||
1334 | /*mutex_unlock(&zr->resource_lock);*/ | ||
1335 | } | ||
1336 | unlock_kernel(); | 1300 | unlock_kernel(); |
1337 | 1301 | ||
1302 | dprintk(2, KERN_INFO "%s: open failed (%d), users(-)=%d\n", | ||
1303 | ZR_DEVNAME(zr), res, zr->user); | ||
1304 | |||
1338 | return res; | 1305 | return res; |
1339 | } | 1306 | } |
1340 | 1307 | ||
@@ -1344,8 +1311,8 @@ zoran_close(struct file *file) | |||
1344 | struct zoran_fh *fh = file->private_data; | 1311 | struct zoran_fh *fh = file->private_data; |
1345 | struct zoran *zr = fh->zr; | 1312 | struct zoran *zr = fh->zr; |
1346 | 1313 | ||
1347 | 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", |
1348 | ZR_DEVNAME(zr), current->comm, task_pid_nr(current), zr->user); | 1315 | ZR_DEVNAME(zr), current->comm, task_pid_nr(current), zr->user - 1); |
1349 | 1316 | ||
1350 | /* kernel locks (fs/device.c), so don't do that ourselves | 1317 | /* kernel locks (fs/device.c), so don't do that ourselves |
1351 | * (prevents deadlocks) */ | 1318 | * (prevents deadlocks) */ |
@@ -1391,10 +1358,8 @@ zoran_close(struct file *file) | |||
1391 | 1358 | ||
1392 | /* release locks on the i2c modules */ | 1359 | /* release locks on the i2c modules */ |
1393 | module_put(zr->decoder->driver->driver.owner); | 1360 | module_put(zr->decoder->driver->driver.owner); |
1394 | if (zr->encoder) { | 1361 | if (zr->encoder) |
1395 | module_put(zr->encoder->driver->driver.owner); | 1362 | module_put(zr->encoder->driver->driver.owner); |
1396 | } | ||
1397 | module_put(THIS_MODULE); | ||
1398 | 1363 | ||
1399 | /*mutex_unlock(&zr->resource_lock);*/ | 1364 | /*mutex_unlock(&zr->resource_lock);*/ |
1400 | 1365 | ||