From: Thomas Haller Date: Sat, 24 Sep 2016 12:42:57 +0000 (+0200) Subject: bridge: change return values for rtnl_link_bridge_get_hwmode() X-Git-Tag: libnl3_2_29rc1~17^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f55cd5d75f552e7ddadcee0a0ba6a2f33a8f5a48;p=libnl bridge: change return values for rtnl_link_bridge_get_hwmode() Unfortunately, libnl3 is rather inconsistent about the getters. - some return the value directly, and don't have a dedicated error return value. - some don't check whether the attribute was set and just return the default value - some fail with -NLE_INVAL or -NLE_NOATTR if the value is unset. I think the best pattern is to fail if the attribue is unset. However, the return value should be negative to indicate an error, while 0 should mean success. Signed-off-by: Thomas Haller --- diff --git a/lib/route/link/bridge.c b/lib/route/link/bridge.c index a63a3ef..b9d05bc 100644 --- a/lib/route/link/bridge.c +++ b/lib/route/link/bridge.c @@ -766,12 +766,13 @@ int rtnl_link_bridge_set_self(struct rtnl_link *link) /** * Get hardware mode - * @arg link Link object of type bridge + * @arg link Link object of type bridge + * @arg hwmode Output argument. * * @see rtnl_link_bridge_set_hwmode() * - * @return 1 and set hwmode if hardware mode is present - * @return 0 if hardware mode is not present + * @return 0 if hardware mode is present and returned in hwmode + * @return -NLE_NOATTR if hardware mode is not present * @return -NLE_OPNOTSUP Link is not a bridge */ int rtnl_link_bridge_get_hwmode(struct rtnl_link *link, uint16_t *hwmode) @@ -780,11 +781,11 @@ int rtnl_link_bridge_get_hwmode(struct rtnl_link *link, uint16_t *hwmode) IS_BRIDGE_LINK_ASSERT(link); - if (bd->ce_mask & BRIDGE_ATTR_HWMODE) { - *hwmode = bd->b_hwmode; - return 1; - } else - return 0; + if (!(bd->ce_mask & BRIDGE_ATTR_HWMODE)) + return -NLE_NOATTR; + + *hwmode = bd->b_hwmode; + return 0; } /**