From cdaa898b5efcc598ab1004e8f913061dc7005091 Mon Sep 17 00:00:00 2001 From: Tomas Winkler Date: Tue, 5 Jul 2011 21:07:47 +0300 Subject: [PATCH] staging/easycap: kill telltale logic This reason for this feature was 'some versions of the videodev module overwrite the data which has been written by the call to usb_set_intfdata() in easycap_usb_probe(), replacing it with a pointer to the embedded v4l2_device structure. to detect this, the string in the easycap.telltale[] buffer is checked.' The upstream version of v4l2_device_register sets driver data only when it wasn't already set, therefore this is not needed Signed-off-by: Tomas Winkler Signed-off-by: Greg Kroah-Hartman --- drivers/staging/easycap/easycap.h | 2 - drivers/staging/easycap/easycap_ioctl.c | 10 --- drivers/staging/easycap/easycap_main.c | 84 +------------------------ drivers/staging/easycap/easycap_sound.c | 29 --------- 4 files changed, 3 insertions(+), 122 deletions(-) diff --git a/drivers/staging/easycap/easycap.h b/drivers/staging/easycap/easycap.h index f5e7193c4bdb..bd3f7c7caf16 100644 --- a/drivers/staging/easycap/easycap.h +++ b/drivers/staging/easycap/easycap.h @@ -280,8 +280,6 @@ struct inputset { */ /*---------------------------------------------------------------------------*/ struct easycap { -#define TELLTALE "expectedstring" - char telltale[16]; int isdongle; int minor; diff --git a/drivers/staging/easycap/easycap_ioctl.c b/drivers/staging/easycap/easycap_ioctl.c index f767f2ea390c..80aa5d8ed5d0 100644 --- a/drivers/staging/easycap/easycap_ioctl.c +++ b/drivers/staging/easycap/easycap_ioctl.c @@ -967,10 +967,6 @@ long easycap_unlocked_ioctl(struct file *file, SAY("ERROR: peasycap is NULL\n"); return -1; } - if (memcmp(&peasycap->telltale[0], TELLTALE, strlen(TELLTALE))) { - SAY("ERROR: bad peasycap\n"); - return -EFAULT; - } p = peasycap->pusb_device; if (!p) { SAM("ERROR: peasycap->pusb_device is NULL\n"); @@ -1004,12 +1000,6 @@ long easycap_unlocked_ioctl(struct file *file, mutex_unlock(&easycapdc60_dongle[kd].mutex_video); return -ERESTARTSYS; } - if (memcmp(&peasycap->telltale[0], TELLTALE, strlen(TELLTALE))) { - SAY("ERROR: bad peasycap\n"); - mutex_unlock(&easycapdc60_dongle[kd].mutex_video); - return -EFAULT; - } - p = peasycap->pusb_device; if (!peasycap->pusb_device) { SAM("ERROR: peasycap->pusb_device is NULL\n"); mutex_unlock(&easycapdc60_dongle[kd].mutex_video); diff --git a/drivers/staging/easycap/easycap_main.c b/drivers/staging/easycap/easycap_main.c index 84d4f77ef46b..a0299560701c 100644 --- a/drivers/staging/easycap/easycap_main.c +++ b/drivers/staging/easycap/easycap_main.c @@ -158,10 +158,6 @@ static int easycap_open(struct inode *inode, struct file *file) SAY("ERROR: peasycap is NULL\n"); return -EFAULT; } - if (memcmp(&peasycap->telltale[0], TELLTALE, strlen(TELLTALE))) { - SAY("ERROR: bad peasycap: %p\n", peasycap); - return -EFAULT; - } if (!peasycap->pusb_device) { SAM("ERROR: peasycap->pusb_device is NULL\n"); return -EFAULT; @@ -695,10 +691,6 @@ static int videodev_release(struct video_device *pvideo_device) SAY("ending unsuccessfully\n"); return -EFAULT; } - if (memcmp(&peasycap->telltale[0], TELLTALE, strlen(TELLTALE))) { - SAY("ERROR: bad peasycap: %p\n", peasycap); - return -EFAULT; - } if (0 != kill_video_urbs(peasycap)) { SAM("ERROR: kill_video_urbs() failed\n"); return -EFAULT; @@ -736,10 +728,6 @@ static void easycap_delete(struct kref *pkref) SAM("ERROR: peasycap is NULL: cannot perform deletions\n"); return; } - if (memcmp(&peasycap->telltale[0], TELLTALE, strlen(TELLTALE))) { - SAY("ERROR: bad peasycap: %p\n", peasycap); - return; - } kd = isdongle(peasycap); /*---------------------------------------------------------------------------*/ /* @@ -962,10 +950,6 @@ static unsigned int easycap_poll(struct file *file, poll_table *wait) SAY("ERROR: peasycap is NULL\n"); return -EFAULT; } - if (memcmp(&peasycap->telltale[0], TELLTALE, strlen(TELLTALE))) { - SAY("ERROR: bad peasycap: %p\n", peasycap); - return -EFAULT; - } if (!peasycap->pusb_device) { SAY("ERROR: peasycap->pusb_device is NULL\n"); return -EFAULT; @@ -996,11 +980,6 @@ static unsigned int easycap_poll(struct file *file, poll_table *wait) mutex_unlock(&easycapdc60_dongle[kd].mutex_video); return -ERESTARTSYS; } - if (memcmp(&peasycap->telltale[0], TELLTALE, strlen(TELLTALE))) { - SAY("ERROR: bad peasycap: %p\n", peasycap); - mutex_unlock(&easycapdc60_dongle[kd].mutex_video); - return -ERESTARTSYS; - } if (!peasycap->pusb_device) { SAM("ERROR: peasycap->pusb_device is NULL\n"); mutex_unlock(&easycapdc60_dongle[kd].mutex_video); @@ -2455,10 +2434,6 @@ static void easycap_vma_open(struct vm_area_struct *pvma) SAY("ERROR: peasycap is NULL\n"); return; } - if (memcmp(&peasycap->telltale[0], TELLTALE, strlen(TELLTALE))) { - SAY("ERROR: bad peasycap: %p\n", peasycap); - return; - } peasycap->vma_many++; JOT(8, "%i=peasycap->vma_many\n", peasycap->vma_many); return; @@ -2473,10 +2448,6 @@ static void easycap_vma_close(struct vm_area_struct *pvma) SAY("ERROR: peasycap is NULL\n"); return; } - if (memcmp(&peasycap->telltale[0], TELLTALE, strlen(TELLTALE))) { - SAY("ERROR: bad peasycap: %p\n", peasycap); - return; - } peasycap->vma_many--; JOT(8, "%i=peasycap->vma_many\n", peasycap->vma_many); return; @@ -2607,10 +2578,6 @@ static void easycap_complete(struct urb *purb) SAY("ERROR: easycap_complete(): peasycap is NULL\n"); return; } - if (memcmp(&peasycap->telltale[0], TELLTALE, strlen(TELLTALE))) { - SAY("ERROR: bad peasycap: %p\n", peasycap); - return; - } if (peasycap->video_eof) return; for (i = 0; i < VIDEO_ISOC_BUFFER_MANY; i++) @@ -3001,7 +2968,6 @@ static int easycap_usb_probe(struct usb_interface *intf, struct easycap_format *peasycap_format; int fmtidx; struct inputset *inputset; - struct v4l2_device *pv4l2_device; usbdev = interface_to_usbdev(intf); @@ -3055,7 +3021,6 @@ static int easycap_usb_probe(struct usb_interface *intf, */ /*---------------------------------------------------------------------------*/ peasycap->minor = -1; - strcpy(&peasycap->telltale[0], TELLTALE); kref_init(&peasycap->kref); JOM(8, "intf[%i]: after kref_init(..._video) " "%i=peasycap->kref.refcount.counter\n", @@ -3268,23 +3233,6 @@ static int easycap_usb_probe(struct usb_interface *intf, bInterfaceNumber); return -ENODEV; } -/*---------------------------------------------------------------------------*/ -/* - * SOME VERSIONS OF THE videodev MODULE OVERWRITE THE DATA WHICH HAS - * BEEN WRITTEN BY THE CALL TO usb_set_intfdata() IN easycap_usb_probe(), - * REPLACING IT WITH A POINTER TO THE EMBEDDED v4l2_device STRUCTURE. - * TO DETECT THIS, THE STRING IN THE easycap.telltale[] BUFFER IS CHECKED. -*/ -/*---------------------------------------------------------------------------*/ - if (memcmp(&peasycap->telltale[0], TELLTALE, strlen(TELLTALE))) { - pv4l2_device = usb_get_intfdata(intf); - if (!pv4l2_device) { - SAY("ERROR: pv4l2_device is NULL\n"); - return -ENODEV; - } - peasycap = (struct easycap *) - container_of(pv4l2_device, struct easycap, v4l2_device); - } } /*---------------------------------------------------------------------------*/ if ((USB_CLASS_VIDEO == bInterfaceClass) || @@ -3776,14 +3724,12 @@ static int easycap_usb_probe(struct usb_interface *intf, * THE VIDEO DEVICE CAN BE REGISTERED NOW, AS IT IS READY. */ /*--------------------------------------------------------------------------*/ - if (0 != (v4l2_device_register(&(intf->dev), - &(peasycap->v4l2_device)))) { + if (v4l2_device_register(&intf->dev, &peasycap->v4l2_device)) { SAM("v4l2_device_register() failed\n"); return -ENODEV; - } else { - JOM(4, "registered device instance: %s\n", - &(peasycap->v4l2_device.name[0])); } + JOM(4, "registered device instance: %s\n", + peasycap->v4l2_device.name); /*---------------------------------------------------------------------------*/ /* * FIXME @@ -4160,7 +4106,6 @@ static void easycap_usb_disconnect(struct usb_interface *pusb_interface) struct list_head *plist_head; struct data_urb *pdata_urb; int minor, m, kd; - struct v4l2_device *pv4l2_device; JOT(4, "\n"); @@ -4187,29 +4132,6 @@ static void easycap_usb_disconnect(struct usb_interface *pusb_interface) return; } /*---------------------------------------------------------------------------*/ -/* - * SOME VERSIONS OF THE videodev MODULE OVERWRITE THE DATA WHICH HAS - * BEEN WRITTEN BY THE CALL TO usb_set_intfdata() IN easycap_usb_probe(), - * REPLACING IT WITH A POINTER TO THE EMBEDDED v4l2_device STRUCTURE. - * TO DETECT THIS, THE STRING IN THE easycap.telltale[] BUFFER IS CHECKED. -*/ -/*---------------------------------------------------------------------------*/ - if (memcmp(&peasycap->telltale[0], TELLTALE, strlen(TELLTALE))) { - pv4l2_device = usb_get_intfdata(pusb_interface); - if (!pv4l2_device) { - SAY("ERROR: pv4l2_device is NULL\n"); - return; - } - peasycap = (struct easycap *) - container_of(pv4l2_device, struct easycap, v4l2_device); - } -/*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/ -/*---------------------------------------------------------------------------*/ - if (memcmp(&peasycap->telltale[0], TELLTALE, strlen(TELLTALE))) { - SAY("ERROR: bad peasycap: %p\n", peasycap); - return; - } -/*---------------------------------------------------------------------------*/ /* * IF THE WAIT QUEUES ARE NOT CLEARED A DEADLOCK IS POSSIBLE. BEWARE. */ diff --git a/drivers/staging/easycap/easycap_sound.c b/drivers/staging/easycap/easycap_sound.c index a3402b00a8be..9218d81e1d82 100644 --- a/drivers/staging/easycap/easycap_sound.c +++ b/drivers/staging/easycap/easycap_sound.c @@ -92,10 +92,6 @@ easycap_alsa_complete(struct urb *purb) SAY("ERROR: peasycap is NULL\n"); return; } - if (memcmp(&peasycap->telltale[0], TELLTALE, strlen(TELLTALE))) { - SAY("ERROR: bad peasycap\n"); - return; - } much = 0; if (peasycap->audio_idle) { JOM(16, "%i=audio_idle %i=audio_isoc_streaming\n", @@ -310,10 +306,6 @@ static int easycap_alsa_open(struct snd_pcm_substream *pss) SAY("ERROR: peasycap is NULL\n"); return -EFAULT; } - if (memcmp(&peasycap->telltale[0], TELLTALE, strlen(TELLTALE))) { - SAY("ERROR: bad peasycap\n"); - return -EFAULT; - } if (peasycap->psnd_card != psnd_card) { SAM("ERROR: bad peasycap->psnd_card\n"); return -EFAULT; @@ -350,10 +342,6 @@ static int easycap_alsa_close(struct snd_pcm_substream *pss) SAY("ERROR: peasycap is NULL\n"); return -EFAULT; } - if (memcmp(&peasycap->telltale[0], TELLTALE, strlen(TELLTALE))) { - SAY("ERROR: bad peasycap\n"); - return -EFAULT; - } pss->private_data = NULL; peasycap->psubstream = NULL; JOT(4, "ending successfully\n"); @@ -441,10 +429,6 @@ static int easycap_alsa_prepare(struct snd_pcm_substream *pss) SAY("ERROR: peasycap is NULL\n"); return -EFAULT; } - if (memcmp(&peasycap->telltale[0], TELLTALE, strlen(TELLTALE))) { - SAY("ERROR: bad peasycap\n"); - return -EFAULT; - } JOM(16, "ALSA decides %8i Hz=rate\n", pss->runtime->rate); JOM(16, "ALSA decides %8ld =period_size\n", pss->runtime->period_size); @@ -488,11 +472,6 @@ static int easycap_alsa_trigger(struct snd_pcm_substream *pss, int cmd) SAY("ERROR: peasycap is NULL\n"); return -EFAULT; } - if (memcmp(&peasycap->telltale[0], TELLTALE, strlen(TELLTALE))) { - SAY("ERROR: bad peasycap\n"); - return -EFAULT; - } - switch (cmd) { case SNDRV_PCM_TRIGGER_START: { peasycap->audio_idle = 0; @@ -523,10 +502,6 @@ static snd_pcm_uframes_t easycap_alsa_pointer(struct snd_pcm_substream *pss) SAY("ERROR: peasycap is NULL\n"); return -EFAULT; } - if (memcmp(&peasycap->telltale[0], TELLTALE, strlen(TELLTALE))) { - SAY("ERROR: bad peasycap\n"); - return -EFAULT; - } if ((0 != peasycap->audio_eof) || (0 != peasycap->audio_idle)) { JOM(8, "returning -EIO because " "%i=audio_idle %i=audio_eof\n", @@ -584,10 +559,6 @@ int easycap_alsa_probe(struct easycap *peasycap) SAY("ERROR: peasycap is NULL\n"); return -ENODEV; } - if (memcmp(&peasycap->telltale[0], TELLTALE, strlen(TELLTALE))) { - SAY("ERROR: bad peasycap\n"); - return -EFAULT; - } if (0 > peasycap->minor) { SAY("ERROR: no minor\n"); return -ENODEV; -- 2.34.1