From: Inki Dae <inki.dae@samsung.com>
To: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH 2/3] drm/exynos: avoid race condition when adding a drm component
Date: Fri, 21 Nov 2014 15:07:33 +0900 [thread overview]
Message-ID: <546ED6A5.90207@samsung.com> (raw)
In-Reply-To: <1416527664-10553-2-git-send-email-gustavo@padovan.org>
On 2014년 11월 21일 08:54, Gustavo Padovan wrote:
> From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
>
> exynos_drm_component_add() correctly checks if a component is present on
> drm_component_list however it release the lock right after the check
> and before we add the new component to the list. That just creates room
> to add the same component more than once to the list.
A little bit strange. drm_component_list is protected from race
condition with mutex_lock. How the same component can be added to the
drm_component_list again? And a new cdev object cannot be same cdev
object already added to the drm_component_list because the new cdev
object is allocated by kzalloc(). And the only case the same kms driver
can request to add a new cdev to drm_component_list again is when the
probe of the driver failed. However, in this case, the driver will call
exynos_drm_component_del function to remove previous cdev. So the same
cdev cannot be added to the drm_component_list even in such case.
Thanks,
Inki Dae
>
> The lock should be held for the whole journey while adding a new
> component.
>
> Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
> ---
> drivers/gpu/drm/exynos/exynos_drm_drv.c | 16 +++++-----------
> 1 file changed, 5 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/gpu/drm/exynos/exynos_drm_drv.c b/drivers/gpu/drm/exynos/exynos_drm_drv.c
> index cb3ed9b..230573d 100644
> --- a/drivers/gpu/drm/exynos/exynos_drm_drv.c
> +++ b/drivers/gpu/drm/exynos/exynos_drm_drv.c
> @@ -402,10 +402,8 @@ int exynos_drm_component_add(struct device *dev,
> * added already just return.
> */
> if (cdev->dev_type_flag == (EXYNOS_DEVICE_TYPE_CRTC |
> - EXYNOS_DEVICE_TYPE_CONNECTOR)) {
> - mutex_unlock(&drm_component_lock);
> - return 0;
> - }
> + EXYNOS_DEVICE_TYPE_CONNECTOR))
> + goto unlock;
>
> if (dev_type == EXYNOS_DEVICE_TYPE_CRTC) {
> cdev->crtc_dev = dev;
> @@ -417,14 +415,11 @@ int exynos_drm_component_add(struct device *dev,
> cdev->dev_type_flag |= dev_type;
> }
>
> - mutex_unlock(&drm_component_lock);
> - return 0;
> + goto unlock;
> }
> }
>
> - mutex_unlock(&drm_component_lock);
> -
> - cdev = kzalloc(sizeof(*cdev), GFP_KERNEL);
> + cdev = kzalloc(sizeof(*cdev), GFP_ATOMIC);
> if (!cdev)
> return -ENOMEM;
>
> @@ -436,10 +431,9 @@ int exynos_drm_component_add(struct device *dev,
> cdev->out_type = out_type;
> cdev->dev_type_flag = dev_type;
>
> - mutex_lock(&drm_component_lock);
> list_add_tail(&cdev->list, &drm_component_list);
> +unlock:
> mutex_unlock(&drm_component_lock);
> -
> return 0;
> }
>
>
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel
next prev parent reply other threads:[~2014-11-21 6:07 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-20 23:54 [PATCH 1/3] drm/exynos: free DP if probe fails to find a panel or bridge Gustavo Padovan
2014-11-20 23:54 ` [PATCH 2/3] drm/exynos: avoid race condition when adding a drm component Gustavo Padovan
2014-11-21 6:07 ` Inki Dae [this message]
2014-11-21 12:50 ` Gustavo Padovan
2014-11-20 23:54 ` [PATCH 3/3] drm/exynos: avoid leak if exynos_dpi_probe() fails Gustavo Padovan
2014-11-21 17:40 ` [PATCH 1/3] drm/exynos: free DP if probe fails to find a panel or bridge Ajay kumar
2014-11-23 9:22 ` Jingoo Han
2014-11-22 14:56 ` Inki Dae
2014-11-24 13:02 ` Gustavo Padovan
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=546ED6A5.90207@samsung.com \
--to=inki.dae@samsung.com \
--cc=dri-devel@lists.freedesktop.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.