diff mbox series

[1/1] staging: ion: Prevent incorrect reference counting behavour

Message ID 20220425155154.2742426-1-lee.jones@linaro.org
State New
Headers show
Series [1/1] staging: ion: Prevent incorrect reference counting behavour | expand

Commit Message

Lee Jones April 25, 2022, 3:51 p.m. UTC
Supply additional check in order to prevent unexpected results.

Fixes: b892bf75b2034 ("ion: Switch ion to use dma-buf")
Suggested-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
---
This is a forward-port from linux-4.4.y and linux-4.9.y.

It has never been upstream.

Please apply to v4.14 through v5.10.

 drivers/staging/android/ion/ion.c | 3 +++
 1 file changed, 3 insertions(+)
diff mbox series

Patch

diff --git a/drivers/staging/android/ion/ion.c b/drivers/staging/android/ion/ion.c
index e1fe03ceb7f13..e6d4a3ee6cda5 100644
--- a/drivers/staging/android/ion/ion.c
+++ b/drivers/staging/android/ion/ion.c
@@ -114,6 +114,9 @@  static void *ion_buffer_kmap_get(struct ion_buffer *buffer)
 	void *vaddr;
 
 	if (buffer->kmap_cnt) {
+		if (buffer->kmap_cnt == INT_MAX)
+			return ERR_PTR(-EOVERFLOW);
+
 		buffer->kmap_cnt++;
 		return buffer->vaddr;
 	}