Skip to contentSkip to conversation

staging: android: ion: Fix error handling in ion_query_heaps()

PATCH New Dan Carpenter 1 participant 1 message Oct 13, 2016

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

PATCH v2 1/1 staging: android: ion: Fix error handling in ion_query_heaps()

If the copy_to_user() fails we should unlock and return directly without updating "cnt". Also the return value should be -EFAULT instead of the number of bytes remaining.

Fixes 02b23803c6af ("staging: android: ion: Add ioctl to query available heaps")

---
v2: a more complete fix

drivers/staging/android/ion/ion.c +4 -2
index 396ded5..209a8f7 100644
@@ -1187,8 +1187,10 @@ int ion_query_heaps(struct ion_client *client, struct ion_heap_query *query)
 		hdata.type = heap->type;
 		hdata.heap_id = heap->id;
 
-		ret = copy_to_user(&buffer[cnt],
-				   &hdata, sizeof(hdata));
+		if (copy_to_user(&buffer[cnt], &hdata, sizeof(hdata))) {
+			ret = -EFAULT;
+			goto out;
+		}
 
 		cnt++;
 		if (cnt >= max_cnt)