diff --git a/kernel/perf_counter.c b/kernel/perf_counter.c
index d7cbc579fc8016603f0d0644c339a470224ad0b9..a67a1dc3cfa3858c0ca969d1feea2f5605fb331b 100644
--- a/kernel/perf_counter.c
+++ b/kernel/perf_counter.c
@@ -4171,6 +4171,7 @@ static int perf_copy_attr(struct perf_counter_attr __user *uattr,
 			if (val)
 				goto err_size;
 		}
+		size = sizeof(*attr);
 	}
 
 	ret = copy_from_user(attr, uattr, size);