diff options
Diffstat (limited to 'drivers/media/video/bt8xx/bttv-driver.c')
-rw-r--r-- | drivers/media/video/bt8xx/bttv-driver.c | 117 |
1 files changed, 3 insertions, 114 deletions
diff --git a/drivers/media/video/bt8xx/bttv-driver.c b/drivers/media/video/bt8xx/bttv-driver.c index a529619e51f6..0902ec041c7a 100644 --- a/drivers/media/video/bt8xx/bttv-driver.c +++ b/drivers/media/video/bt8xx/bttv-driver.c | |||
@@ -854,7 +854,6 @@ int check_alloc_btres_lock(struct bttv *btv, struct bttv_fh *fh, int bit) | |||
854 | xbits |= RESOURCE_VIDEO_READ | RESOURCE_VIDEO_STREAM; | 854 | xbits |= RESOURCE_VIDEO_READ | RESOURCE_VIDEO_STREAM; |
855 | 855 | ||
856 | /* is it free? */ | 856 | /* is it free? */ |
857 | mutex_lock(&btv->lock); | ||
858 | if (btv->resources & xbits) { | 857 | if (btv->resources & xbits) { |
859 | /* no, someone else uses it */ | 858 | /* no, someone else uses it */ |
860 | goto fail; | 859 | goto fail; |
@@ -884,11 +883,9 @@ int check_alloc_btres_lock(struct bttv *btv, struct bttv_fh *fh, int bit) | |||
884 | /* it's free, grab it */ | 883 | /* it's free, grab it */ |
885 | fh->resources |= bit; | 884 | fh->resources |= bit; |
886 | btv->resources |= bit; | 885 | btv->resources |= bit; |
887 | mutex_unlock(&btv->lock); | ||
888 | return 1; | 886 | return 1; |
889 | 887 | ||
890 | fail: | 888 | fail: |
891 | mutex_unlock(&btv->lock); | ||
892 | return 0; | 889 | return 0; |
893 | } | 890 | } |
894 | 891 | ||
@@ -940,7 +937,6 @@ void free_btres_lock(struct bttv *btv, struct bttv_fh *fh, int bits) | |||
940 | /* trying to free ressources not allocated by us ... */ | 937 | /* trying to free ressources not allocated by us ... */ |
941 | printk("bttv: BUG! (btres)\n"); | 938 | printk("bttv: BUG! (btres)\n"); |
942 | } | 939 | } |
943 | mutex_lock(&btv->lock); | ||
944 | fh->resources &= ~bits; | 940 | fh->resources &= ~bits; |
945 | btv->resources &= ~bits; | 941 | btv->resources &= ~bits; |
946 | 942 | ||
@@ -951,8 +947,6 @@ void free_btres_lock(struct bttv *btv, struct bttv_fh *fh, int bits) | |||
951 | 947 | ||
952 | if (0 == (bits & VBI_RESOURCES)) | 948 | if (0 == (bits & VBI_RESOURCES)) |
953 | disclaim_vbi_lines(btv); | 949 | disclaim_vbi_lines(btv); |
954 | |||
955 | mutex_unlock(&btv->lock); | ||
956 | } | 950 | } |
957 | 951 | ||
958 | /* ----------------------------------------------------------------------- */ | 952 | /* ----------------------------------------------------------------------- */ |
@@ -1713,28 +1707,20 @@ static int bttv_prepare_buffer(struct videobuf_queue *q,struct bttv *btv, | |||
1713 | 1707 | ||
1714 | /* Make sure tvnorm and vbi_end remain consistent | 1708 | /* Make sure tvnorm and vbi_end remain consistent |
1715 | until we're done. */ | 1709 | until we're done. */ |
1716 | mutex_lock(&btv->lock); | ||
1717 | 1710 | ||
1718 | norm = btv->tvnorm; | 1711 | norm = btv->tvnorm; |
1719 | 1712 | ||
1720 | /* In this mode capturing always starts at defrect.top | 1713 | /* In this mode capturing always starts at defrect.top |
1721 | (default VDELAY), ignoring cropping parameters. */ | 1714 | (default VDELAY), ignoring cropping parameters. */ |
1722 | if (btv->vbi_end > bttv_tvnorms[norm].cropcap.defrect.top) { | 1715 | if (btv->vbi_end > bttv_tvnorms[norm].cropcap.defrect.top) { |
1723 | mutex_unlock(&btv->lock); | ||
1724 | return -EINVAL; | 1716 | return -EINVAL; |
1725 | } | 1717 | } |
1726 | 1718 | ||
1727 | mutex_unlock(&btv->lock); | ||
1728 | |||
1729 | c.rect = bttv_tvnorms[norm].cropcap.defrect; | 1719 | c.rect = bttv_tvnorms[norm].cropcap.defrect; |
1730 | } else { | 1720 | } else { |
1731 | mutex_lock(&btv->lock); | ||
1732 | |||
1733 | norm = btv->tvnorm; | 1721 | norm = btv->tvnorm; |
1734 | c = btv->crop[!!fh->do_crop]; | 1722 | c = btv->crop[!!fh->do_crop]; |
1735 | 1723 | ||
1736 | mutex_unlock(&btv->lock); | ||
1737 | |||
1738 | if (width < c.min_scaled_width || | 1724 | if (width < c.min_scaled_width || |
1739 | width > c.max_scaled_width || | 1725 | width > c.max_scaled_width || |
1740 | height < c.min_scaled_height) | 1726 | height < c.min_scaled_height) |
@@ -1858,7 +1844,6 @@ static int bttv_s_std(struct file *file, void *priv, v4l2_std_id *id) | |||
1858 | unsigned int i; | 1844 | unsigned int i; |
1859 | int err; | 1845 | int err; |
1860 | 1846 | ||
1861 | mutex_lock(&btv->lock); | ||
1862 | err = v4l2_prio_check(&btv->prio, fh->prio); | 1847 | err = v4l2_prio_check(&btv->prio, fh->prio); |
1863 | if (err) | 1848 | if (err) |
1864 | goto err; | 1849 | goto err; |
@@ -1874,7 +1859,6 @@ static int bttv_s_std(struct file *file, void *priv, v4l2_std_id *id) | |||
1874 | set_tvnorm(btv, i); | 1859 | set_tvnorm(btv, i); |
1875 | 1860 | ||
1876 | err: | 1861 | err: |
1877 | mutex_unlock(&btv->lock); | ||
1878 | 1862 | ||
1879 | return err; | 1863 | return err; |
1880 | } | 1864 | } |
@@ -1898,7 +1882,6 @@ static int bttv_enum_input(struct file *file, void *priv, | |||
1898 | struct bttv *btv = fh->btv; | 1882 | struct bttv *btv = fh->btv; |
1899 | int rc = 0; | 1883 | int rc = 0; |
1900 | 1884 | ||
1901 | mutex_lock(&btv->lock); | ||
1902 | if (i->index >= bttv_tvcards[btv->c.type].video_inputs) { | 1885 | if (i->index >= bttv_tvcards[btv->c.type].video_inputs) { |
1903 | rc = -EINVAL; | 1886 | rc = -EINVAL; |
1904 | goto err; | 1887 | goto err; |
@@ -1928,7 +1911,6 @@ static int bttv_enum_input(struct file *file, void *priv, | |||
1928 | i->std = BTTV_NORMS; | 1911 | i->std = BTTV_NORMS; |
1929 | 1912 | ||
1930 | err: | 1913 | err: |
1931 | mutex_unlock(&btv->lock); | ||
1932 | 1914 | ||
1933 | return rc; | 1915 | return rc; |
1934 | } | 1916 | } |
@@ -1938,9 +1920,7 @@ static int bttv_g_input(struct file *file, void *priv, unsigned int *i) | |||
1938 | struct bttv_fh *fh = priv; | 1920 | struct bttv_fh *fh = priv; |
1939 | struct bttv *btv = fh->btv; | 1921 | struct bttv *btv = fh->btv; |
1940 | 1922 | ||
1941 | mutex_lock(&btv->lock); | ||
1942 | *i = btv->input; | 1923 | *i = btv->input; |
1943 | mutex_unlock(&btv->lock); | ||
1944 | 1924 | ||
1945 | return 0; | 1925 | return 0; |
1946 | } | 1926 | } |
@@ -1952,7 +1932,6 @@ static int bttv_s_input(struct file *file, void *priv, unsigned int i) | |||
1952 | 1932 | ||
1953 | int err; | 1933 | int err; |
1954 | 1934 | ||
1955 | mutex_lock(&btv->lock); | ||
1956 | err = v4l2_prio_check(&btv->prio, fh->prio); | 1935 | err = v4l2_prio_check(&btv->prio, fh->prio); |
1957 | if (unlikely(err)) | 1936 | if (unlikely(err)) |
1958 | goto err; | 1937 | goto err; |
@@ -1965,7 +1944,6 @@ static int bttv_s_input(struct file *file, void *priv, unsigned int i) | |||
1965 | set_input(btv, i, btv->tvnorm); | 1944 | set_input(btv, i, btv->tvnorm); |
1966 | 1945 | ||
1967 | err: | 1946 | err: |
1968 | mutex_unlock(&btv->lock); | ||
1969 | return 0; | 1947 | return 0; |
1970 | } | 1948 | } |
1971 | 1949 | ||
@@ -1979,7 +1957,6 @@ static int bttv_s_tuner(struct file *file, void *priv, | |||
1979 | if (unlikely(0 != t->index)) | 1957 | if (unlikely(0 != t->index)) |
1980 | return -EINVAL; | 1958 | return -EINVAL; |
1981 | 1959 | ||
1982 | mutex_lock(&btv->lock); | ||
1983 | if (unlikely(btv->tuner_type == TUNER_ABSENT)) { | 1960 | if (unlikely(btv->tuner_type == TUNER_ABSENT)) { |
1984 | err = -EINVAL; | 1961 | err = -EINVAL; |
1985 | goto err; | 1962 | goto err; |
@@ -1995,7 +1972,6 @@ static int bttv_s_tuner(struct file *file, void *priv, | |||
1995 | btv->audio_mode_gpio(btv, t, 1); | 1972 | btv->audio_mode_gpio(btv, t, 1); |
1996 | 1973 | ||
1997 | err: | 1974 | err: |
1998 | mutex_unlock(&btv->lock); | ||
1999 | 1975 | ||
2000 | return 0; | 1976 | return 0; |
2001 | } | 1977 | } |
@@ -2006,10 +1982,8 @@ static int bttv_g_frequency(struct file *file, void *priv, | |||
2006 | struct bttv_fh *fh = priv; | 1982 | struct bttv_fh *fh = priv; |
2007 | struct bttv *btv = fh->btv; | 1983 | struct bttv *btv = fh->btv; |
2008 | 1984 | ||
2009 | mutex_lock(&btv->lock); | ||
2010 | f->type = btv->radio_user ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; | 1985 | f->type = btv->radio_user ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; |
2011 | f->frequency = btv->freq; | 1986 | f->frequency = btv->freq; |
2012 | mutex_unlock(&btv->lock); | ||
2013 | 1987 | ||
2014 | return 0; | 1988 | return 0; |
2015 | } | 1989 | } |
@@ -2024,7 +1998,6 @@ static int bttv_s_frequency(struct file *file, void *priv, | |||
2024 | if (unlikely(f->tuner != 0)) | 1998 | if (unlikely(f->tuner != 0)) |
2025 | return -EINVAL; | 1999 | return -EINVAL; |
2026 | 2000 | ||
2027 | mutex_lock(&btv->lock); | ||
2028 | err = v4l2_prio_check(&btv->prio, fh->prio); | 2001 | err = v4l2_prio_check(&btv->prio, fh->prio); |
2029 | if (unlikely(err)) | 2002 | if (unlikely(err)) |
2030 | goto err; | 2003 | goto err; |
@@ -2039,7 +2012,6 @@ static int bttv_s_frequency(struct file *file, void *priv, | |||
2039 | if (btv->has_matchbox && btv->radio_user) | 2012 | if (btv->has_matchbox && btv->radio_user) |
2040 | tea5757_set_freq(btv, btv->freq); | 2013 | tea5757_set_freq(btv, btv->freq); |
2041 | err: | 2014 | err: |
2042 | mutex_unlock(&btv->lock); | ||
2043 | 2015 | ||
2044 | return 0; | 2016 | return 0; |
2045 | } | 2017 | } |
@@ -2172,7 +2144,6 @@ limit_scaled_size_lock (struct bttv_fh * fh, | |||
2172 | 2144 | ||
2173 | /* Make sure tvnorm, vbi_end and the current cropping parameters | 2145 | /* Make sure tvnorm, vbi_end and the current cropping parameters |
2174 | remain consistent until we're done. */ | 2146 | remain consistent until we're done. */ |
2175 | mutex_lock(&btv->lock); | ||
2176 | 2147 | ||
2177 | b = &bttv_tvnorms[btv->tvnorm].cropcap.bounds; | 2148 | b = &bttv_tvnorms[btv->tvnorm].cropcap.bounds; |
2178 | 2149 | ||
@@ -2250,7 +2221,6 @@ limit_scaled_size_lock (struct bttv_fh * fh, | |||
2250 | rc = 0; /* success */ | 2221 | rc = 0; /* success */ |
2251 | 2222 | ||
2252 | fail: | 2223 | fail: |
2253 | mutex_unlock(&btv->lock); | ||
2254 | 2224 | ||
2255 | return rc; | 2225 | return rc; |
2256 | } | 2226 | } |
@@ -2282,9 +2252,7 @@ verify_window_lock (struct bttv_fh * fh, | |||
2282 | if (V4L2_FIELD_ANY == field) { | 2252 | if (V4L2_FIELD_ANY == field) { |
2283 | __s32 height2; | 2253 | __s32 height2; |
2284 | 2254 | ||
2285 | mutex_lock(&fh->btv->lock); | ||
2286 | height2 = fh->btv->crop[!!fh->do_crop].rect.height >> 1; | 2255 | height2 = fh->btv->crop[!!fh->do_crop].rect.height >> 1; |
2287 | mutex_unlock(&fh->btv->lock); | ||
2288 | field = (win->w.height > height2) | 2256 | field = (win->w.height > height2) |
2289 | ? V4L2_FIELD_INTERLACED | 2257 | ? V4L2_FIELD_INTERLACED |
2290 | : V4L2_FIELD_TOP; | 2258 | : V4L2_FIELD_TOP; |
@@ -2360,7 +2328,6 @@ static int setup_window_lock(struct bttv_fh *fh, struct bttv *btv, | |||
2360 | } | 2328 | } |
2361 | } | 2329 | } |
2362 | 2330 | ||
2363 | mutex_lock(&fh->cap.vb_lock); | ||
2364 | /* clip against screen */ | 2331 | /* clip against screen */ |
2365 | if (NULL != btv->fbuf.base) | 2332 | if (NULL != btv->fbuf.base) |
2366 | n = btcx_screen_clips(btv->fbuf.fmt.width, btv->fbuf.fmt.height, | 2333 | n = btcx_screen_clips(btv->fbuf.fmt.width, btv->fbuf.fmt.height, |
@@ -2391,13 +2358,6 @@ static int setup_window_lock(struct bttv_fh *fh, struct bttv *btv, | |||
2391 | fh->ov.field = win->field; | 2358 | fh->ov.field = win->field; |
2392 | fh->ov.setup_ok = 1; | 2359 | fh->ov.setup_ok = 1; |
2393 | 2360 | ||
2394 | /* | ||
2395 | * FIXME: btv is protected by btv->lock mutex, while btv->init | ||
2396 | * is protected by fh->cap.vb_lock. This seems to open the | ||
2397 | * possibility for some race situations. Maybe the better would | ||
2398 | * be to unify those locks or to use another way to store the | ||
2399 | * init values that will be consumed by videobuf callbacks | ||
2400 | */ | ||
2401 | btv->init.ov.w.width = win->w.width; | 2361 | btv->init.ov.w.width = win->w.width; |
2402 | btv->init.ov.w.height = win->w.height; | 2362 | btv->init.ov.w.height = win->w.height; |
2403 | btv->init.ov.field = win->field; | 2363 | btv->init.ov.field = win->field; |
@@ -2412,7 +2372,6 @@ static int setup_window_lock(struct bttv_fh *fh, struct bttv *btv, | |||
2412 | bttv_overlay_risc(btv, &fh->ov, fh->ovfmt, new); | 2372 | bttv_overlay_risc(btv, &fh->ov, fh->ovfmt, new); |
2413 | retval = bttv_switch_overlay(btv,fh,new); | 2373 | retval = bttv_switch_overlay(btv,fh,new); |
2414 | } | 2374 | } |
2415 | mutex_unlock(&fh->cap.vb_lock); | ||
2416 | return retval; | 2375 | return retval; |
2417 | } | 2376 | } |
2418 | 2377 | ||
@@ -2526,9 +2485,7 @@ static int bttv_try_fmt_vid_cap(struct file *file, void *priv, | |||
2526 | if (V4L2_FIELD_ANY == field) { | 2485 | if (V4L2_FIELD_ANY == field) { |
2527 | __s32 height2; | 2486 | __s32 height2; |
2528 | 2487 | ||
2529 | mutex_lock(&btv->lock); | ||
2530 | height2 = btv->crop[!!fh->do_crop].rect.height >> 1; | 2488 | height2 = btv->crop[!!fh->do_crop].rect.height >> 1; |
2531 | mutex_unlock(&btv->lock); | ||
2532 | field = (f->fmt.pix.height > height2) | 2489 | field = (f->fmt.pix.height > height2) |
2533 | ? V4L2_FIELD_INTERLACED | 2490 | ? V4L2_FIELD_INTERLACED |
2534 | : V4L2_FIELD_BOTTOM; | 2491 | : V4L2_FIELD_BOTTOM; |
@@ -2614,7 +2571,6 @@ static int bttv_s_fmt_vid_cap(struct file *file, void *priv, | |||
2614 | fmt = format_by_fourcc(f->fmt.pix.pixelformat); | 2571 | fmt = format_by_fourcc(f->fmt.pix.pixelformat); |
2615 | 2572 | ||
2616 | /* update our state informations */ | 2573 | /* update our state informations */ |
2617 | mutex_lock(&fh->cap.vb_lock); | ||
2618 | fh->fmt = fmt; | 2574 | fh->fmt = fmt; |
2619 | fh->cap.field = f->fmt.pix.field; | 2575 | fh->cap.field = f->fmt.pix.field; |
2620 | fh->cap.last = V4L2_FIELD_NONE; | 2576 | fh->cap.last = V4L2_FIELD_NONE; |
@@ -2623,7 +2579,6 @@ static int bttv_s_fmt_vid_cap(struct file *file, void *priv, | |||
2623 | btv->init.fmt = fmt; | 2579 | btv->init.fmt = fmt; |
2624 | btv->init.width = f->fmt.pix.width; | 2580 | btv->init.width = f->fmt.pix.width; |
2625 | btv->init.height = f->fmt.pix.height; | 2581 | btv->init.height = f->fmt.pix.height; |
2626 | mutex_unlock(&fh->cap.vb_lock); | ||
2627 | 2582 | ||
2628 | return 0; | 2583 | return 0; |
2629 | } | 2584 | } |
@@ -2649,11 +2604,9 @@ static int vidiocgmbuf(struct file *file, void *priv, struct video_mbuf *mbuf) | |||
2649 | unsigned int i; | 2604 | unsigned int i; |
2650 | struct bttv_fh *fh = priv; | 2605 | struct bttv_fh *fh = priv; |
2651 | 2606 | ||
2652 | mutex_lock(&fh->cap.vb_lock); | ||
2653 | retval = __videobuf_mmap_setup(&fh->cap, gbuffers, gbufsize, | 2607 | retval = __videobuf_mmap_setup(&fh->cap, gbuffers, gbufsize, |
2654 | V4L2_MEMORY_MMAP); | 2608 | V4L2_MEMORY_MMAP); |
2655 | if (retval < 0) { | 2609 | if (retval < 0) { |
2656 | mutex_unlock(&fh->cap.vb_lock); | ||
2657 | return retval; | 2610 | return retval; |
2658 | } | 2611 | } |
2659 | 2612 | ||
@@ -2665,7 +2618,6 @@ static int vidiocgmbuf(struct file *file, void *priv, struct video_mbuf *mbuf) | |||
2665 | for (i = 0; i < gbuffers; i++) | 2618 | for (i = 0; i < gbuffers; i++) |
2666 | mbuf->offsets[i] = i * gbufsize; | 2619 | mbuf->offsets[i] = i * gbufsize; |
2667 | 2620 | ||
2668 | mutex_unlock(&fh->cap.vb_lock); | ||
2669 | return 0; | 2621 | return 0; |
2670 | } | 2622 | } |
2671 | #endif | 2623 | #endif |
@@ -2775,10 +2727,8 @@ static int bttv_overlay(struct file *file, void *f, unsigned int on) | |||
2775 | int retval = 0; | 2727 | int retval = 0; |
2776 | 2728 | ||
2777 | if (on) { | 2729 | if (on) { |
2778 | mutex_lock(&fh->cap.vb_lock); | ||
2779 | /* verify args */ | 2730 | /* verify args */ |
2780 | if (unlikely(!btv->fbuf.base)) { | 2731 | if (unlikely(!btv->fbuf.base)) { |
2781 | mutex_unlock(&fh->cap.vb_lock); | ||
2782 | return -EINVAL; | 2732 | return -EINVAL; |
2783 | } | 2733 | } |
2784 | if (unlikely(!fh->ov.setup_ok)) { | 2734 | if (unlikely(!fh->ov.setup_ok)) { |
@@ -2787,13 +2737,11 @@ static int bttv_overlay(struct file *file, void *f, unsigned int on) | |||
2787 | } | 2737 | } |
2788 | if (retval) | 2738 | if (retval) |
2789 | return retval; | 2739 | return retval; |
2790 | mutex_unlock(&fh->cap.vb_lock); | ||
2791 | } | 2740 | } |
2792 | 2741 | ||
2793 | if (!check_alloc_btres_lock(btv, fh, RESOURCE_OVERLAY)) | 2742 | if (!check_alloc_btres_lock(btv, fh, RESOURCE_OVERLAY)) |
2794 | return -EBUSY; | 2743 | return -EBUSY; |
2795 | 2744 | ||
2796 | mutex_lock(&fh->cap.vb_lock); | ||
2797 | if (on) { | 2745 | if (on) { |
2798 | fh->ov.tvnorm = btv->tvnorm; | 2746 | fh->ov.tvnorm = btv->tvnorm; |
2799 | new = videobuf_sg_alloc(sizeof(*new)); | 2747 | new = videobuf_sg_alloc(sizeof(*new)); |
@@ -2805,7 +2753,6 @@ static int bttv_overlay(struct file *file, void *f, unsigned int on) | |||
2805 | 2753 | ||
2806 | /* switch over */ | 2754 | /* switch over */ |
2807 | retval = bttv_switch_overlay(btv, fh, new); | 2755 | retval = bttv_switch_overlay(btv, fh, new); |
2808 | mutex_unlock(&fh->cap.vb_lock); | ||
2809 | return retval; | 2756 | return retval; |
2810 | } | 2757 | } |
2811 | 2758 | ||
@@ -2844,7 +2791,6 @@ static int bttv_s_fbuf(struct file *file, void *f, | |||
2844 | } | 2791 | } |
2845 | 2792 | ||
2846 | /* ok, accept it */ | 2793 | /* ok, accept it */ |
2847 | mutex_lock(&fh->cap.vb_lock); | ||
2848 | btv->fbuf.base = fb->base; | 2794 | btv->fbuf.base = fb->base; |
2849 | btv->fbuf.fmt.width = fb->fmt.width; | 2795 | btv->fbuf.fmt.width = fb->fmt.width; |
2850 | btv->fbuf.fmt.height = fb->fmt.height; | 2796 | btv->fbuf.fmt.height = fb->fmt.height; |
@@ -2876,7 +2822,6 @@ static int bttv_s_fbuf(struct file *file, void *f, | |||
2876 | retval = bttv_switch_overlay(btv, fh, new); | 2822 | retval = bttv_switch_overlay(btv, fh, new); |
2877 | } | 2823 | } |
2878 | } | 2824 | } |
2879 | mutex_unlock(&fh->cap.vb_lock); | ||
2880 | return retval; | 2825 | return retval; |
2881 | } | 2826 | } |
2882 | 2827 | ||
@@ -2955,7 +2900,6 @@ static int bttv_queryctrl(struct file *file, void *priv, | |||
2955 | c->id >= V4L2_CID_PRIVATE_LASTP1)) | 2900 | c->id >= V4L2_CID_PRIVATE_LASTP1)) |
2956 | return -EINVAL; | 2901 | return -EINVAL; |
2957 | 2902 | ||
2958 | mutex_lock(&btv->lock); | ||
2959 | if (!btv->volume_gpio && (c->id == V4L2_CID_AUDIO_VOLUME)) | 2903 | if (!btv->volume_gpio && (c->id == V4L2_CID_AUDIO_VOLUME)) |
2960 | *c = no_ctl; | 2904 | *c = no_ctl; |
2961 | else { | 2905 | else { |
@@ -2963,7 +2907,6 @@ static int bttv_queryctrl(struct file *file, void *priv, | |||
2963 | 2907 | ||
2964 | *c = (NULL != ctrl) ? *ctrl : no_ctl; | 2908 | *c = (NULL != ctrl) ? *ctrl : no_ctl; |
2965 | } | 2909 | } |
2966 | mutex_unlock(&btv->lock); | ||
2967 | 2910 | ||
2968 | return 0; | 2911 | return 0; |
2969 | } | 2912 | } |
@@ -2974,10 +2917,8 @@ static int bttv_g_parm(struct file *file, void *f, | |||
2974 | struct bttv_fh *fh = f; | 2917 | struct bttv_fh *fh = f; |
2975 | struct bttv *btv = fh->btv; | 2918 | struct bttv *btv = fh->btv; |
2976 | 2919 | ||
2977 | mutex_lock(&btv->lock); | ||
2978 | v4l2_video_std_frame_period(bttv_tvnorms[btv->tvnorm].v4l2_id, | 2920 | v4l2_video_std_frame_period(bttv_tvnorms[btv->tvnorm].v4l2_id, |
2979 | &parm->parm.capture.timeperframe); | 2921 | &parm->parm.capture.timeperframe); |
2980 | mutex_unlock(&btv->lock); | ||
2981 | 2922 | ||
2982 | return 0; | 2923 | return 0; |
2983 | } | 2924 | } |
@@ -2993,7 +2934,6 @@ static int bttv_g_tuner(struct file *file, void *priv, | |||
2993 | if (0 != t->index) | 2934 | if (0 != t->index) |
2994 | return -EINVAL; | 2935 | return -EINVAL; |
2995 | 2936 | ||
2996 | mutex_lock(&btv->lock); | ||
2997 | t->rxsubchans = V4L2_TUNER_SUB_MONO; | 2937 | t->rxsubchans = V4L2_TUNER_SUB_MONO; |
2998 | bttv_call_all(btv, tuner, g_tuner, t); | 2938 | bttv_call_all(btv, tuner, g_tuner, t); |
2999 | strcpy(t->name, "Television"); | 2939 | strcpy(t->name, "Television"); |
@@ -3005,7 +2945,6 @@ static int bttv_g_tuner(struct file *file, void *priv, | |||
3005 | if (btv->audio_mode_gpio) | 2945 | if (btv->audio_mode_gpio) |
3006 | btv->audio_mode_gpio(btv, t, 0); | 2946 | btv->audio_mode_gpio(btv, t, 0); |
3007 | 2947 | ||
3008 | mutex_unlock(&btv->lock); | ||
3009 | return 0; | 2948 | return 0; |
3010 | } | 2949 | } |
3011 | 2950 | ||
@@ -3014,9 +2953,7 @@ static int bttv_g_priority(struct file *file, void *f, enum v4l2_priority *p) | |||
3014 | struct bttv_fh *fh = f; | 2953 | struct bttv_fh *fh = f; |
3015 | struct bttv *btv = fh->btv; | 2954 | struct bttv *btv = fh->btv; |
3016 | 2955 | ||
3017 | mutex_lock(&btv->lock); | ||
3018 | *p = v4l2_prio_max(&btv->prio); | 2956 | *p = v4l2_prio_max(&btv->prio); |
3019 | mutex_unlock(&btv->lock); | ||
3020 | 2957 | ||
3021 | return 0; | 2958 | return 0; |
3022 | } | 2959 | } |
@@ -3028,9 +2965,7 @@ static int bttv_s_priority(struct file *file, void *f, | |||
3028 | struct bttv *btv = fh->btv; | 2965 | struct bttv *btv = fh->btv; |
3029 | int rc; | 2966 | int rc; |
3030 | 2967 | ||
3031 | mutex_lock(&btv->lock); | ||
3032 | rc = v4l2_prio_change(&btv->prio, &fh->prio, prio); | 2968 | rc = v4l2_prio_change(&btv->prio, &fh->prio, prio); |
3033 | mutex_unlock(&btv->lock); | ||
3034 | 2969 | ||
3035 | return rc; | 2970 | return rc; |
3036 | } | 2971 | } |
@@ -3045,9 +2980,7 @@ static int bttv_cropcap(struct file *file, void *priv, | |||
3045 | cap->type != V4L2_BUF_TYPE_VIDEO_OVERLAY) | 2980 | cap->type != V4L2_BUF_TYPE_VIDEO_OVERLAY) |
3046 | return -EINVAL; | 2981 | return -EINVAL; |
3047 | 2982 | ||
3048 | mutex_lock(&btv->lock); | ||
3049 | *cap = bttv_tvnorms[btv->tvnorm].cropcap; | 2983 | *cap = bttv_tvnorms[btv->tvnorm].cropcap; |
3050 | mutex_unlock(&btv->lock); | ||
3051 | 2984 | ||
3052 | return 0; | 2985 | return 0; |
3053 | } | 2986 | } |
@@ -3065,9 +2998,7 @@ static int bttv_g_crop(struct file *file, void *f, struct v4l2_crop *crop) | |||
3065 | inconsistent with fh->width or fh->height and apps | 2998 | inconsistent with fh->width or fh->height and apps |
3066 | do not expect a change here. */ | 2999 | do not expect a change here. */ |
3067 | 3000 | ||
3068 | mutex_lock(&btv->lock); | ||
3069 | crop->c = btv->crop[!!fh->do_crop].rect; | 3001 | crop->c = btv->crop[!!fh->do_crop].rect; |
3070 | mutex_unlock(&btv->lock); | ||
3071 | 3002 | ||
3072 | return 0; | 3003 | return 0; |
3073 | } | 3004 | } |
@@ -3091,17 +3022,14 @@ static int bttv_s_crop(struct file *file, void *f, struct v4l2_crop *crop) | |||
3091 | /* Make sure tvnorm, vbi_end and the current cropping | 3022 | /* Make sure tvnorm, vbi_end and the current cropping |
3092 | parameters remain consistent until we're done. Note | 3023 | parameters remain consistent until we're done. Note |
3093 | read() may change vbi_end in check_alloc_btres_lock(). */ | 3024 | read() may change vbi_end in check_alloc_btres_lock(). */ |
3094 | mutex_lock(&btv->lock); | ||
3095 | retval = v4l2_prio_check(&btv->prio, fh->prio); | 3025 | retval = v4l2_prio_check(&btv->prio, fh->prio); |
3096 | if (0 != retval) { | 3026 | if (0 != retval) { |
3097 | mutex_unlock(&btv->lock); | ||
3098 | return retval; | 3027 | return retval; |
3099 | } | 3028 | } |
3100 | 3029 | ||
3101 | retval = -EBUSY; | 3030 | retval = -EBUSY; |
3102 | 3031 | ||
3103 | if (locked_btres(fh->btv, VIDEO_RESOURCES)) { | 3032 | if (locked_btres(fh->btv, VIDEO_RESOURCES)) { |
3104 | mutex_unlock(&btv->lock); | ||
3105 | return retval; | 3033 | return retval; |
3106 | } | 3034 | } |
3107 | 3035 | ||
@@ -3113,7 +3041,6 @@ static int bttv_s_crop(struct file *file, void *f, struct v4l2_crop *crop) | |||
3113 | 3041 | ||
3114 | b_top = max(b->top, btv->vbi_end); | 3042 | b_top = max(b->top, btv->vbi_end); |
3115 | if (b_top + 32 >= b_bottom) { | 3043 | if (b_top + 32 >= b_bottom) { |
3116 | mutex_unlock(&btv->lock); | ||
3117 | return retval; | 3044 | return retval; |
3118 | } | 3045 | } |
3119 | 3046 | ||
@@ -3136,12 +3063,8 @@ static int bttv_s_crop(struct file *file, void *f, struct v4l2_crop *crop) | |||
3136 | 3063 | ||
3137 | btv->crop[1] = c; | 3064 | btv->crop[1] = c; |
3138 | 3065 | ||
3139 | mutex_unlock(&btv->lock); | ||
3140 | |||
3141 | fh->do_crop = 1; | 3066 | fh->do_crop = 1; |
3142 | 3067 | ||
3143 | mutex_lock(&fh->cap.vb_lock); | ||
3144 | |||
3145 | if (fh->width < c.min_scaled_width) { | 3068 | if (fh->width < c.min_scaled_width) { |
3146 | fh->width = c.min_scaled_width; | 3069 | fh->width = c.min_scaled_width; |
3147 | btv->init.width = c.min_scaled_width; | 3070 | btv->init.width = c.min_scaled_width; |
@@ -3158,8 +3081,6 @@ static int bttv_s_crop(struct file *file, void *f, struct v4l2_crop *crop) | |||
3158 | btv->init.height = c.max_scaled_height; | 3081 | btv->init.height = c.max_scaled_height; |
3159 | } | 3082 | } |
3160 | 3083 | ||
3161 | mutex_unlock(&fh->cap.vb_lock); | ||
3162 | |||
3163 | return 0; | 3084 | return 0; |
3164 | } | 3085 | } |
3165 | 3086 | ||
@@ -3227,7 +3148,6 @@ static unsigned int bttv_poll(struct file *file, poll_table *wait) | |||
3227 | return videobuf_poll_stream(file, &fh->vbi, wait); | 3148 | return videobuf_poll_stream(file, &fh->vbi, wait); |
3228 | } | 3149 | } |
3229 | 3150 | ||
3230 | mutex_lock(&fh->cap.vb_lock); | ||
3231 | if (check_btres(fh,RESOURCE_VIDEO_STREAM)) { | 3151 | if (check_btres(fh,RESOURCE_VIDEO_STREAM)) { |
3232 | /* streaming capture */ | 3152 | /* streaming capture */ |
3233 | if (list_empty(&fh->cap.stream)) | 3153 | if (list_empty(&fh->cap.stream)) |
@@ -3262,7 +3182,6 @@ static unsigned int bttv_poll(struct file *file, poll_table *wait) | |||
3262 | else | 3182 | else |
3263 | rc = 0; | 3183 | rc = 0; |
3264 | err: | 3184 | err: |
3265 | mutex_unlock(&fh->cap.vb_lock); | ||
3266 | return rc; | 3185 | return rc; |
3267 | } | 3186 | } |
3268 | 3187 | ||
@@ -3293,23 +3212,11 @@ static int bttv_open(struct file *file) | |||
3293 | return -ENOMEM; | 3212 | return -ENOMEM; |
3294 | file->private_data = fh; | 3213 | file->private_data = fh; |
3295 | 3214 | ||
3296 | /* | ||
3297 | * btv is protected by btv->lock mutex, while btv->init and other | ||
3298 | * streaming vars are protected by fh->cap.vb_lock. We need to take | ||
3299 | * care of both locks to avoid troubles. However, vb_lock is used also | ||
3300 | * inside videobuf, without calling buf->lock. So, it is a very bad | ||
3301 | * idea to hold both locks at the same time. | ||
3302 | * Let's first copy btv->init at fh, holding cap.vb_lock, and then work | ||
3303 | * with the rest of init, holding btv->lock. | ||
3304 | */ | ||
3305 | mutex_lock(&fh->cap.vb_lock); | ||
3306 | *fh = btv->init; | 3215 | *fh = btv->init; |
3307 | mutex_unlock(&fh->cap.vb_lock); | ||
3308 | 3216 | ||
3309 | fh->type = type; | 3217 | fh->type = type; |
3310 | fh->ov.setup_ok = 0; | 3218 | fh->ov.setup_ok = 0; |
3311 | 3219 | ||
3312 | mutex_lock(&btv->lock); | ||
3313 | v4l2_prio_open(&btv->prio, &fh->prio); | 3220 | v4l2_prio_open(&btv->prio, &fh->prio); |
3314 | 3221 | ||
3315 | videobuf_queue_sg_init(&fh->cap, &bttv_video_qops, | 3222 | videobuf_queue_sg_init(&fh->cap, &bttv_video_qops, |
@@ -3317,13 +3224,13 @@ static int bttv_open(struct file *file) | |||
3317 | V4L2_BUF_TYPE_VIDEO_CAPTURE, | 3224 | V4L2_BUF_TYPE_VIDEO_CAPTURE, |
3318 | V4L2_FIELD_INTERLACED, | 3225 | V4L2_FIELD_INTERLACED, |
3319 | sizeof(struct bttv_buffer), | 3226 | sizeof(struct bttv_buffer), |
3320 | fh, NULL); | 3227 | fh, &btv->lock); |
3321 | videobuf_queue_sg_init(&fh->vbi, &bttv_vbi_qops, | 3228 | videobuf_queue_sg_init(&fh->vbi, &bttv_vbi_qops, |
3322 | &btv->c.pci->dev, &btv->s_lock, | 3229 | &btv->c.pci->dev, &btv->s_lock, |
3323 | V4L2_BUF_TYPE_VBI_CAPTURE, | 3230 | V4L2_BUF_TYPE_VBI_CAPTURE, |
3324 | V4L2_FIELD_SEQ_TB, | 3231 | V4L2_FIELD_SEQ_TB, |
3325 | sizeof(struct bttv_buffer), | 3232 | sizeof(struct bttv_buffer), |
3326 | fh, NULL); | 3233 | fh, &btv->lock); |
3327 | set_tvnorm(btv,btv->tvnorm); | 3234 | set_tvnorm(btv,btv->tvnorm); |
3328 | set_input(btv, btv->input, btv->tvnorm); | 3235 | set_input(btv, btv->input, btv->tvnorm); |
3329 | 3236 | ||
@@ -3346,7 +3253,6 @@ static int bttv_open(struct file *file) | |||
3346 | bttv_vbi_fmt_reset(&fh->vbi_fmt, btv->tvnorm); | 3253 | bttv_vbi_fmt_reset(&fh->vbi_fmt, btv->tvnorm); |
3347 | 3254 | ||
3348 | bttv_field_count(btv); | 3255 | bttv_field_count(btv); |
3349 | mutex_unlock(&btv->lock); | ||
3350 | return 0; | 3256 | return 0; |
3351 | } | 3257 | } |
3352 | 3258 | ||
@@ -3355,7 +3261,6 @@ static int bttv_release(struct file *file) | |||
3355 | struct bttv_fh *fh = file->private_data; | 3261 | struct bttv_fh *fh = file->private_data; |
3356 | struct bttv *btv = fh->btv; | 3262 | struct bttv *btv = fh->btv; |
3357 | 3263 | ||
3358 | mutex_lock(&btv->lock); | ||
3359 | /* turn off overlay */ | 3264 | /* turn off overlay */ |
3360 | if (check_btres(fh, RESOURCE_OVERLAY)) | 3265 | if (check_btres(fh, RESOURCE_OVERLAY)) |
3361 | bttv_switch_overlay(btv,fh,NULL); | 3266 | bttv_switch_overlay(btv,fh,NULL); |
@@ -3381,14 +3286,8 @@ static int bttv_release(struct file *file) | |||
3381 | 3286 | ||
3382 | /* free stuff */ | 3287 | /* free stuff */ |
3383 | 3288 | ||
3384 | /* | ||
3385 | * videobuf uses cap.vb_lock - we should avoid holding btv->lock, | ||
3386 | * otherwise we may have dead lock conditions | ||
3387 | */ | ||
3388 | mutex_unlock(&btv->lock); | ||
3389 | videobuf_mmap_free(&fh->cap); | 3289 | videobuf_mmap_free(&fh->cap); |
3390 | videobuf_mmap_free(&fh->vbi); | 3290 | videobuf_mmap_free(&fh->vbi); |
3391 | mutex_lock(&btv->lock); | ||
3392 | v4l2_prio_close(&btv->prio, fh->prio); | 3291 | v4l2_prio_close(&btv->prio, fh->prio); |
3393 | file->private_data = NULL; | 3292 | file->private_data = NULL; |
3394 | kfree(fh); | 3293 | kfree(fh); |
@@ -3398,7 +3297,6 @@ static int bttv_release(struct file *file) | |||
3398 | 3297 | ||
3399 | if (!btv->users) | 3298 | if (!btv->users) |
3400 | audio_mute(btv, 1); | 3299 | audio_mute(btv, 1); |
3401 | mutex_unlock(&btv->lock); | ||
3402 | 3300 | ||
3403 | return 0; | 3301 | return 0; |
3404 | } | 3302 | } |
@@ -3502,11 +3400,8 @@ static int radio_open(struct file *file) | |||
3502 | if (unlikely(!fh)) | 3400 | if (unlikely(!fh)) |
3503 | return -ENOMEM; | 3401 | return -ENOMEM; |
3504 | file->private_data = fh; | 3402 | file->private_data = fh; |
3505 | mutex_lock(&fh->cap.vb_lock); | ||
3506 | *fh = btv->init; | 3403 | *fh = btv->init; |
3507 | mutex_unlock(&fh->cap.vb_lock); | ||
3508 | 3404 | ||
3509 | mutex_lock(&btv->lock); | ||
3510 | v4l2_prio_open(&btv->prio, &fh->prio); | 3405 | v4l2_prio_open(&btv->prio, &fh->prio); |
3511 | 3406 | ||
3512 | btv->radio_user++; | 3407 | btv->radio_user++; |
@@ -3514,7 +3409,6 @@ static int radio_open(struct file *file) | |||
3514 | bttv_call_all(btv, tuner, s_radio); | 3409 | bttv_call_all(btv, tuner, s_radio); |
3515 | audio_input(btv,TVAUDIO_INPUT_RADIO); | 3410 | audio_input(btv,TVAUDIO_INPUT_RADIO); |
3516 | 3411 | ||
3517 | mutex_unlock(&btv->lock); | ||
3518 | return 0; | 3412 | return 0; |
3519 | } | 3413 | } |
3520 | 3414 | ||
@@ -3524,7 +3418,6 @@ static int radio_release(struct file *file) | |||
3524 | struct bttv *btv = fh->btv; | 3418 | struct bttv *btv = fh->btv; |
3525 | struct rds_command cmd; | 3419 | struct rds_command cmd; |
3526 | 3420 | ||
3527 | mutex_lock(&btv->lock); | ||
3528 | v4l2_prio_close(&btv->prio, fh->prio); | 3421 | v4l2_prio_close(&btv->prio, fh->prio); |
3529 | file->private_data = NULL; | 3422 | file->private_data = NULL; |
3530 | kfree(fh); | 3423 | kfree(fh); |
@@ -3532,7 +3425,6 @@ static int radio_release(struct file *file) | |||
3532 | btv->radio_user--; | 3425 | btv->radio_user--; |
3533 | 3426 | ||
3534 | bttv_call_all(btv, core, ioctl, RDS_CMD_CLOSE, &cmd); | 3427 | bttv_call_all(btv, core, ioctl, RDS_CMD_CLOSE, &cmd); |
3535 | mutex_unlock(&btv->lock); | ||
3536 | 3428 | ||
3537 | return 0; | 3429 | return 0; |
3538 | } | 3430 | } |
@@ -3561,7 +3453,6 @@ static int radio_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t) | |||
3561 | return -EINVAL; | 3453 | return -EINVAL; |
3562 | if (0 != t->index) | 3454 | if (0 != t->index) |
3563 | return -EINVAL; | 3455 | return -EINVAL; |
3564 | mutex_lock(&btv->lock); | ||
3565 | strcpy(t->name, "Radio"); | 3456 | strcpy(t->name, "Radio"); |
3566 | t->type = V4L2_TUNER_RADIO; | 3457 | t->type = V4L2_TUNER_RADIO; |
3567 | 3458 | ||
@@ -3570,8 +3461,6 @@ static int radio_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t) | |||
3570 | if (btv->audio_mode_gpio) | 3461 | if (btv->audio_mode_gpio) |
3571 | btv->audio_mode_gpio(btv, t, 0); | 3462 | btv->audio_mode_gpio(btv, t, 0); |
3572 | 3463 | ||
3573 | mutex_unlock(&btv->lock); | ||
3574 | |||
3575 | return 0; | 3464 | return 0; |
3576 | } | 3465 | } |
3577 | 3466 | ||
@@ -3692,7 +3581,7 @@ static const struct v4l2_file_operations radio_fops = | |||
3692 | .open = radio_open, | 3581 | .open = radio_open, |
3693 | .read = radio_read, | 3582 | .read = radio_read, |
3694 | .release = radio_release, | 3583 | .release = radio_release, |
3695 | .ioctl = video_ioctl2, | 3584 | .unlocked_ioctl = video_ioctl2, |
3696 | .poll = radio_poll, | 3585 | .poll = radio_poll, |
3697 | }; | 3586 | }; |
3698 | 3587 | ||