--- zzzz-none-000/linux-3.10.107/drivers/media/pci/zoran/zoran_driver.c 2017-06-27 09:49:32.000000000 +0000 +++ scorpion-7490-727/linux-3.10.107/drivers/media/pci/zoran/zoran_driver.c 2021-02-04 17:41:59.000000000 +0000 @@ -61,6 +61,7 @@ #include #include #include +#include #include "videocodec.h" #include @@ -592,10 +593,14 @@ return -EPROTO; } + mutex_unlock(&zr->lock); /* wait on this buffer to get ready */ if (!wait_event_interruptible_timeout(zr->v4l_capq, - (zr->v4l_buffers.buffer[frame].state != BUZ_STATE_PEND), 10*HZ)) + (zr->v4l_buffers.buffer[frame].state != BUZ_STATE_PEND), 10*HZ)) { + mutex_lock(&zr->lock); return -ETIME; + } + mutex_lock(&zr->lock); if (signal_pending(current)) return -ERESTARTSYS; @@ -783,6 +788,7 @@ ZR_DEVNAME(zr), __func__); return -EINVAL; } + mutex_unlock(&zr->lock); if (!wait_event_interruptible_timeout(zr->jpg_capq, (zr->jpg_que_tail != zr->jpg_dma_tail || zr->jpg_dma_tail == zr->jpg_dma_head), @@ -793,6 +799,7 @@ udelay(1); zr->codec->control(zr->codec, CODEC_G_STATUS, sizeof(isr), &isr); + mutex_lock(&zr->lock); dprintk(1, KERN_ERR "%s: %s - timeout: codec isr=0x%02x\n", @@ -801,6 +808,7 @@ return -ETIME; } + mutex_lock(&zr->lock); if (signal_pending(current)) return -ERESTARTSYS; @@ -911,7 +919,7 @@ dprintk(2, KERN_INFO "%s: %s(%s, pid=[%d]), users(-)=%d\n", ZR_DEVNAME(zr), __func__, current->comm, task_pid_nr(current), zr->user + 1); - mutex_lock(&zr->other_lock); + mutex_lock(&zr->lock); if (zr->user >= 2048) { dprintk(1, KERN_ERR "%s: too many users (%d) on device\n", @@ -930,6 +938,8 @@ res = -ENOMEM; goto fail_unlock; } + v4l2_fh_init(&fh->fh, video_devdata(file)); + /* used to be BUZ_MAX_WIDTH/HEIGHT, but that gives overflows * on norm-change! */ fh->overlay_mask = @@ -946,8 +956,6 @@ if (zr->user++ == 0) first_open = 1; - /*mutex_unlock(&zr->resource_lock);*/ - /* default setup - TODO: look at flags */ if (first_open) { /* First device open */ zr36057_restart(zr); @@ -961,14 +969,15 @@ file->private_data = fh; fh->zr = zr; zoran_open_init_session(fh); - mutex_unlock(&zr->other_lock); + v4l2_fh_add(&fh->fh); + mutex_unlock(&zr->lock); return 0; fail_fh: kfree(fh); fail_unlock: - mutex_unlock(&zr->other_lock); + mutex_unlock(&zr->lock); dprintk(2, KERN_INFO "%s: open failed (%d), users(-)=%d\n", ZR_DEVNAME(zr), res, zr->user); @@ -987,7 +996,7 @@ /* kernel locks (fs/device.c), so don't do that ourselves * (prevents deadlocks) */ - mutex_lock(&zr->other_lock); + mutex_lock(&zr->lock); zoran_close_end_session(fh); @@ -1021,9 +1030,10 @@ encoder_call(zr, video, s_routing, 2, 0, 0); } } - mutex_unlock(&zr->other_lock); + mutex_unlock(&zr->lock); - file->private_data = NULL; + v4l2_fh_del(&fh->fh); + v4l2_fh_exit(&fh->fh); kfree(fh->overlay_mask); kfree(fh); @@ -1032,29 +1042,6 @@ return 0; } - -static ssize_t -zoran_read (struct file *file, - char __user *data, - size_t count, - loff_t *ppos) -{ - /* we simply don't support read() (yet)... */ - - return -EINVAL; -} - -static ssize_t -zoran_write (struct file *file, - const char __user *data, - size_t count, - loff_t *ppos) -{ - /* ...and the same goes for write() */ - - return -EINVAL; -} - static int setup_fbuffer(struct zoran_fh *fh, void *base, const struct zoran_format *fmt, @@ -1456,29 +1443,6 @@ return -EINVAL; } - if (norm == V4L2_STD_ALL) { - unsigned int status = 0; - v4l2_std_id std = 0; - - decoder_call(zr, video, querystd, &std); - decoder_call(zr, core, s_std, std); - - /* let changes come into effect */ - ssleep(2); - - decoder_call(zr, video, g_input_status, &status); - if (status & V4L2_IN_ST_NO_SIGNAL) { - dprintk(1, - KERN_ERR - "%s: %s - no norm detected\n", - ZR_DEVNAME(zr), __func__); - /* reset norm */ - decoder_call(zr, core, s_std, zr->norm); - return -EIO; - } - - norm = std; - } if (norm & V4L2_STD_SECAM) zr->timing = zr->card.tvn[2]; else if (norm & V4L2_STD_NTSC) @@ -1492,7 +1456,7 @@ if (on) zr36057_overlay(zr, 0); - decoder_call(zr, core, s_std, norm); + decoder_call(zr, video, s_std, norm); encoder_call(zr, video, s_std_output, norm); if (on) @@ -1546,13 +1510,13 @@ struct zoran_fh *fh = __fh; struct zoran *zr = fh->zr; - memset(cap, 0, sizeof(*cap)); strncpy(cap->card, ZR_DEVNAME(zr), sizeof(cap->card)-1); strncpy(cap->driver, "zoran", sizeof(cap->driver)-1); snprintf(cap->bus_info, sizeof(cap->bus_info), "PCI:%s", pci_name(zr->pci_dev)); - cap->capabilities = V4L2_CAP_STREAMING | V4L2_CAP_VIDEO_CAPTURE | - V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_VIDEO_OVERLAY; + cap->device_caps = V4L2_CAP_STREAMING | V4L2_CAP_VIDEO_CAPTURE | + V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_VIDEO_OVERLAY; + cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS; return 0; } @@ -1605,9 +1569,6 @@ struct v4l2_format *fmt) { struct zoran_fh *fh = __fh; - struct zoran *zr = fh->zr; - - mutex_lock(&zr->resource_lock); fmt->fmt.pix.width = fh->jpg_settings.img_width / fh->jpg_settings.HorDcm; fmt->fmt.pix.height = fh->jpg_settings.img_height * 2 / @@ -1623,7 +1584,6 @@ fmt->fmt.pix.bytesperline = 0; fmt->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; - mutex_unlock(&zr->resource_lock); return 0; } @@ -1636,7 +1596,6 @@ if (fh->map_mode != ZORAN_MAP_MODE_RAW) return zoran_g_fmt_vid_out(file, fh, fmt); - mutex_lock(&zr->resource_lock); fmt->fmt.pix.width = fh->v4l_settings.width; fmt->fmt.pix.height = fh->v4l_settings.height; fmt->fmt.pix.sizeimage = fh->v4l_settings.bytesperline * @@ -1648,7 +1607,6 @@ fmt->fmt.pix.field = V4L2_FIELD_INTERLACED; else fmt->fmt.pix.field = V4L2_FIELD_TOP; - mutex_unlock(&zr->resource_lock); return 0; } @@ -1658,8 +1616,6 @@ struct zoran_fh *fh = __fh; struct zoran *zr = fh->zr; - mutex_lock(&zr->resource_lock); - fmt->fmt.win.w.left = fh->overlay_settings.x; fmt->fmt.win.w.top = fh->overlay_settings.y; fmt->fmt.win.w.width = fh->overlay_settings.width; @@ -1669,7 +1625,6 @@ else fmt->fmt.win.field = V4L2_FIELD_TOP; - mutex_unlock(&zr->resource_lock); return 0; } @@ -1679,8 +1634,6 @@ struct zoran_fh *fh = __fh; struct zoran *zr = fh->zr; - mutex_lock(&zr->resource_lock); - if (fmt->fmt.win.w.width > BUZ_MAX_WIDTH) fmt->fmt.win.w.width = BUZ_MAX_WIDTH; if (fmt->fmt.win.w.width < BUZ_MIN_WIDTH) @@ -1690,7 +1643,6 @@ if (fmt->fmt.win.w.height < BUZ_MIN_HEIGHT) fmt->fmt.win.w.height = BUZ_MIN_HEIGHT; - mutex_unlock(&zr->resource_lock); return 0; } @@ -1705,7 +1657,6 @@ if (fmt->fmt.pix.pixelformat != V4L2_PIX_FMT_MJPEG) return -EINVAL; - mutex_lock(&zr->resource_lock); settings = fh->jpg_settings; /* we actually need to set 'real' parameters now */ @@ -1740,7 +1691,7 @@ /* check */ res = zoran_check_jpg_settings(zr, &settings, 1); if (res) - goto tryfmt_unlock_and_return; + return res; /* tell the user what we actually did */ fmt->fmt.pix.width = settings.img_width / settings.HorDcm; @@ -1756,8 +1707,6 @@ fmt->fmt.pix.sizeimage = zoran_v4l2_calc_bufsize(&settings); fmt->fmt.pix.bytesperline = 0; fmt->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; -tryfmt_unlock_and_return: - mutex_unlock(&zr->resource_lock); return res; } @@ -1772,23 +1721,17 @@ if (fmt->fmt.pix.pixelformat == V4L2_PIX_FMT_MJPEG) return zoran_try_fmt_vid_out(file, fh, fmt); - mutex_lock(&zr->resource_lock); - for (i = 0; i < NUM_FORMATS; i++) if (zoran_formats[i].fourcc == fmt->fmt.pix.pixelformat) break; - if (i == NUM_FORMATS) { - mutex_unlock(&zr->resource_lock); + if (i == NUM_FORMATS) return -EINVAL; - } bpp = DIV_ROUND_UP(zoran_formats[i].depth, 8); v4l_bound_align_image( &fmt->fmt.pix.width, BUZ_MIN_WIDTH, BUZ_MAX_WIDTH, bpp == 2 ? 1 : 2, &fmt->fmt.pix.height, BUZ_MIN_HEIGHT, BUZ_MAX_HEIGHT, 0, 0); - mutex_unlock(&zr->resource_lock); - return 0; } @@ -1796,7 +1739,6 @@ struct v4l2_format *fmt) { struct zoran_fh *fh = __fh; - struct zoran *zr = fh->zr; int res; dprintk(3, "x=%d, y=%d, w=%d, h=%d, cnt=%d, map=0x%p\n", @@ -1805,12 +1747,10 @@ fmt->fmt.win.w.height, fmt->fmt.win.clipcount, fmt->fmt.win.bitmap); - mutex_lock(&zr->resource_lock); res = setup_window(fh, fmt->fmt.win.w.left, fmt->fmt.win.w.top, fmt->fmt.win.w.width, fmt->fmt.win.w.height, (struct v4l2_clip __user *)fmt->fmt.win.clips, fmt->fmt.win.clipcount, fmt->fmt.win.bitmap); - mutex_unlock(&zr->resource_lock); return res; } @@ -1830,13 +1770,11 @@ if (fmt->fmt.pix.pixelformat != V4L2_PIX_FMT_MJPEG) return -EINVAL; - mutex_lock(&zr->resource_lock); - if (fh->buffers.allocated) { dprintk(1, KERN_ERR "%s: VIDIOC_S_FMT - cannot change capture mode\n", ZR_DEVNAME(zr)); res = -EBUSY; - goto sfmtjpg_unlock_and_return; + return res; } settings = fh->jpg_settings; @@ -1873,7 +1811,7 @@ /* check */ res = zoran_check_jpg_settings(zr, &settings, 0); if (res) - goto sfmtjpg_unlock_and_return; + return res; /* it's ok, so set them */ fh->jpg_settings = settings; @@ -1894,9 +1832,6 @@ fmt->fmt.pix.bytesperline = 0; fmt->fmt.pix.sizeimage = fh->buffers.buffer_size; fmt->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; - -sfmtjpg_unlock_and_return: - mutex_unlock(&zr->resource_lock); return res; } @@ -1920,14 +1855,12 @@ return -EINVAL; } - mutex_lock(&zr->resource_lock); - if ((fh->map_mode != ZORAN_MAP_MODE_RAW && fh->buffers.allocated) || fh->buffers.active != ZORAN_FREE) { dprintk(1, KERN_ERR "%s: VIDIOC_S_FMT - cannot change capture mode\n", ZR_DEVNAME(zr)); res = -EBUSY; - goto sfmtv4l_unlock_and_return; + return res; } if (fmt->fmt.pix.height > BUZ_MAX_HEIGHT) fmt->fmt.pix.height = BUZ_MAX_HEIGHT; @@ -1939,7 +1872,7 @@ res = zoran_v4l_set_format(fh, fmt->fmt.pix.width, fmt->fmt.pix.height, &zoran_formats[i]); if (res) - goto sfmtv4l_unlock_and_return; + return res; /* tell the user the results/missing stuff */ fmt->fmt.pix.bytesperline = fh->v4l_settings.bytesperline; @@ -1949,9 +1882,6 @@ fmt->fmt.pix.field = V4L2_FIELD_INTERLACED; else fmt->fmt.pix.field = V4L2_FIELD_TOP; - -sfmtv4l_unlock_and_return: - mutex_unlock(&zr->resource_lock); return res; } @@ -1962,14 +1892,12 @@ struct zoran *zr = fh->zr; memset(fb, 0, sizeof(*fb)); - mutex_lock(&zr->resource_lock); fb->base = zr->vbuf_base; fb->fmt.width = zr->vbuf_width; fb->fmt.height = zr->vbuf_height; if (zr->overlay_settings.format) fb->fmt.pixelformat = fh->overlay_settings.format->fourcc; fb->fmt.bytesperline = zr->vbuf_bytesperline; - mutex_unlock(&zr->resource_lock); fb->fmt.colorspace = V4L2_COLORSPACE_SRGB; fb->fmt.field = V4L2_FIELD_INTERLACED; fb->capability = V4L2_FBUF_CAP_LIST_CLIPPING; @@ -1995,10 +1923,8 @@ return -EINVAL; } - mutex_lock(&zr->resource_lock); res = setup_fbuffer(fh, fb->base, &zoran_formats[i], fb->fmt.width, fb->fmt.height, fb->fmt.bytesperline); - mutex_unlock(&zr->resource_lock); return res; } @@ -2006,12 +1932,9 @@ static int zoran_overlay(struct file *file, void *__fh, unsigned int on) { struct zoran_fh *fh = __fh; - struct zoran *zr = fh->zr; int res; - mutex_lock(&zr->resource_lock); res = setup_overlay(fh, on); - mutex_unlock(&zr->resource_lock); return res; } @@ -2035,14 +1958,13 @@ if (req->count == 0) return zoran_streamoff(file, fh, req->type); - mutex_lock(&zr->resource_lock); if (fh->buffers.allocated) { dprintk(2, KERN_ERR "%s: VIDIOC_REQBUFS - buffers already allocated\n", ZR_DEVNAME(zr)); res = -EBUSY; - goto v4l2reqbuf_unlock_and_return; + return res; } if (fh->map_mode == ZORAN_MAP_MODE_RAW && @@ -2059,7 +1981,7 @@ if (v4l_fbuffer_alloc(fh)) { res = -ENOMEM; - goto v4l2reqbuf_unlock_and_return; + return res; } } else if (fh->map_mode == ZORAN_MAP_MODE_JPG_REC || fh->map_mode == ZORAN_MAP_MODE_JPG_PLAY) { @@ -2076,7 +1998,7 @@ if (jpg_fbuffer_alloc(fh)) { res = -ENOMEM; - goto v4l2reqbuf_unlock_and_return; + return res; } } else { dprintk(1, @@ -2084,23 +2006,17 @@ "%s: VIDIOC_REQBUFS - unknown type %d\n", ZR_DEVNAME(zr), req->type); res = -EINVAL; - goto v4l2reqbuf_unlock_and_return; + return res; } -v4l2reqbuf_unlock_and_return: - mutex_unlock(&zr->resource_lock); - return res; } static int zoran_querybuf(struct file *file, void *__fh, struct v4l2_buffer *buf) { struct zoran_fh *fh = __fh; - struct zoran *zr = fh->zr; int res; - mutex_lock(&zr->resource_lock); res = zoran_v4l2_buffer_status(fh, buf, buf->index); - mutex_unlock(&zr->resource_lock); return res; } @@ -2111,8 +2027,6 @@ struct zoran *zr = fh->zr; int res = 0, codec_mode, buf_type; - mutex_lock(&zr->resource_lock); - switch (fh->map_mode) { case ZORAN_MAP_MODE_RAW: if (buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) { @@ -2120,12 +2034,12 @@ "%s: VIDIOC_QBUF - invalid buf->type=%d for map_mode=%d\n", ZR_DEVNAME(zr), buf->type, fh->map_mode); res = -EINVAL; - goto qbuf_unlock_and_return; + return res; } res = zoran_v4l_queue_frame(fh, buf->index); if (res) - goto qbuf_unlock_and_return; + return res; if (!zr->v4l_memgrab_active && fh->buffers.active == ZORAN_LOCKED) zr36057_set_memgrab(zr, 1); break; @@ -2145,12 +2059,12 @@ "%s: VIDIOC_QBUF - invalid buf->type=%d for map_mode=%d\n", ZR_DEVNAME(zr), buf->type, fh->map_mode); res = -EINVAL; - goto qbuf_unlock_and_return; + return res; } res = zoran_jpg_queue_frame(fh, buf->index, codec_mode); if (res != 0) - goto qbuf_unlock_and_return; + return res; if (zr->codec_mode == BUZ_MODE_IDLE && fh->buffers.active == ZORAN_LOCKED) zr36057_enable_jpg(zr, codec_mode); @@ -2164,9 +2078,6 @@ res = -EINVAL; break; } -qbuf_unlock_and_return: - mutex_unlock(&zr->resource_lock); - return res; } @@ -2176,8 +2087,6 @@ struct zoran *zr = fh->zr; int res = 0, buf_type, num = -1; /* compiler borks here (?) */ - mutex_lock(&zr->resource_lock); - switch (fh->map_mode) { case ZORAN_MAP_MODE_RAW: if (buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) { @@ -2185,18 +2094,18 @@ "%s: VIDIOC_QBUF - invalid buf->type=%d for map_mode=%d\n", ZR_DEVNAME(zr), buf->type, fh->map_mode); res = -EINVAL; - goto dqbuf_unlock_and_return; + return res; } num = zr->v4l_pend[zr->v4l_sync_tail & V4L_MASK_FRAME]; if (file->f_flags & O_NONBLOCK && zr->v4l_buffers.buffer[num].state != BUZ_STATE_DONE) { res = -EAGAIN; - goto dqbuf_unlock_and_return; + return res; } res = v4l_sync(fh, num); if (res) - goto dqbuf_unlock_and_return; + return res; zr->v4l_sync_tail++; res = zoran_v4l2_buffer_status(fh, buf, num); break; @@ -2216,7 +2125,7 @@ "%s: VIDIOC_QBUF - invalid buf->type=%d for map_mode=%d\n", ZR_DEVNAME(zr), buf->type, fh->map_mode); res = -EINVAL; - goto dqbuf_unlock_and_return; + return res; } num = zr->jpg_pend[zr->jpg_que_tail & BUZ_MASK_FRAME]; @@ -2224,12 +2133,12 @@ if (file->f_flags & O_NONBLOCK && zr->jpg_buffers.buffer[num].state != BUZ_STATE_DONE) { res = -EAGAIN; - goto dqbuf_unlock_and_return; + return res; } bs.frame = 0; /* suppress compiler warning */ res = jpg_sync(fh, &bs); if (res) - goto dqbuf_unlock_and_return; + return res; res = zoran_v4l2_buffer_status(fh, buf, bs.frame); break; } @@ -2241,9 +2150,6 @@ res = -EINVAL; break; } -dqbuf_unlock_and_return: - mutex_unlock(&zr->resource_lock); - return res; } @@ -2253,14 +2159,12 @@ struct zoran *zr = fh->zr; int res = 0; - mutex_lock(&zr->resource_lock); - switch (fh->map_mode) { case ZORAN_MAP_MODE_RAW: /* raw capture */ if (zr->v4l_buffers.active != ZORAN_ACTIVE || fh->buffers.active != ZORAN_ACTIVE) { res = -EBUSY; - goto strmon_unlock_and_return; + return res; } zr->v4l_buffers.active = fh->buffers.active = ZORAN_LOCKED; @@ -2279,7 +2183,7 @@ if (zr->jpg_buffers.active != ZORAN_ACTIVE || fh->buffers.active != ZORAN_ACTIVE) { res = -EBUSY; - goto strmon_unlock_and_return; + return res; } zr->jpg_buffers.active = fh->buffers.active = ZORAN_LOCKED; @@ -2298,9 +2202,6 @@ res = -EINVAL; break; } -strmon_unlock_and_return: - mutex_unlock(&zr->resource_lock); - return res; } @@ -2311,17 +2212,15 @@ int i, res = 0; unsigned long flags; - mutex_lock(&zr->resource_lock); - switch (fh->map_mode) { case ZORAN_MAP_MODE_RAW: /* raw capture */ if (fh->buffers.active == ZORAN_FREE && zr->v4l_buffers.active != ZORAN_FREE) { res = -EPERM; /* stay off other's settings! */ - goto strmoff_unlock_and_return; + return res; } if (zr->v4l_buffers.active == ZORAN_FREE) - goto strmoff_unlock_and_return; + return res; spin_lock_irqsave(&zr->spinlock, flags); /* unload capture */ @@ -2349,17 +2248,17 @@ if (fh->buffers.active == ZORAN_FREE && zr->jpg_buffers.active != ZORAN_FREE) { res = -EPERM; /* stay off other's settings! */ - goto strmoff_unlock_and_return; + return res; } if (zr->jpg_buffers.active == ZORAN_FREE) - goto strmoff_unlock_and_return; + return res; res = jpg_qbuf(fh, -1, (fh->map_mode == ZORAN_MAP_MODE_JPG_REC) ? BUZ_MODE_MOTION_COMPRESS : BUZ_MODE_MOTION_DECOMPRESS); if (res) - goto strmoff_unlock_and_return; + return res; break; default: dprintk(1, KERN_ERR @@ -2368,70 +2267,14 @@ res = -EINVAL; break; } -strmoff_unlock_and_return: - mutex_unlock(&zr->resource_lock); - return res; } - -static int zoran_queryctrl(struct file *file, void *__fh, - struct v4l2_queryctrl *ctrl) -{ - struct zoran_fh *fh = __fh; - struct zoran *zr = fh->zr; - - /* we only support hue/saturation/contrast/brightness */ - if (ctrl->id < V4L2_CID_BRIGHTNESS || - ctrl->id > V4L2_CID_HUE) - return -EINVAL; - - decoder_call(zr, core, queryctrl, ctrl); - - return 0; -} - -static int zoran_g_ctrl(struct file *file, void *__fh, struct v4l2_control *ctrl) -{ - struct zoran_fh *fh = __fh; - struct zoran *zr = fh->zr; - - /* we only support hue/saturation/contrast/brightness */ - if (ctrl->id < V4L2_CID_BRIGHTNESS || - ctrl->id > V4L2_CID_HUE) - return -EINVAL; - - mutex_lock(&zr->resource_lock); - decoder_call(zr, core, g_ctrl, ctrl); - mutex_unlock(&zr->resource_lock); - - return 0; -} - -static int zoran_s_ctrl(struct file *file, void *__fh, struct v4l2_control *ctrl) -{ - struct zoran_fh *fh = __fh; - struct zoran *zr = fh->zr; - - /* we only support hue/saturation/contrast/brightness */ - if (ctrl->id < V4L2_CID_BRIGHTNESS || - ctrl->id > V4L2_CID_HUE) - return -EINVAL; - - mutex_lock(&zr->resource_lock); - decoder_call(zr, core, s_ctrl, ctrl); - mutex_unlock(&zr->resource_lock); - - return 0; -} - static int zoran_g_std(struct file *file, void *__fh, v4l2_std_id *std) { struct zoran_fh *fh = __fh; struct zoran *zr = fh->zr; - mutex_lock(&zr->resource_lock); *std = zr->norm; - mutex_unlock(&zr->resource_lock); return 0; } @@ -2441,14 +2284,11 @@ struct zoran *zr = fh->zr; int res = 0; - mutex_lock(&zr->resource_lock); res = zoran_set_norm(zr, std); if (res) - goto sstd_unlock_and_return; + return res; res = wait_grab_pending(zr); -sstd_unlock_and_return: - mutex_unlock(&zr->resource_lock); return res; } @@ -2467,9 +2307,7 @@ inp->std = V4L2_STD_ALL; /* Get status of video decoder */ - mutex_lock(&zr->resource_lock); decoder_call(zr, video, g_input_status, &inp->status); - mutex_unlock(&zr->resource_lock); return 0; } @@ -2478,9 +2316,7 @@ struct zoran_fh *fh = __fh; struct zoran *zr = fh->zr; - mutex_lock(&zr->resource_lock); *input = zr->input; - mutex_unlock(&zr->resource_lock); return 0; } @@ -2491,15 +2327,12 @@ struct zoran *zr = fh->zr; int res; - mutex_lock(&zr->resource_lock); res = zoran_set_input(zr, input); if (res) - goto sinput_unlock_and_return; + return res; /* Make sure the changes come into effect */ res = wait_grab_pending(zr); -sinput_unlock_and_return: - mutex_unlock(&zr->resource_lock); return res; } @@ -2542,8 +2375,6 @@ memset(cropcap, 0, sizeof(*cropcap)); cropcap->type = type; - mutex_lock(&zr->resource_lock); - if (cropcap->type != V4L2_BUF_TYPE_VIDEO_OUTPUT && (cropcap->type != V4L2_BUF_TYPE_VIDEO_CAPTURE || fh->map_mode == ZORAN_MAP_MODE_RAW)) { @@ -2551,7 +2382,7 @@ "%s: VIDIOC_CROPCAP - subcapture only supported for compressed capture\n", ZR_DEVNAME(zr)); res = -EINVAL; - goto cropcap_unlock_and_return; + return res; } cropcap->bounds.top = cropcap->bounds.left = 0; @@ -2560,8 +2391,6 @@ cropcap->defrect.top = cropcap->defrect.left = 0; cropcap->defrect.width = BUZ_MIN_WIDTH; cropcap->defrect.height = BUZ_MIN_HEIGHT; -cropcap_unlock_and_return: - mutex_unlock(&zr->resource_lock); return res; } @@ -2574,8 +2403,6 @@ memset(crop, 0, sizeof(*crop)); crop->type = type; - mutex_lock(&zr->resource_lock); - if (crop->type != V4L2_BUF_TYPE_VIDEO_OUTPUT && (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE || fh->map_mode == ZORAN_MAP_MODE_RAW)) { @@ -2584,17 +2411,13 @@ "%s: VIDIOC_G_CROP - subcapture only supported for compressed capture\n", ZR_DEVNAME(zr)); res = -EINVAL; - goto gcrop_unlock_and_return; + return res; } crop->c.top = fh->jpg_settings.img_y; crop->c.left = fh->jpg_settings.img_x; crop->c.width = fh->jpg_settings.img_width; crop->c.height = fh->jpg_settings.img_height; - -gcrop_unlock_and_return: - mutex_unlock(&zr->resource_lock); - return res; } @@ -2607,14 +2430,12 @@ settings = fh->jpg_settings; - mutex_lock(&zr->resource_lock); - if (fh->buffers.allocated) { dprintk(1, KERN_ERR "%s: VIDIOC_S_CROP - cannot change settings while active\n", ZR_DEVNAME(zr)); res = -EBUSY; - goto scrop_unlock_and_return; + return res; } if (crop->type != V4L2_BUF_TYPE_VIDEO_OUTPUT && @@ -2624,7 +2445,7 @@ "%s: VIDIOC_G_CROP - subcapture only supported for compressed capture\n", ZR_DEVNAME(zr)); res = -EINVAL; - goto scrop_unlock_and_return; + return res; } /* move into a form that we understand */ @@ -2636,13 +2457,10 @@ /* check validity */ res = zoran_check_jpg_settings(zr, &settings, 0); if (res) - goto scrop_unlock_and_return; + return res; /* accept */ fh->jpg_settings = settings; - -scrop_unlock_and_return: - mutex_unlock(&zr->resource_lock); return res; } @@ -2650,11 +2468,8 @@ struct v4l2_jpegcompression *params) { struct zoran_fh *fh = __fh; - struct zoran *zr = fh->zr; memset(params, 0, sizeof(*params)); - mutex_lock(&zr->resource_lock); - params->quality = fh->jpg_settings.jpg_comp.quality; params->APPn = fh->jpg_settings.jpg_comp.APPn; memcpy(params->APP_data, @@ -2668,8 +2483,6 @@ params->jpeg_markers = fh->jpg_settings.jpg_comp.jpeg_markers; - mutex_unlock(&zr->resource_lock); - return 0; } @@ -2685,26 +2498,21 @@ settings.jpg_comp = *params; - mutex_lock(&zr->resource_lock); - if (fh->buffers.active != ZORAN_FREE) { dprintk(1, KERN_WARNING "%s: VIDIOC_S_JPEGCOMP called while in playback/capture mode\n", ZR_DEVNAME(zr)); res = -EBUSY; - goto sjpegc_unlock_and_return; + return res; } res = zoran_check_jpg_settings(zr, &settings, 0); if (res) - goto sjpegc_unlock_and_return; + return res; if (!fh->buffers.allocated) fh->buffers.buffer_size = zoran_v4l2_calc_bufsize(&fh->jpg_settings); fh->jpg_settings.jpg_comp = settings.jpg_comp; -sjpegc_unlock_and_return: - mutex_unlock(&zr->resource_lock); - return res; } @@ -2714,7 +2522,8 @@ { struct zoran_fh *fh = file->private_data; struct zoran *zr = fh->zr; - int res = 0, frame; + int res = v4l2_ctrl_poll(file, wait); + int frame; unsigned long flags; /* we should check whether buffers are ready to be synced on @@ -2725,8 +2534,6 @@ * if no buffers queued or so, return POLLNVAL */ - mutex_lock(&zr->resource_lock); - switch (fh->map_mode) { case ZORAN_MAP_MODE_RAW: poll_wait(file, &zr->v4l_capq, wait); @@ -2744,7 +2551,7 @@ if (fh->buffers.active != ZORAN_FREE && /* Buffer ready to DQBUF? */ zr->v4l_buffers.buffer[frame].state == BUZ_STATE_DONE) - res = POLLIN | POLLRDNORM; + res |= POLLIN | POLLRDNORM; spin_unlock_irqrestore(&zr->spinlock, flags); break; @@ -2765,9 +2572,9 @@ if (fh->buffers.active != ZORAN_FREE && zr->jpg_buffers.buffer[frame].state == BUZ_STATE_DONE) { if (fh->map_mode == ZORAN_MAP_MODE_JPG_REC) - res = POLLIN | POLLRDNORM; + res |= POLLIN | POLLRDNORM; else - res = POLLOUT | POLLWRNORM; + res |= POLLOUT | POLLWRNORM; } spin_unlock_irqrestore(&zr->spinlock, flags); @@ -2778,11 +2585,9 @@ KERN_ERR "%s: %s - internal error, unknown map_mode=%d\n", ZR_DEVNAME(zr), __func__, fh->map_mode); - res = POLLNVAL; + res |= POLLERR; } - mutex_unlock(&zr->resource_lock); - return res; } @@ -2814,9 +2619,6 @@ struct zoran *zr = fh->zr; int i; - if (!atomic_dec_and_mutex_lock(&map->count, &zr->resource_lock)) - return; - dprintk(3, KERN_INFO "%s: %s - munmap(%s)\n", ZR_DEVNAME(zr), __func__, mode_name(fh->map_mode)); @@ -2829,7 +2631,6 @@ /* Any buffers still mapped? */ for (i = 0; i < fh->buffers.num_buffers; i++) { if (fh->buffers.buffer[i].map) { - mutex_unlock(&zr->resource_lock); return; } } @@ -2837,7 +2638,6 @@ dprintk(3, KERN_INFO "%s: %s - free %s buffers\n", ZR_DEVNAME(zr), __func__, mode_name(fh->map_mode)); - if (fh->map_mode == ZORAN_MAP_MODE_RAW) { if (fh->buffers.active != ZORAN_FREE) { unsigned long flags; @@ -2857,8 +2657,6 @@ } jpg_fbuffer_free(fh); } - - mutex_unlock(&zr->resource_lock); } static const struct vm_operations_struct zoran_vm_ops = { @@ -2894,15 +2692,13 @@ return -EINVAL; } - mutex_lock(&zr->resource_lock); - if (!fh->buffers.allocated) { dprintk(1, KERN_ERR "%s: %s(%s) - buffers not yet allocated\n", ZR_DEVNAME(zr), __func__, mode_name(fh->map_mode)); res = -ENOMEM; - goto mmap_unlock_and_return; + return res; } first = offset / fh->buffers.buffer_size; @@ -2918,7 +2714,7 @@ fh->buffers.buffer_size, fh->buffers.num_buffers); res = -EINVAL; - goto mmap_unlock_and_return; + return res; } /* Check if any buffers are already mapped */ @@ -2929,7 +2725,7 @@ "%s: %s(%s) - buffer %d already mapped\n", ZR_DEVNAME(zr), __func__, mode_name(fh->map_mode), i); res = -EBUSY; - goto mmap_unlock_and_return; + return res; } } @@ -2937,7 +2733,7 @@ map = kmalloc(sizeof(struct zoran_mapping), GFP_KERNEL); if (!map) { res = -ENOMEM; - goto mmap_unlock_and_return; + return res; } map->fh = fh; atomic_set(&map->count, 1); @@ -2959,7 +2755,7 @@ "%s: %s(V4L) - remap_pfn_range failed\n", ZR_DEVNAME(zr), __func__); res = -EAGAIN; - goto mmap_unlock_and_return; + return res; } size -= todo; start += todo; @@ -2991,7 +2787,7 @@ "%s: %s(V4L) - remap_pfn_range failed\n", ZR_DEVNAME(zr), __func__); res = -EAGAIN; - goto mmap_unlock_and_return; + return res; } size -= todo; start += todo; @@ -3007,10 +2803,6 @@ } } - -mmap_unlock_and_return: - mutex_unlock(&zr->resource_lock); - return res; } @@ -3050,33 +2842,15 @@ .vidioc_try_fmt_vid_cap = zoran_try_fmt_vid_cap, .vidioc_try_fmt_vid_out = zoran_try_fmt_vid_out, .vidioc_try_fmt_vid_overlay = zoran_try_fmt_vid_overlay, - .vidioc_queryctrl = zoran_queryctrl, - .vidioc_s_ctrl = zoran_s_ctrl, - .vidioc_g_ctrl = zoran_g_ctrl, + .vidioc_subscribe_event = v4l2_ctrl_subscribe_event, + .vidioc_unsubscribe_event = v4l2_event_unsubscribe, }; -/* please use zr->resource_lock consistently and kill this wrapper */ -static long zoran_ioctl(struct file *file, unsigned int cmd, - unsigned long arg) -{ - struct zoran_fh *fh = file->private_data; - struct zoran *zr = fh->zr; - int ret; - - mutex_lock(&zr->other_lock); - ret = video_ioctl2(file, cmd, arg); - mutex_unlock(&zr->other_lock); - - return ret; -} - static const struct v4l2_file_operations zoran_fops = { .owner = THIS_MODULE, .open = zoran_open, .release = zoran_close, - .unlocked_ioctl = zoran_ioctl, - .read = zoran_read, - .write = zoran_write, + .unlocked_ioctl = video_ioctl2, .mmap = zoran_mmap, .poll = zoran_poll, };