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