platform: cleanup nm_platform_link_get_address() to return-early
Avoid nested if-blocks, and instead check conditions and return early.
This commit is contained in:
@@ -1340,30 +1340,26 @@ gconstpointer
|
|||||||
nm_platform_link_get_address (NMPlatform *self, int ifindex, size_t *length)
|
nm_platform_link_get_address (NMPlatform *self, int ifindex, size_t *length)
|
||||||
{
|
{
|
||||||
const NMPlatformLink *pllink;
|
const NMPlatformLink *pllink;
|
||||||
gconstpointer a = NULL;
|
|
||||||
guint8 l = 0;
|
|
||||||
|
|
||||||
_CHECK_SELF (self, klass, NULL);
|
_CHECK_SELF (self, klass, NULL);
|
||||||
|
|
||||||
if (length)
|
|
||||||
*length = 0;
|
|
||||||
|
|
||||||
g_return_val_if_fail (ifindex > 0, NULL);
|
g_return_val_if_fail (ifindex > 0, NULL);
|
||||||
|
|
||||||
pllink = nm_platform_link_get (self, ifindex);
|
pllink = nm_platform_link_get (self, ifindex);
|
||||||
if (pllink && pllink->addr.len > 0) {
|
|
||||||
if (pllink->addr.len > NM_UTILS_HWADDR_LEN_MAX) {
|
if ( !pllink
|
||||||
if (length)
|
|| pllink->addr.len <= 0) {
|
||||||
*length = 0;
|
NM_SET_OUT (length, 0);
|
||||||
g_return_val_if_reached (NULL);
|
return NULL;
|
||||||
}
|
|
||||||
a = pllink->addr.data;
|
|
||||||
l = pllink->addr.len;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (length)
|
if (pllink->addr.len > NM_UTILS_HWADDR_LEN_MAX) {
|
||||||
*length = l;
|
NM_SET_OUT (length, 0);
|
||||||
return a;
|
g_return_val_if_reached (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
NM_SET_OUT (length, pllink->addr.len);
|
||||||
|
return pllink->addr.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user