mirror of
https://github.com/Divested-Mobile/DivestOS-Build.git
synced 2024-12-29 01:16:26 -05:00
51 lines
1.3 KiB
Diff
51 lines
1.3 KiB
Diff
diff --git a/drivers/staging/android/ion/ion.c b/drivers/staging/android/ion/ion.c
|
|
index cc1b3bf..48b6b86 100644
|
|
--- a/drivers/staging/android/ion/ion.c
|
|
+++ b/drivers/staging/android/ion/ion.c
|
|
@@ -16,6 +16,8 @@
|
|
*
|
|
*/
|
|
|
|
+#include <linux/atomic.h>
|
|
+#include <linux/err.h>
|
|
#include <linux/file.h>
|
|
#include <linux/freezer.h>
|
|
#include <linux/fs.h>
|
|
@@ -400,6 +402,15 @@
|
|
kref_get(&handle->ref);
|
|
}
|
|
|
|
+/* Must hold the client lock */
|
|
+static struct ion_handle* ion_handle_get_check_overflow(struct ion_handle *handle)
|
|
+{
|
|
+ if (atomic_read(&handle->ref.refcount) + 1 == 0)
|
|
+ return ERR_PTR(-EOVERFLOW);
|
|
+ ion_handle_get(handle);
|
|
+ return handle;
|
|
+}
|
|
+
|
|
int ion_handle_put_nolock(struct ion_handle *handle)
|
|
{
|
|
int ret;
|
|
@@ -445,9 +456,9 @@
|
|
|
|
handle = idr_find(&client->idr, id);
|
|
if (handle)
|
|
- ion_handle_get(handle);
|
|
+ return ion_handle_get_check_overflow(handle);
|
|
|
|
- return handle ? handle : ERR_PTR(-EINVAL);
|
|
+ return ERR_PTR(-EINVAL);
|
|
}
|
|
|
|
struct ion_handle *ion_handle_get_by_id(struct ion_client *client,
|
|
@@ -1339,7 +1350,7 @@
|
|
/* if a handle exists for this buffer just take a reference to it */
|
|
handle = ion_handle_lookup(client, buffer);
|
|
if (!IS_ERR(handle)) {
|
|
- ion_handle_get(handle);
|
|
+ handle = ion_handle_get_check_overflow(handle);
|
|
mutex_unlock(&client->lock);
|
|
goto end;
|
|
}
|