public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
From: "Frank Schäfer" <fschaefer.oss@googlemail.com>
To: Mauro Carvalho Chehab <mchehab@redhat.com>, unlisted-recipients:;
Cc: Mauro Carvalho Chehab <m.chehab@samsung.com>,
	Linux Media Mailing List <linux-media@vger.kernel.org>,
	Mauro Carvalho Chehab <mchehab@infradead.org>
Subject: Re: [PATCH v3 20/24] em28xx: Fix em28xx deplock
Date: Fri, 03 Jan 2014 18:03:10 +0100	[thread overview]
Message-ID: <52C6ED4E.1030307@googlemail.com> (raw)
In-Reply-To: <1388232976-20061-21-git-send-email-mchehab@redhat.com>

Am 28.12.2013 13:16, schrieb Mauro Carvalho Chehab:
> From: Mauro Carvalho Chehab <m.chehab@samsung.com>
>
> When em28xx extensions are loaded/removed, there are two locks:
>
> a single static em28xx_devlist_mutex that registers each extension
> and the struct em28xx dev->lock.
>
> When extensions are registered, em28xx_devlist_mutex is taken first,
> and then dev->lock.
>
> Be sure that, when extensions are being removed, the same order
> will be used.
>
> Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
> ---
>  drivers/media/usb/em28xx/em28xx-cards.c | 10 ++++++----
>  drivers/media/usb/em28xx/em28xx-core.c  |  2 ++
>  2 files changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/media/usb/em28xx/em28xx-cards.c b/drivers/media/usb/em28xx/em28xx-cards.c
> index 4fe742429f2c..16383f46dae9 100644
> --- a/drivers/media/usb/em28xx/em28xx-cards.c
> +++ b/drivers/media/usb/em28xx/em28xx-cards.c
> @@ -3334,9 +3334,7 @@ static void em28xx_usb_disconnect(struct usb_interface *interface)
>  	dev->disconnected = 1;
>  
>  	if (dev->is_audio_only) {
> -		mutex_lock(&dev->lock);
>  		em28xx_close_extension(dev);
> -		mutex_unlock(&dev->lock);
>  		return;
>  	}
>  
> @@ -3355,19 +3353,23 @@ static void em28xx_usb_disconnect(struct usb_interface *interface)
>  		em28xx_uninit_usb_xfer(dev, EM28XX_ANALOG_MODE);
>  		em28xx_uninit_usb_xfer(dev, EM28XX_DIGITAL_MODE);
>  	}
> +	mutex_unlock(&dev->lock);
>  
>  	em28xx_close_extension(dev);
> +
>  	/* NOTE: must be called BEFORE the resources are released */
>  
> +	mutex_lock(&dev->lock);
>  	if (!dev->users)
>  		em28xx_release_resources(dev);
>  

> -	mutex_unlock(&dev->lock);
> -
>  	if (!dev->users) {
> +		mutex_unlock(&dev->lock);
>  		kfree(dev->alt_max_pkt_size_isoc);
>  		kfree(dev);
> +		return;
>  	}
> +	mutex_unlock(&dev->lock);
No functional change here, it just needlessly complicates the code.
I assume it's a leftover from experiments. ;)

>  }
>  
>  static struct usb_driver em28xx_usb_driver = {
> diff --git a/drivers/media/usb/em28xx/em28xx-core.c b/drivers/media/usb/em28xx/em28xx-core.c
> index 2ad84ff1fc4f..d6928d83fb2a 100644
> --- a/drivers/media/usb/em28xx/em28xx-core.c
> +++ b/drivers/media/usb/em28xx/em28xx-core.c
> @@ -1098,8 +1098,10 @@ void em28xx_close_extension(struct em28xx *dev)
>  
>  	mutex_lock(&em28xx_devlist_mutex);
>  	list_for_each_entry(ops, &em28xx_extension_devlist, next) {
> +		mutex_lock(&dev->lock);
>  		if (ops->fini)
>  			ops->fini(dev);
> +		mutex_unlock(&dev->lock);
>  	}

Why not move the locking/unlocking of dev->lock outside
list_for_each_entry() ?
No need to do this one time for each extension.

>  	list_del(&dev->devlist);
>  	mutex_unlock(&em28xx_devlist_mutex);
Apart from these 2 minor issues, the patch looks good and should fix the
warning.



  reply	other threads:[~2014-01-03 17:02 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-28 12:15 [PATCH v3 00/24] em28xx: split analog part into a separate module Mauro Carvalho Chehab
2013-12-28 12:15 ` [PATCH v3 01/24] em28xx: move some video-specific functions to em28xx-video Mauro Carvalho Chehab
2013-12-28 12:15 ` [PATCH v3 02/24] em28xx: some cosmetic changes Mauro Carvalho Chehab
2013-12-28 12:15 ` [PATCH v3 03/24] em28xx: move analog-specific init to em28xx-video Mauro Carvalho Chehab
2013-12-28 12:15 ` [PATCH v3 04/24] em28xx: make em28xx-video to be a separate module Mauro Carvalho Chehab
2013-12-28 12:15 ` [PATCH v3 05/24] em28xx: initialize analog I2C devices at the right place Mauro Carvalho Chehab
2013-12-28 12:15 ` [PATCH v3 06/24] em28xx-cards: remove a now dead code Mauro Carvalho Chehab
2013-12-28 12:15 ` [PATCH v3 07/24] em28xx: fix a cut and paste error Mauro Carvalho Chehab
2013-12-28 12:16 ` [PATCH v3 08/24] em28xx: add warn messages for timeout Mauro Carvalho Chehab
2013-12-28 12:16 ` [PATCH v3 09/24] em28xx: improve extension information messages Mauro Carvalho Chehab
2013-12-28 12:16 ` [PATCH v3 10/24] em28xx: convert i2c wait completion logic to use jiffies Mauro Carvalho Chehab
2013-12-28 12:16 ` [PATCH v3 11/24] tvp5150: make read operations atomic Mauro Carvalho Chehab
2014-01-01 18:52   ` Frank Schäfer
2014-01-02 19:20     ` Mauro Carvalho Chehab
2014-01-02 21:59       ` Frank Schäfer
2013-12-28 12:16 ` [PATCH v3 12/24] tuner-xc2028: remove unused code Mauro Carvalho Chehab
2014-01-01 18:53   ` Frank Schäfer
2013-12-28 12:16 ` [PATCH v3 13/24] em28xx: retry I2C ops if failed by timeout Mauro Carvalho Chehab
2013-12-28 12:16 ` [PATCH v3 14/24] em28xx: remove a false positive warning Mauro Carvalho Chehab
2013-12-28 12:16 ` [PATCH v3 15/24] em28xx: check if a device has audio earlier Mauro Carvalho Chehab
2013-12-28 12:16 ` [PATCH v3 16/24] em28xx: properly implement AC97 wait code Mauro Carvalho Chehab
2013-12-28 12:16 ` [PATCH v3 17/24] em28xx: initialize audio latter Mauro Carvalho Chehab
2013-12-28 12:16 ` [PATCH v3 18/24] em28xx: improve I2C timeout error message Mauro Carvalho Chehab
2013-12-28 12:16 ` [PATCH v3 19/24] em28xx: unify module version Mauro Carvalho Chehab
2013-12-28 12:16 ` [PATCH v3 20/24] em28xx: Fix em28xx deplock Mauro Carvalho Chehab
2014-01-03 17:03   ` Frank Schäfer [this message]
2013-12-28 12:16 ` [PATCH v3 21/24] em28xx: USB: adjust for changed 3.8 USB API Mauro Carvalho Chehab
2013-12-28 12:26   ` Hans Verkuil
2013-12-28 12:34     ` Mauro Carvalho Chehab
2013-12-28 12:16 ` [PATCH v3 22/24] em28xx: use a better value for I2C timeouts Mauro Carvalho Chehab
2013-12-28 12:16 ` [PATCH v3 23/24] em28xx: don't return -ENODEV for I2C xfer errors Mauro Carvalho Chehab
2013-12-28 12:16 ` [PATCH v3 24/24] em28xx: cleanup I2C debug messages Mauro Carvalho Chehab
2014-01-03 20:29 ` [PATCH v3 00/24] em28xx: split analog part into a separate module Frank Schäfer
2014-01-04 14:09   ` Mauro Carvalho Chehab

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=52C6ED4E.1030307@googlemail.com \
    --to=fschaefer.oss@googlemail.com \
    --cc=linux-media@vger.kernel.org \
    --cc=m.chehab@samsung.com \
    --cc=mchehab@infradead.org \
    --cc=mchehab@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox