All of lore.kernel.org
 help / color / mirror / Atom feed
From: Inki Dae <inki.dae@samsung.com>
To: Marek Szyprowski <m.szyprowski@samsung.com>,
	dri-devel@lists.freedesktop.org,
	linux-samsung-soc@vger.kernel.org
Cc: Andrzej Hajda <a.hajda@samsung.com>,
	Krzysztof Kozlowski <k.kozlowski@samsung.com>,
	Seung-Woo Kim <sw0312.kim@samsung.com>,
	Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
Subject: Re: [PATCH v2 1/5] drm/exynos: iommu: move dma_params configuration code to separate functions
Date: Fri, 08 Jul 2016 17:15:22 +0900	[thread overview]
Message-ID: <577F611A.6070500@samsung.com> (raw)
In-Reply-To: <1466150067-8065-2-git-send-email-m.szyprowski@samsung.com>

Hi Marek,

2016년 06월 17일 16:54에 Marek Szyprowski 이(가) 쓴 글:
> Move code for managing DMA max segment size parameter to separate
> functions. This patch also replaces devm_kzalloc() with kzalloc() and
> adds proper kfree call. devm_kzalloc() cannot be used for dma_params
> structure, because it will be freed on driver remove not on device
> release. This means in case of Exynos DRM being compiled as module and
> loaded 2 times, a user-after-free issue will happen.

Picked this patch series up.

Thanks,
Inki Dae

> 
> Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
> ---
>  drivers/gpu/drm/exynos/exynos_drm_iommu.c | 28 ++++++++++++++++++++++------
>  1 file changed, 22 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/gpu/drm/exynos/exynos_drm_iommu.c b/drivers/gpu/drm/exynos/exynos_drm_iommu.c
> index 7ca09ee19656..1e82529e0c41 100644
> --- a/drivers/gpu/drm/exynos/exynos_drm_iommu.c
> +++ b/drivers/gpu/drm/exynos/exynos_drm_iommu.c
> @@ -21,6 +21,23 @@
>  #include "exynos_drm_drv.h"
>  #include "exynos_drm_iommu.h"
>  
> +static inline int configure_dma_max_seg_size(struct device *dev)
> +{
> +	if (!dev->dma_parms)
> +		dev->dma_parms = kzalloc(sizeof(*dev->dma_parms), GFP_KERNEL);
> +	if (!dev->dma_parms)
> +		return -ENOMEM;
> +
> +	dma_set_max_seg_size(dev, DMA_BIT_MASK(32));
> +	return 0;
> +}
> +
> +static inline void clear_dma_max_seg_size(struct device *dev)
> +{
> +	kfree(dev->dma_parms);
> +	dev->dma_parms = NULL;
> +}
> +
>  /*
>   * drm_create_iommu_mapping - create a mapping structure
>   *
> @@ -80,13 +97,10 @@ int drm_iommu_attach_device(struct drm_device *drm_dev,
>  	if (!priv->mapping)
>  		return 0;
>  
> -	subdrv_dev->dma_parms = devm_kzalloc(subdrv_dev,
> -					sizeof(*subdrv_dev->dma_parms),
> -					GFP_KERNEL);
> -	if (!subdrv_dev->dma_parms)
> -		return -ENOMEM;
>  
> -	dma_set_max_seg_size(subdrv_dev, 0xffffffffu);
> +	ret = configure_dma_max_seg_size(subdrv_dev);
> +	if (ret)
> +		return ret;
>  
>  	if (subdrv_dev->archdata.mapping)
>  		arm_iommu_detach_device(subdrv_dev);
> @@ -94,6 +108,7 @@ int drm_iommu_attach_device(struct drm_device *drm_dev,
>  	ret = arm_iommu_attach_device(subdrv_dev, priv->mapping);
>  	if (ret < 0) {
>  		DRM_DEBUG_KMS("failed iommu attach.\n");
> +		clear_dma_max_seg_size(subdrv_dev);
>  		return ret;
>  	}
>  
> @@ -119,4 +134,5 @@ void drm_iommu_detach_device(struct drm_device *drm_dev,
>  		return;
>  
>  	arm_iommu_detach_device(subdrv_dev);
> +	clear_dma_max_seg_size(subdrv_dev);
>  }
> 
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  reply	other threads:[~2016-07-08  8:15 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-17  7:54 [PATCH v2 0/5] Exynos DRM: add support for ARM 64bit arch with IOMMU Marek Szyprowski
2016-06-17  7:54 ` [PATCH v2 1/5] drm/exynos: iommu: move dma_params configuration code to separate functions Marek Szyprowski
2016-07-08  8:15   ` Inki Dae [this message]
2016-06-17  7:54 ` [PATCH v2 2/5] drm/exynos: iommu: add a check if all sub-devices have iommu controller Marek Szyprowski
2016-06-17  7:54 ` [PATCH v2 3/5] drm/exynos: iommu: remove unused entries from exynos_drm_private strcuture Marek Szyprowski
2016-06-17  7:54 ` [PATCH v2 4/5] drm/exynos: iommu: move ARM specific code to exynos_drm_iommu.h Marek Szyprowski
2016-06-17  7:54 ` [PATCH v2 5/5] drm/exynos: iommu: add support for ARM64 specific code for IOMMU glue Marek Szyprowski

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=577F611A.6070500@samsung.com \
    --to=inki.dae@samsung.com \
    --cc=a.hajda@samsung.com \
    --cc=b.zolnierkie@samsung.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=k.kozlowski@samsung.com \
    --cc=linux-samsung-soc@vger.kernel.org \
    --cc=m.szyprowski@samsung.com \
    --cc=sw0312.kim@samsung.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 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.