public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] utsname: Optimize clone_uts_ns()
@ 2024-01-15  6:11 Li kunyu
  2024-01-15  6:54 ` Al Viro
  0 siblings, 1 reply; 2+ messages in thread
From: Li kunyu @ 2024-01-15  6:11 UTC (permalink / raw)
  To: linux-kernel; +Cc: Li kunyu

Optimize the err variable assignment location so that the err variable
is manually modified when an error occurs.

Signed-off-by: Li kunyu <kunyu@nfschina.com>
---
 kernel/utsname.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/kernel/utsname.c b/kernel/utsname.c
index b1ac3ca870f24..f55568e00927c 100644
--- a/kernel/utsname.c
+++ b/kernel/utsname.c
@@ -49,15 +49,17 @@ static struct uts_namespace *clone_uts_ns(struct user_namespace *user_ns,
 	struct ucounts *ucounts;
 	int err;
 
-	err = -ENOSPC;
 	ucounts = inc_uts_namespaces(user_ns);
-	if (!ucounts)
+	if (!ucounts) {
+		err = -ENOSPC;
 		goto fail;
+	}
 
-	err = -ENOMEM;
 	ns = create_uts_ns();
-	if (!ns)
+	if (!ns) {
+		err = -ENOMEM;
 		goto fail_dec;
+	}
 
 	err = ns_alloc_inum(&ns->ns);
 	if (err)
-- 
2.18.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] utsname: Optimize clone_uts_ns()
  2024-01-15  6:11 [PATCH] utsname: Optimize clone_uts_ns() Li kunyu
@ 2024-01-15  6:54 ` Al Viro
  0 siblings, 0 replies; 2+ messages in thread
From: Al Viro @ 2024-01-15  6:54 UTC (permalink / raw)
  To: Li kunyu; +Cc: linux-kernel

On Mon, Jan 15, 2024 at 02:11:27PM +0800, Li kunyu wrote:
> Optimize the err variable assignment location so that the err variable
> is manually modified when an error occurs.

First of all, this is *not* an optimization in any meaningful sense -
compiler is perfectly capable to shift those assignments (from either
form) and choose whatever it prefers.

Incidentally, it might end up lifting the store out of if - it's
entirely possible that
	r1 = v
	flag = (r2 == 0)
	if flag goto fail
is better than
	flag = (r2 == 0)
	if flag goto l
	...
l:
	r1 = v
	goto fail
provided that assignment to r1 and checking r2 can be done in parallel
and that's assuming that it will figure out that branch is unlikely.

Readability might be a good reason; optimization... no.  Leave that to
compiler; it will override your choice here anyway.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-01-15  6:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-15  6:11 [PATCH] utsname: Optimize clone_uts_ns() Li kunyu
2024-01-15  6:54 ` Al Viro

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox