]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/ieee1394/dv1394.c
ieee1394: dv1394: fix possible deadlock in multithreaded clients
[linux-2.6-omap-h63xx.git] / drivers / ieee1394 / dv1394.c
index 9d19aec5820a303145d8b286e2d1ce2e72b4a586..53329972c7dba580df1b8bd830c8cf8a85545b47 100644 (file)
@@ -918,7 +918,7 @@ static int do_dv1394_init(struct video_card *video, struct dv1394_init *init)
                /* default SYT offset is 3 cycles */
                init->syt_offset = 3;
 
-       if ( (init->channel > 63) || (init->channel < 0) )
+       if (init->channel > 63)
                init->channel = 63;
 
        chan_mask = (u64)1 << init->channel;
@@ -1270,8 +1270,14 @@ static int dv1394_mmap(struct file *file, struct vm_area_struct *vma)
        struct video_card *video = file_to_video_card(file);
        int retval = -EINVAL;
 
-       /* serialize mmap */
-       mutex_lock(&video->mtx);
+       /*
+        * We cannot use the blocking variant mutex_lock here because .mmap
+        * is called with mmap_sem held, while .ioctl, .read, .write acquire
+        * video->mtx and subsequently call copy_to/from_user which will
+        * grab mmap_sem in case of a page fault.
+        */
+       if (!mutex_trylock(&video->mtx))
+               return -EAGAIN;
 
        if ( ! video_card_initialized(video) ) {
                retval = do_dv1394_init_default(video);
@@ -2296,9 +2302,10 @@ static void dv1394_add_host(struct hpsb_host *host)
 
        ohci = (struct ti_ohci *)host->hostdata;
 
-       device_create(hpsb_protocol_class, NULL, MKDEV(
-               IEEE1394_MAJOR, IEEE1394_MINOR_BLOCK_DV1394 * 16 + (id<<2)),
-               "dv1394-%d", id);
+       device_create_drvdata(hpsb_protocol_class, NULL,
+                             MKDEV(IEEE1394_MAJOR,
+                                   IEEE1394_MINOR_BLOCK_DV1394 * 16 + (id<<2)), NULL,
+                             "dv1394-%d", id);
 
        dv1394_init(ohci, DV1394_NTSC, MODE_RECEIVE);
        dv1394_init(ohci, DV1394_NTSC, MODE_TRANSMIT);