diff
--- a/original.c
+++ b/original.c
@@ -42,7 +42,13 @@
 32 			if (!lower) {
 38 		if (mas.last > max) {
 42 			upper = kmemdup(&entry[max + 1],
-			if (max >= mas.last) {
-				// Handle error: max is out of bounds 
-				return -EINVAL; 
+			// Calculate the size to be copied
+			size_t copy_size = (mas.last - (max + 1)) * sizeof(*entry); 
+
+			// Allocate memory for upper
+			upper = kmalloc(copy_size);
+			if (!upper) {
+				// Handle memory allocation failure
+				return -ENOMEM; 
 			}
+			memcpy(upper, &entry[max + 1], copy_size);
 

