From patchwork Mon May 23 10:50:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 9131447 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 939BB607D5 for ; Mon, 23 May 2016 10:51:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8579C28221 for ; Mon, 23 May 2016 10:51:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7A3DE28234; Mon, 23 May 2016 10:51:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D10592822F for ; Mon, 23 May 2016 10:51:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752476AbcEWKu7 (ORCPT ); Mon, 23 May 2016 06:50:59 -0400 Received: from mailout4.w1.samsung.com ([210.118.77.14]:39065 "EHLO mailout4.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752205AbcEWKu6 (ORCPT ); Mon, 23 May 2016 06:50:58 -0400 Received: from eucpsbgm1.samsung.com (unknown [203.254.199.244]) by mailout4.w1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0O7M00FJ3M4VH560@mailout4.w1.samsung.com> for linux-samsung-soc@vger.kernel.org; Mon, 23 May 2016 11:50:55 +0100 (BST) X-AuditID: cbfec7f4-f796c6d000001486-13-5742e08f3768 Received: from eusync1.samsung.com ( [203.254.199.211]) by eucpsbgm1.samsung.com (EUCPMTA) with SMTP id B3.72.05254.F80E2475; Mon, 23 May 2016 11:50:55 +0100 (BST) Received: from amdc1339.digital.local ([106.116.147.30]) by eusync1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0O7M00JPJM4ORQ10@eusync1.samsung.com>; Mon, 23 May 2016 11:50:55 +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 1/5] drm/exynos: iommu: move dma_params configuration code to separate functions Date: Mon, 23 May 2016 12:50:40 +0200 Message-id: <1464000644-12227-2-git-send-email-m.szyprowski@samsung.com> X-Mailer: git-send-email 1.9.2 In-reply-to: <1464000644-12227-1-git-send-email-m.szyprowski@samsung.com> References: <1464000644-12227-1-git-send-email-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprMLMWRmVeSWpSXmKPExsVy+t/xy7r9D5zCDV5tZ7e4te4cq8XGGetZ La58fc9mMen+BBaLF/cusli8fmFoMeP8PiaLtUfuslvMmPySzYHT4373cSaPvi2rGD0+b5IL YI7isklJzcksSy3St0vgynjSe4KtYLZQxZsT75gbGJfydzFyckgImEg8OzqBBcIWk7hwbz1b FyMXh5DAUkaJrzfvM0E4TUwSVxd2gVWxCRhKdL3tYgOxRQTcJJoOz2QFKWIW2MIk0b5rIxNI QlggSeL2iiXsIDaLgKrEvGuvwRp4BTwk3rRfYoRYJyfx/+UKsHpOAU+J13PmAdVwAG3zkPj1 ImYCI+8CRoZVjKKppckFxUnpuYZ6xYm5xaV56XrJ+bmbGCFB9WUH4+JjVocYBTgYlXh4NzA6 hQuxJpYVV+YeYpTgYFYS4TW8DxTiTUmsrEotyo8vKs1JLT7EKM3BoiTOO3fX+xAhgfTEktTs 1NSC1CKYLBMHp1QD47TW+8JaR1LOTtrxKexxkm5kfNmnaOlmySXsm9Un7JQVrr5oseWBqtPb az67P2dHfU4LmGOx7Aj7howze1fJRq9or794PfTl8dfRxdM2P9cWPD13Sce8b+b7NQXyrF+E nr7lL8TrcmKTldHeNdKP4+Q7V2ydu15kjrqm2mIxx/37j7De6reelKPEUpyRaKjFXFScCACd 0IdoJgIAAA== Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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(-) diff --git a/drivers/gpu/drm/exynos/exynos_drm_iommu.c b/drivers/gpu/drm/exynos/exynos_drm_iommu.c index 7ca09ee..1e82529 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); }