Skip to contentSkip to conversation

fs/userfaultfd: No need for gotos

PATCH New Pavel Machek 1 participant 1 message Jun 6, 2020 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fs/userfaultfd: No need for gotos

No need for gotos when all the target does is return. In this case it also avoids redundant variable assignments.

fs/userfaultfd.c +7 -11
index e39fdec8a0b0..860db4fd28dc 100644
@@ -1883,12 +1883,10 @@ static int userfaultfd_api(struct userfaultfd_ctx *ctx,
 	int ret;
 	__u64 features;
 
-	ret = -EINVAL;
 	if (ctx->state != UFFD_STATE_WAIT_API)
-		goto out;
-	ret = -EFAULT;
+		return -EINVAL;
 	if (copy_from_user(&uffdio_api, buf, sizeof(uffdio_api)))
-		goto out;
+		return -EFAULT;
 	features = uffdio_api.features;
 	ret = -EINVAL;
 	if (uffdio_api.api != UFFD_API || (features & ~UFFD_API_FEATURES))
@@ -1899,20 +1897,18 @@ static int userfaultfd_api(struct userfaultfd_ctx *ctx,
 	/* report all available features and ioctls to userland */
 	uffdio_api.features = UFFD_API_FEATURES;
 	uffdio_api.ioctls = UFFD_API_IOCTLS;
-	ret = -EFAULT;
 	if (copy_to_user(buf, &uffdio_api, sizeof(uffdio_api)))
-		goto out;
+		return -EFAULT;
 	ctx->state = UFFD_STATE_RUNNING;
 	/* only enable the requested features for this uffd context */
 	ctx->features = uffd_ctx_features(features);
-	ret = 0;
-out:
-	return ret;
+	return 0;
+
 err_out:
 	memset(&uffdio_api, 0, sizeof(uffdio_api));
 	if (copy_to_user(buf, &uffdio_api, sizeof(uffdio_api)))
-		ret = -EFAULT;
-	goto out;
+		return -EFAULT;
+	return ret;
 }
 
 static long userfaultfd_ioctl(struct file *file, unsigned cmd,
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html