tipc: Cleanup tipc_nl_bearer_add() error paths
authorShigeru Yoshida <syoshida@redhat.com>
Tue, 13 Feb 2024 13:40:58 +0000 (22:40 +0900)
committerPaolo Abeni <pabeni@redhat.com>
Thu, 15 Feb 2024 12:18:19 +0000 (13:18 +0100)
Consolidate the error paths of tipc_nl_bearer_add() under the common label
if the function holds rtnl_lock.

Signed-off-by: Shigeru Yoshida <syoshida@redhat.com>
Reviewed-by: Tung Nguyen <tung.q.nguyen@dektech.com.au>
Link: https://lore.kernel.org/r/20240213134058.386123-1-syoshida@redhat.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
net/tipc/bearer.c

index 878415c43527615801186d79a6c0c73b62bf5750..5a526ebafeb4b7b50e15dd22872079c1a5194f36 100644 (file)
@@ -1079,30 +1079,27 @@ int tipc_nl_bearer_add(struct sk_buff *skb, struct genl_info *info)
        rtnl_lock();
        b = tipc_bearer_find(net, name);
        if (!b) {
-               rtnl_unlock();
                NL_SET_ERR_MSG(info->extack, "Bearer not found");
-               return -EINVAL;
+               err = -EINVAL;
+               goto out;
        }
 
 #ifdef CONFIG_TIPC_MEDIA_UDP
        if (attrs[TIPC_NLA_BEARER_UDP_OPTS]) {
                if (b->media->type_id != TIPC_MEDIA_TYPE_UDP) {
-                       rtnl_unlock();
                        NL_SET_ERR_MSG(info->extack, "UDP option is unsupported");
-                       return -EINVAL;
+                       err = -EINVAL;
+                       goto out;
                }
 
                err = tipc_udp_nl_bearer_add(b,
                                             attrs[TIPC_NLA_BEARER_UDP_OPTS]);
-               if (err) {
-                       rtnl_unlock();
-                       return err;
-               }
        }
 #endif
+out:
        rtnl_unlock();
 
-       return 0;
+       return err;
 }
 
 int __tipc_nl_bearer_set(struct sk_buff *skb, struct genl_info *info)