From patchwork Fri Jun 17 07:54:23 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 70287 Delivered-To: patch@linaro.org Received: by 10.140.28.4 with SMTP id 4csp153609qgy; Fri, 17 Jun 2016 00:54:57 -0700 (PDT) X-Received: by 10.66.255.7 with SMTP id am7mr987544pad.75.1466150085847; Fri, 17 Jun 2016 00:54:45 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id un5si42494297pab.174.2016.06.17.00.54.45; Fri, 17 Jun 2016 00:54:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-samsung-soc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-samsung-soc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-samsung-soc-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755323AbcFQHyo (ORCPT + 4 others); Fri, 17 Jun 2016 03:54:44 -0400 Received: from mailout3.w1.samsung.com ([210.118.77.13]:61768 "EHLO mailout3.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755044AbcFQHyo (ORCPT ); Fri, 17 Jun 2016 03:54:44 -0400 Received: from eucpsbgm1.samsung.com (unknown [203.254.199.244]) by mailout3.w1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0O8W0053GON4GA10@mailout3.w1.samsung.com> for linux-samsung-soc@vger.kernel.org; Fri, 17 Jun 2016 08:54:40 +0100 (BST) X-AuditID: cbfec7f4-f796c6d000001486-38-5763acc0f9b3 Received: from eusync1.samsung.com ( [203.254.199.211]) by eucpsbgm1.samsung.com (EUCPMTA) with SMTP id 26.FF.05254.0CCA3675; Fri, 17 Jun 2016 08:54:40 +0100 (BST) Received: from AMDC2765.digital.local ([106.116.147.25]) by eusync1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0O8W00AVTOMWCT10@eusync1.samsung.com>; Fri, 17 Jun 2016 08:54:40 +0100 (BST) From: Marek Szyprowski To: dri-devel@lists.freedesktop.org, linux-samsung-soc@vger.kernel.org Cc: Marek Szyprowski , Inki Dae , Joonyoung Shim , Seung-Woo Kim , Andrzej Hajda , Krzysztof Kozlowski , Bartlomiej Zolnierkiewicz Subject: [PATCH v2 1/5] drm/exynos: iommu: move dma_params configuration code to separate functions Date: Fri, 17 Jun 2016 09:54:23 +0200 Message-id: <1466150067-8065-2-git-send-email-m.szyprowski@samsung.com> X-Mailer: git-send-email 1.9.1 In-reply-to: <1466150067-8065-1-git-send-email-m.szyprowski@samsung.com> References: <1466150067-8065-1-git-send-email-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprCLMWRmVeSWpSXmKPExsVy+t/xy7oH1iSHG7z9LGBxa905VouNM9az Wlz5+p7NYtL9CSwWL+5dZLF4/cLQYsb5fUwWa4/cZbeYMfklmwOnx/3u40wefVtWMXp83iQX wBzFZZOSmpNZllqkb5fAldE3ZzVbwVKhimPfv7I3MK7n72Lk5JAQMJH4enwZG4QtJnHh3nog m4tDSGApo8T0dVdZIJwmJon/l5Ywg1SxCRhKdL3tAusQEXCTaDo8kxWkiFlgC5NE+66NTCAJ YYFUicmtz8AaWARUJVatOM8CYvMKuEtseDyPGWKdnMTJY5NZQWxOAQ+Jh/t7GEFsIaCaueeX skxg5F3AyLCKUTS1NLmgOCk911CvODG3uDQvXS85P3cTIySsvuxgXHzM6hCjAAejEg/vCtHk cCHWxLLiytxDjBIczEoivIyrgEK8KYmVValF+fFFpTmpxYcYpTlYlMR55+56HyIkkJ5Ykpqd mlqQWgSTZeLglGpgVGoKE/q46SLL+q3LGHeve6u8e9ccc4V4iQsfPuudtHsUusjg16cvd64s Kz+2t8vyb5tX+tqnl2y2rjXRlbNmulDX/fZNnaclj3Rjy/TdaoqHWa9HdFXxn/ZSueM0c1PA YZ3o3w5Bkh47ROK+lUxi2CNlWvrX+ELGu9d3ax6vTgmaMeNmj5/3KiWW4oxEQy3mouJEAI/B IyknAgAA Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org 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. Signed-off-by: Marek Szyprowski --- drivers/gpu/drm/exynos/exynos_drm_iommu.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html 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); }