public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Shuah Khan <shuahkh@osg.samsung.com>
To: Javier Martinez Canillas <javier@osg.samsung.com>,
	linux-kernel@vger.kernel.org
Cc: Mauro Carvalho Chehab <mchehab@osg.samsung.com>,
	Sakari Ailus <sakari.ailus@linux.intel.com>,
	Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
	Hans Verkuil <hans.verkuil@cisco.com>,
	linux-media@vger.kernel.org, Shuah Khan <shuahkh@osg.samsung.com>
Subject: Re: [PATCH v5 1/3] [media] media-device: check before unregister if mdev was registered
Date: Fri, 11 Dec 2015 16:36:27 -0700	[thread overview]
Message-ID: <566B5DFB.3020100@osg.samsung.com> (raw)
In-Reply-To: <1449874629-8973-2-git-send-email-javier@osg.samsung.com>

On 12/11/2015 03:57 PM, Javier Martinez Canillas wrote:
> Most media functions that unregister, check if the corresponding register
> function succeed before. So these functions can safely be called even if a
> registration was never made or the component as already been unregistered.
> 
> Add the same check to media_device_unregister() function for consistency.
> 
> This will also allow to split the media_device_register() function in an
> initialization and registration functions without the need to change the
> generic cleanup functions and error code paths for all the media drivers.
> 
> Suggested-by: Sakari Ailus <sakari.ailus@linux.intel.com>
> Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
> Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
> 
> ---
> 
> Changes in v5: None
> Changes in v4: None
> Changes in v3: None
> Changes in v2:
> - Reword the documentation for media_device_unregister(). Suggested by Sakari.
> - Added Sakari's Acked-by tag for patch #1.
> 
>  drivers/media/media-device.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
> index c12481c753a0..11c1c7383361 100644
> --- a/drivers/media/media-device.c
> +++ b/drivers/media/media-device.c
> @@ -577,6 +577,8 @@ EXPORT_SYMBOL_GPL(__media_device_register);
>   * media_device_unregister - unregister a media device
>   * @mdev:	The media device
>   *
> + * It is safe to call this function on an unregistered
> + * (but initialised) media device.
>   */
>  void media_device_unregister(struct media_device *mdev)
>  {
> @@ -584,6 +586,10 @@ void media_device_unregister(struct media_device *mdev)
>  	struct media_entity *next;
>  	struct media_interface *intf, *tmp_intf;
>  
> +	/* Check if mdev was ever registered at all */
> +	if (!media_devnode_is_registered(&mdev->devnode))
> +		return;

This is a good check, however, this check will not prevent
media_device_unregister() from getting run twice by two
different drivers. i.e media_devnode gets unregistered
towards the end of at the end of media_device_unregister().

In an example case, if bridge driver and snd-usb-aduio both
call media_device_unregister(), this check won't help prevent
media_device_unregister() being done only once. I think we
need a different state variable in struct media_device
to ensure unregister is done only once.

> +
>  	/* Remove all entities from the media device */
>  	list_for_each_entry_safe(entity, next, &mdev->entities, graph_obj.list)
>  		media_device_unregister_entity(entity);
> 


-- 
Shuah Khan
Sr. Linux Kernel Developer
Open Source Innovation Group
Samsung Research America (Silicon Valley)
shuahkh@osg.samsung.com | (970) 217-8978

  reply	other threads:[~2015-12-11 23:36 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-11 22:57 [PATCH v5 0/3] [media] Fix race between graph enumeration and entities registration Javier Martinez Canillas
2015-12-11 22:57 ` [PATCH v5 1/3] [media] media-device: check before unregister if mdev was registered Javier Martinez Canillas
2015-12-11 23:36   ` Shuah Khan [this message]
2015-12-15 10:41     ` Mauro Carvalho Chehab
2015-12-21 12:14       ` Javier Martinez Canillas
2015-12-11 22:57 ` [PATCH v5 2/3] [media] media-device: split media initialization and registration Javier Martinez Canillas
2015-12-11 22:57 ` [PATCH v5 3/3] [media] media-device: set topology version 0 at media registration Javier Martinez Canillas
2015-12-12 13:50 ` [PATCH v5 0/3] [media] Fix race between graph enumeration and entities registration Mauro Carvalho Chehab
2015-12-21 11:21   ` Javier Martinez Canillas

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=566B5DFB.3020100@osg.samsung.com \
    --to=shuahkh@osg.samsung.com \
    --cc=hans.verkuil@cisco.com \
    --cc=javier@osg.samsung.com \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@osg.samsung.com \
    --cc=sakari.ailus@linux.intel.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