Skip to contentSkip to conversation

Add return value checks in the drm-dmabuf

PATCH Applied Subash Patel 2 participants 5 messages Jun 25, 2012 – Jun 27, 2012

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover Add return value checks in the drm-dmabuf

From: Subash Patel <[email protected]>

This patch series is split and re-send of my original patch, after request from Inki Dae.

Below two patches add the required error checks in drm dmabuf when the system fails to allocate pages for the scatter-gather. This is very rare situation, and occurs when the system is under memory pressure.

Scatter-gather asks for memory using sg_kmalloc() and this can return no memory. Without below return value checks, the code will crash the system due to invalid pointer access.

Subash Patel (2):
DRM: Exynos: return NULL if exynos_pages_to_sg fails
DRM: Exynos: check for null in return value of
dma_buf_map_attachment()

 drivers/gpu/drm/exynos/exynos_drm_dmabuf.c |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH 1/2 DRM: Exynos: return NULL if exynos_pages_to_sg fails

From: Subash Patel <[email protected]>

exynos_pages_to_sg() internally calls sg_kmalloc() which can return no pages when the system is under high memory crunch. One such instance is chromeos-install in the chromeos. This patch adds check for the return value of the function in subject to return NULL on failure.

---
 drivers/gpu/drm/exynos/exynos_drm_dmabuf.c |    4 ++++
 1 file changed, 4 insertions(+)
drivers/gpu/drm/exynos/exynos_drm_dmabuf.c +4 -0
index 97325c1..52cf761 100644
@@ -87,6 +87,10 @@ static struct sg_table *
 	npages = buf->size / buf->page_size;
 
 	sgt = exynos_pages_to_sg(buf->pages, npages, buf->page_size);
+	if (!sgt) {
+		DRM_DEBUG_PRIME("exynos_pages_to_sg returned NULL!\n");
+		goto err_unlock;
+	}
 	nents = dma_map_sg(attach->dev, sgt->sgl, sgt->nents, dir);
 
 	DRM_DEBUG_PRIME("npages = %d buffer size = 0x%lx page_size = 0x%lx\n",
Signature · 1 line
1.7.9.5
maintainer Applied
#2 lore raw

RE: [PATCH 1/2] DRM: Exynos: return NULL if exynos_pages_to_sg fails

Quoted 46 lines

-----Original Message-----
From: Subash Patel [mailto:[email protected]]
Sent: Tuesday, June 26, 2012 3:23 AM
To: [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; Subash Patel; Subash Patel
Subject: [PATCH 1/2] DRM: Exynos: return NULL if exynos_pages_to_sg fails

From: Subash Patel <[email protected]>

exynos_pages_to_sg() internally calls sg_kmalloc() which can return no pages when the system is under high memory crunch. One such instance is chromeos-install in the chromeos. This patch adds check for the return value of the function in subject to return NULL on failure.

---
 drivers/gpu/drm/exynos/exynos_drm_dmabuf.c |    4 ++++
 1 file changed, 4 insertions(+)
drivers/gpu/drm/exynos/exynos_drm_dmabuf.c +4 -0
index 97325c1..52cf761 100644
@@ -87,6 +87,10 @@ static struct sg_table *
 	npages = buf->size / buf->page_size;
 
 	sgt = exynos_pages_to_sg(buf->pages, npages, buf->page_size);
+	if (!sgt) {
+		DRM_DEBUG_PRIME("exynos_pages_to_sg returned NULL!\n");
+		goto err_unlock;
+	}
 	nents = dma_map_sg(attach->dev, sgt->sgl, sgt->nents, dir);
 
 	DRM_DEBUG_PRIME("npages = %d buffer size = 0x%lx page_size =
Quoted 3 lines

0x%lx\n",
--
1.7.9.5

Applied.

Thanks,
Inki Dae

#3 lore raw

PATCH 2/2 DRM: Exynos: check for null in return value of dma_buf_map_attachment()

In reply to Subash Patel

From: Subash Patel <[email protected]>

dma_buf_map_attachment() can return NULL and valid sg as return value. Hence the check for the returned scatter-gather must be using the inline function IS_ERR_OR_NULL() in place of IS_ERR()

---
 drivers/gpu/drm/exynos/exynos_drm_dmabuf.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/exynos/exynos_drm_dmabuf.c +1 -1
index 52cf761..c908a29 100644
@@ -245,7 +245,7 @@ struct drm_gem_object *exynos_dmabuf_prime_import(struct drm_device *drm_dev,
 
 
 	sgt = dma_buf_map_attachment(attach, DMA_BIDIRECTIONAL);
-	if (IS_ERR(sgt)) {
+	if (IS_ERR_OR_NULL(sgt)) {
 		ret = PTR_ERR(sgt);
 		goto err_buf_detach;
 	}
Signature · 1 line
1.7.9.5
maintainer Applied
#4 lore raw

RE: [PATCH 2/2] DRM: Exynos: check for null in return value of dma_buf_map_attachment()

Quoted 44 lines

-----Original Message-----
From: Subash Patel [mailto:[email protected]]
Sent: Tuesday, June 26, 2012 3:23 AM
To: [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; Subash Patel; Subash Patel
Subject: [PATCH 2/2] DRM: Exynos: check for null in return value of dma_buf_map_attachment()

From: Subash Patel <[email protected]>

dma_buf_map_attachment() can return NULL and valid sg as return value. Hence the check for the returned scatter-gather must be using the inline function IS_ERR_OR_NULL() in place of IS_ERR()

---
 drivers/gpu/drm/exynos/exynos_drm_dmabuf.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/exynos/exynos_drm_dmabuf.c +1 -1
index 52cf761..c908a29 100644
@@ -245,7 +245,7 @@ struct drm_gem_object
 *exynos_dmabuf_prime_import(struct drm_device *drm_dev,
 
 
 	sgt = dma_buf_map_attachment(attach, DMA_BIDIRECTIONAL);
-	if (IS_ERR(sgt)) {
+	if (IS_ERR_OR_NULL(sgt)) {
 		ret = PTR_ERR(sgt);
 		goto err_buf_detach;
Quoted 3 lines

}
--
1.7.9.5

Applied.

Thanks,
Inki Dae