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 <[email protected]> --- CC: Ian Jackson <[email protected]> CC: Wei Liu <[email protected]> CC: Anthony PERARD <[email protected]> --- 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
