nfc: llcp: use centralized exiting of bind on errors
authorKrzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
Wed, 2 Mar 2022 19:25:20 +0000 (20:25 +0100)
committerDavid S. Miller <davem@davemloft.net>
Thu, 3 Mar 2022 10:43:37 +0000 (10:43 +0000)
Coding style encourages centralized exiting of functions, so rewrite
llcp_sock_bind() error paths to use such pattern.  This reduces the
duplicated cleanup code, make success path visually shorter and also
cleans up the errors in proper order (in reversed way from
initialization).

No functional impact expected.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/nfc/llcp_sock.c

index fdf0856..c9d5c42 100644 (file)
@@ -108,21 +108,13 @@ static int llcp_sock_bind(struct socket *sock, struct sockaddr *addr, int alen)
                                          llcp_sock->service_name_len,
                                          GFP_KERNEL);
        if (!llcp_sock->service_name) {
-               nfc_llcp_local_put(llcp_sock->local);
-               llcp_sock->local = NULL;
-               llcp_sock->dev = NULL;
                ret = -ENOMEM;
-               goto put_dev;
+               goto sock_llcp_put_local;
        }
        llcp_sock->ssap = nfc_llcp_get_sdp_ssap(local, llcp_sock);
        if (llcp_sock->ssap == LLCP_SAP_MAX) {
-               nfc_llcp_local_put(llcp_sock->local);
-               llcp_sock->local = NULL;
-               kfree(llcp_sock->service_name);
-               llcp_sock->service_name = NULL;
-               llcp_sock->dev = NULL;
                ret = -EADDRINUSE;
-               goto put_dev;
+               goto free_service_name;
        }
 
        llcp_sock->reserved_ssap = llcp_sock->ssap;
@@ -132,6 +124,19 @@ static int llcp_sock_bind(struct socket *sock, struct sockaddr *addr, int alen)
        pr_debug("Socket bound to SAP %d\n", llcp_sock->ssap);
 
        sk->sk_state = LLCP_BOUND;
+       nfc_put_device(dev);
+       release_sock(sk);
+
+       return 0;
+
+free_service_name:
+       kfree(llcp_sock->service_name);
+       llcp_sock->service_name = NULL;
+
+sock_llcp_put_local:
+       nfc_llcp_local_put(llcp_sock->local);
+       llcp_sock->local = NULL;
+       llcp_sock->dev = NULL;
 
 put_dev:
        nfc_put_device(dev);