All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Xen-devel <xen-devel@lists.xenproject.org>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
	Ian Jackson <iwj@xenproject.org>, Wei Liu <wl@xen.org>,
	Anthony PERARD <anthony.perard@citrix.com>
Subject: [PATCH 2/3] tools/libxl: Simplfy the out path in libxl__domain_get_device_model_uid()
Date: Wed, 17 Feb 2021 16:42:50 +0000	[thread overview]
Message-ID: <20210217164251.11005-3-andrew.cooper3@citrix.com> (raw)
In-Reply-To: <20210217164251.11005-1-andrew.cooper3@citrix.com>

All paths heading towards `out` have rc = 0.  Assert this property.

The intended_uid check is an error path.  Use the err label rather than
falling into subsequent success logic.

With the above two changes, the two `if (!rc)` checks can be dropped.

Now, both remaining tests start with `if (user ...)`.  Combine the two blocks.

No functional change, but far simpler logic to follow.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Ian Jackson <iwj@xenproject.org>
CC: Wei Liu <wl@xen.org>
CC: Anthony PERARD <anthony.perard@citrix.com>
---
 tools/libs/light/libxl_dm.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/tools/libs/light/libxl_dm.c b/tools/libs/light/libxl_dm.c
index 30b3242e57..7843c283ca 100644
--- a/tools/libs/light/libxl_dm.c
+++ b/tools/libs/light/libxl_dm.c
@@ -243,16 +243,17 @@ static int libxl__domain_get_device_model_uid(libxl__gc *gc,
     goto err;
 
 out:
-    /* First, do a root check if appropriate */
-    if (!rc) {
-        if (user && intended_uid == 0) {
+    assert(rc == 0);
+
+    if (user) {
+        /* First, do a root check if appropriate */
+        if (intended_uid == 0) {
             LOGD(ERROR, guest_domid, "intended_uid is 0 (root)!");
             rc = ERROR_INVAL;
+            goto err;
         }
-    }
 
-    /* Then do the final set, if still appropriate */
-    if (!rc && user) {
+        /* Then do the final set. */
         state->dm_runas = user;
         if (kill_by_uid)
             state->dm_kill_uid = GCSPRINTF("%ld", (long)intended_uid);
-- 
2.11.0



  parent reply	other threads:[~2021-02-17 16:43 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-17 16:42 [PATCH for-4.15 0/3] tools/libxl: -Og fixes for libxl__domain_get_device_model_uid() Andrew Cooper
2021-02-17 16:42 ` [PATCH 1/3] tools/libxl: Split out and err paths in libxl__domain_get_device_model_uid() Andrew Cooper
2021-02-17 16:42 ` Andrew Cooper [this message]
2021-02-17 16:42 ` [PATCH 3/3] tools/libxl: Rework invariants " Andrew Cooper
2021-02-17 17:50   ` Ian Jackson
2021-02-17 18:13     ` Andrew Cooper

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210217164251.11005-3-andrew.cooper3@citrix.com \
    --to=andrew.cooper3@citrix.com \
    --cc=anthony.perard@citrix.com \
    --cc=iwj@xenproject.org \
    --cc=wl@xen.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.