From c5322608a5b78d55381fc87985304ec515cd723d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 24 Apr 2019 10:54:44 +0200 Subject: [PATCH 1/2] core: adjust unit_get_ancestor_memory_{low,min}() to work with units which don't have a CGroupContext Coverity doesn't like the fact that unit_get_cgroup_context() returns NULL for unit types that don't have a CGroupContext. We don't expect to call those functions with such unit types, so this isn't an immediate problem, but we can make things more robust by handling this case. CID #1400683, #1400684. --- src/core/cgroup.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/core/cgroup.c b/src/core/cgroup.c index 946fab24c2..32d5605899 100644 --- a/src/core/cgroup.c +++ b/src/core/cgroup.c @@ -403,15 +403,12 @@ int cgroup_add_device_allow(CGroupContext *c, const char *dev, const char *mode) assert(u); \ \ c = unit_get_cgroup_context(u); \ - \ - if (c->entry##_set) \ + if (c && c->entry##_set) \ return c->entry; \ \ - while (UNIT_ISSET(u->slice)) { \ - u = UNIT_DEREF(u->slice); \ + while ((u = UNIT_DEREF(u->slice))) { \ c = unit_get_cgroup_context(u); \ - \ - if (c->default_##entry##_set) \ + if (c && c->default_##entry##_set) \ return c->default_##entry; \ } \ \ From 4232cf049f5f41f47f2b8e8ad6ca8c66bf7c4f51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 25 Apr 2019 10:41:59 +0200 Subject: [PATCH 2/2] network: drop "return 1" when the return value is ignored by all callers The reader is tricked into thinking that this has some meaning... --- src/network/networkd-link.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c index d3928e2862..ec2190fd13 100644 --- a/src/network/networkd-link.c +++ b/src/network/networkd-link.c @@ -3365,7 +3365,7 @@ static int link_initialized_and_synced(Link *link) { /* We may get called either from the asynchronous netlink callback, * or directly for link_add() if running in a container. See link_add(). */ if (!IN_SET(link->state, LINK_STATE_PENDING, LINK_STATE_INITIALIZED)) - return 1; + return 0; log_link_debug(link, "Link state is up-to-date"); link_set_state(link, LINK_STATE_INITIALIZED); @@ -3383,7 +3383,7 @@ static int link_initialized_and_synced(Link *link) { &link->mac, &network); if (r == -ENOENT) { link_enter_unmanaged(link); - return 1; + return 0; } else if (r == 0 && network->unmanaged) { link_enter_unmanaged(link); return 0; @@ -3420,7 +3420,7 @@ static int link_initialized_and_synced(Link *link) { if (r < 0) return r; - return 1; + return 0; } static int link_initialized_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {