Commit fc96ab73 authored by Trent Piepho's avatar Trent Piepho Committed by Mauro Carvalho Chehab

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: default avatarTrent Piepho <xyzzy@speakeasy.org>
Acked-by: default avatarJean Delvare <khali@linux-fr.org>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 5e098b66
...@@ -1200,7 +1200,10 @@ static int zoran_open(struct file *file) ...@@ -1200,7 +1200,10 @@ static int zoran_open(struct file *file)
{ {
struct zoran *zr = video_drvdata(file); struct zoran *zr = video_drvdata(file);
struct zoran_fh *fh; struct zoran_fh *fh;
int res, first_open = 0, have_module_locks = 0; int res, first_open = 0;
dprintk(2, KERN_INFO "%s: zoran_open(%s, pid=[%d]), users(-)=%d\n",
ZR_DEVNAME(zr), current->comm, task_pid_nr(current), zr->user + 1);
lock_kernel(); lock_kernel();
...@@ -1208,56 +1211,39 @@ static int zoran_open(struct file *file) ...@@ -1208,56 +1211,39 @@ static int zoran_open(struct file *file)
* so locking ourselves only causes deadlocks */ * so locking ourselves only causes deadlocks */
/*mutex_lock(&zr->resource_lock);*/ /*mutex_lock(&zr->resource_lock);*/
if (zr->user >= 2048) {
dprintk(1, KERN_ERR "%s: too many users (%d) on device\n",
ZR_DEVNAME(zr), zr->user);
res = -EBUSY;
goto fail_unlock;
}
if (!zr->decoder) { if (!zr->decoder) {
dprintk(1, dprintk(1,
KERN_ERR "%s: no TV decoder loaded for device!\n", KERN_ERR "%s: no TV decoder loaded for device!\n",
ZR_DEVNAME(zr)); ZR_DEVNAME(zr));
res = -EIO; res = -EIO;
goto open_unlock_and_return; goto fail_unlock;
} }
/* try to grab a module lock */
if (!try_module_get(THIS_MODULE)) {
dprintk(1,
KERN_ERR
"%s: failed to acquire my own lock! PANIC!\n",
ZR_DEVNAME(zr));
res = -ENODEV;
goto open_unlock_and_return;
}
if (!try_module_get(zr->decoder->driver->driver.owner)) { if (!try_module_get(zr->decoder->driver->driver.owner)) {
dprintk(1, dprintk(1,
KERN_ERR KERN_ERR
"%s: failed to grab ownership of i2c decoder\n", "%s: failed to grab ownership of video decoder\n",
ZR_DEVNAME(zr)); ZR_DEVNAME(zr));
res = -EIO; res = -EIO;
module_put(THIS_MODULE); goto fail_unlock;
goto open_unlock_and_return;
} }
if (zr->encoder && if (zr->encoder &&
!try_module_get(zr->encoder->driver->driver.owner)) { !try_module_get(zr->encoder->driver->driver.owner)) {
dprintk(1, dprintk(1,
KERN_ERR KERN_ERR
"%s: failed to grab ownership of i2c encoder\n", "%s: failed to grab ownership of video encoder\n",
ZR_DEVNAME(zr)); ZR_DEVNAME(zr));
res = -EIO; res = -EIO;
module_put(zr->decoder->driver->driver.owner); goto fail_decoder;
module_put(THIS_MODULE);
goto open_unlock_and_return;
}
have_module_locks = 1;
if (zr->user >= 2048) {
dprintk(1, KERN_ERR "%s: too many users (%d) on device\n",
ZR_DEVNAME(zr), zr->user);
res = -EBUSY;
goto open_unlock_and_return;
} }
dprintk(1, KERN_INFO "%s: zoran_open(%s, pid=[%d]), users(-)=%d\n",
ZR_DEVNAME(zr), current->comm, task_pid_nr(current), zr->user);
/* now, create the open()-specific file_ops struct */ /* now, create the open()-specific file_ops struct */
fh = kzalloc(sizeof(struct zoran_fh), GFP_KERNEL); fh = kzalloc(sizeof(struct zoran_fh), GFP_KERNEL);
if (!fh) { if (!fh) {
...@@ -1266,7 +1252,7 @@ static int zoran_open(struct file *file) ...@@ -1266,7 +1252,7 @@ static int zoran_open(struct file *file)
"%s: zoran_open() - allocation of zoran_fh failed\n", "%s: zoran_open() - allocation of zoran_fh failed\n",
ZR_DEVNAME(zr)); ZR_DEVNAME(zr));
res = -ENOMEM; res = -ENOMEM;
goto open_unlock_and_return; goto fail_encoder;
} }
/* used to be BUZ_MAX_WIDTH/HEIGHT, but that gives overflows /* used to be BUZ_MAX_WIDTH/HEIGHT, but that gives overflows
* on norm-change! */ * on norm-change! */
...@@ -1277,9 +1263,8 @@ static int zoran_open(struct file *file) ...@@ -1277,9 +1263,8 @@ static int zoran_open(struct file *file)
KERN_ERR KERN_ERR
"%s: zoran_open() - allocation of overlay_mask failed\n", "%s: zoran_open() - allocation of overlay_mask failed\n",
ZR_DEVNAME(zr)); ZR_DEVNAME(zr));
kfree(fh);
res = -ENOMEM; res = -ENOMEM;
goto open_unlock_and_return; goto fail_fh;
} }
if (zr->user++ == 0) if (zr->user++ == 0)
...@@ -1304,18 +1289,19 @@ static int zoran_open(struct file *file) ...@@ -1304,18 +1289,19 @@ static int zoran_open(struct file *file)
return 0; return 0;
open_unlock_and_return: fail_fh:
/* if we grabbed locks, release them accordingly */ kfree(fh);
if (have_module_locks) { fail_encoder:
module_put(zr->decoder->driver->driver.owner); if (zr->encoder)
if (zr->encoder) { module_put(zr->encoder->driver->driver.owner);
module_put(zr->encoder->driver->driver.owner); fail_decoder:
} module_put(zr->decoder->driver->driver.owner);
module_put(THIS_MODULE); fail_unlock:
}
unlock_kernel(); unlock_kernel();
dprintk(2, KERN_INFO "%s: open failed (%d), users(-)=%d\n",
ZR_DEVNAME(zr), res, zr->user);
return res; return res;
} }
...@@ -1325,8 +1311,8 @@ zoran_close(struct file *file) ...@@ -1325,8 +1311,8 @@ zoran_close(struct file *file)
struct zoran_fh *fh = file->private_data; struct zoran_fh *fh = file->private_data;
struct zoran *zr = fh->zr; struct zoran *zr = fh->zr;
dprintk(1, KERN_INFO "%s: zoran_close(%s, pid=[%d]), users(+)=%d\n", dprintk(2, KERN_INFO "%s: zoran_close(%s, pid=[%d]), users(+)=%d\n",
ZR_DEVNAME(zr), current->comm, task_pid_nr(current), zr->user); ZR_DEVNAME(zr), current->comm, task_pid_nr(current), zr->user - 1);
/* kernel locks (fs/device.c), so don't do that ourselves /* kernel locks (fs/device.c), so don't do that ourselves
* (prevents deadlocks) */ * (prevents deadlocks) */
...@@ -1372,10 +1358,8 @@ zoran_close(struct file *file) ...@@ -1372,10 +1358,8 @@ zoran_close(struct file *file)
/* release locks on the i2c modules */ /* release locks on the i2c modules */
module_put(zr->decoder->driver->driver.owner); module_put(zr->decoder->driver->driver.owner);
if (zr->encoder) { if (zr->encoder)
module_put(zr->encoder->driver->driver.owner); module_put(zr->encoder->driver->driver.owner);
}
module_put(THIS_MODULE);
/*mutex_unlock(&zr->resource_lock);*/ /*mutex_unlock(&zr->resource_lock);*/
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment