]> granicus.if.org Git - libnl/commitdiff
bridge: change return values for rtnl_link_bridge_get_hwmode()
authorThomas Haller <thaller@redhat.com>
Sat, 24 Sep 2016 12:42:57 +0000 (14:42 +0200)
committerThomas Haller <thaller@redhat.com>
Sat, 24 Sep 2016 12:43:01 +0000 (14:43 +0200)
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 <thaller@redhat.com>
lib/route/link/bridge.c

index a63a3efbd30ba01c57b436a9bfa8a89802f9a2dc..b9d05bc45580bb8f8a4b1330385cc588cac86dbe 100644 (file)
@@ -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;
 }
 
 /**