From patchwork Wed Jan 19 07:52:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 12717183 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9B505C433FE for ; Wed, 19 Jan 2022 07:53:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352199AbiASHxJ (ORCPT ); Wed, 19 Jan 2022 02:53:09 -0500 Received: from smtp-relay-internal-1.canonical.com ([185.125.188.123]:55272 "EHLO smtp-relay-internal-1.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352181AbiASHxH (ORCPT ); Wed, 19 Jan 2022 02:53:07 -0500 Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id B7FFC3FFDE for ; Wed, 19 Jan 2022 07:53:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1642578785; bh=5w/EAxi3BWNa4bEEDcXXXFqwUZVzXL/jpIlNMT11cAw=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=loNBMorjQGultM2jhX+DevSvczJjc9pHvyw7LW99zlDSs4WbZtDdwv0xWDkwupPqN kNIVEYM3EXkxniRvQzAQOOjE1F0tBZy/XSDOxJk60+B5y26N0Z92VHGvCMFTg5cK3g s3MwhvFFizTLnZyXB1WPb4ABvZ+H08nvW1DP5FRrs5g8OlNmPe8HwU4revuDSpRxLu Oj2WHT+fEZzsTag1S4ii5LGCrzFZogKgOMJdQ3Zput2W175jdplFY94zTlfSlKbui+ J4c3OLMlMczOIeqNT/IMCYgnXlMJGBho9slnZPJTGdkx64rvVrl0ZAof/WfBBelkG5 qM6b3vdMMriIA== Received: by mail-ed1-f70.google.com with SMTP id ej6-20020a056402368600b00402b6f12c3fso1501029edb.8 for ; Tue, 18 Jan 2022 23:53:05 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5w/EAxi3BWNa4bEEDcXXXFqwUZVzXL/jpIlNMT11cAw=; b=lxbURvPb03A6F0GfkSRsEq39MKRqcCQBfJ9OCOM4YWjb8LSyd7jKvhB76ujuI6UgKB p07jtzMfZ/MRWfLSWDuFPnUte9CtlWvt9jjp/QOxU1s7ywLCtUHp79WIV6sUIvkob9Po 7Yu5jYiKAJCbhSjWvawRKVDscr5kCVrhfcqErUjTz7Lq6qAEFhrOsFXpXXPTSh1DRhVh +epBbvP9N7MmlMQ6fZ4BhYPQqDrnwmhQIQLR+4LQhxOkHzKZpgd/knAYYymVDniWscx6 fhcJLmklNh4Xa7WznCfIdKFnSpLpt723fDx9r0uYIt7EW8DqnNBq6r9BzzPuumOdR13M NXyA== X-Gm-Message-State: AOAM530oT8jPokCAgVuUqtzXwwaMSG60TUWJrGTN0HzTkkJSWLOa7zp1 fKegID5snKo71VhPZaDVW/sYRijvBr1eDH5PPZQRmBLMx7skhn+j4cCVF8pRSLTl+H4AWUxJRUF xayMmzug6yxw3A3sEnvz5lqj/e6FcdGk2ZQ== X-Received: by 2002:a05:6402:4244:: with SMTP id g4mr6483609edb.271.1642578785493; Tue, 18 Jan 2022 23:53:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJxYUDYe5Iu0UOqAPwEgNesa55/g4cd+jnk3TlZFlICHhPfLFfLvKw8cfJ2BVa1of970eRb/Ng== X-Received: by 2002:a05:6402:4244:: with SMTP id g4mr6483602edb.271.1642578785369; Tue, 18 Jan 2022 23:53:05 -0800 (PST) Received: from localhost.localdomain (xdsl-188-155-168-84.adslplus.ch. [188.155.168.84]) by smtp.gmail.com with ESMTPSA id w17sm805286edr.68.2022.01.18.23.53.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jan 2022 23:53:04 -0800 (PST) From: Krzysztof Kozlowski To: Krzysztof Kozlowski , "David S. Miller" , Jakub Kicinski , linux-nfc@lists.01.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/6] nfc: llcp: nullify llcp_sock->dev on connect() error paths Date: Wed, 19 Jan 2022 08:52:56 +0100 Message-Id: <20220119075301.7346-2-krzysztof.kozlowski@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220119075301.7346-1-krzysztof.kozlowski@canonical.com> References: <20220119075301.7346-1-krzysztof.kozlowski@canonical.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Nullify the llcp_sock->dev on llcp_sock_connect() error paths, symmetrically to the code llcp_sock_bind(). The non-NULL value of llcp_sock->dev is used in a few places to check whether the socket is still valid. There was no particular issue observed with missing NULL assignment in connect() error path, however a similar case - in the bind() error path - was triggereable. That one was fixed in commit 4ac06a1e013c ("nfc: fix NULL ptr dereference in llcp_sock_getname() after failed connect"), so the change here seems logical as well. Signed-off-by: Krzysztof Kozlowski --- net/nfc/llcp_sock.c | 1 + 1 file changed, 1 insertion(+) diff --git a/net/nfc/llcp_sock.c b/net/nfc/llcp_sock.c index 6cfd30fc0798..d951d4f0c87f 100644 --- a/net/nfc/llcp_sock.c +++ b/net/nfc/llcp_sock.c @@ -764,6 +764,7 @@ static int llcp_sock_connect(struct socket *sock, struct sockaddr *_addr, llcp_sock->local = NULL; put_dev: + llcp_sock->dev = NULL; nfc_put_device(dev); error: From patchwork Wed Jan 19 07:52:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 12717182 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F3AAAC433F5 for ; Wed, 19 Jan 2022 07:53:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352197AbiASHxK (ORCPT ); Wed, 19 Jan 2022 02:53:10 -0500 Received: from smtp-relay-internal-0.canonical.com ([185.125.188.122]:38494 "EHLO smtp-relay-internal-0.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352190AbiASHxI (ORCPT ); Wed, 19 Jan 2022 02:53:08 -0500 Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 959993F1E9 for ; Wed, 19 Jan 2022 07:53:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1642578787; bh=hsf4OWBu8gj1asXGvoAW6jPDrjEeTDLfH6tpVV1berI=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=VZjG057EcIilUeAT/ICp+xIDLWs40XjCvGvkbY3rGpVuIXD6N2lWRsOeQES+uaQH3 d35RFradZII3dl2jjqwd983JBN6V0iFi/6E+mxtOjLBOUmK5lNfGxSKrstP/3nAn6W YbY/bACj/l9mEhApOsxBsf0pva+LHvMtTfVkHYkh03hQvvuB+qJLQfPBOeCByN4fzu l4bJdiM98velGcUJxf4cwKSAWQJLCo4rDRBGglJPJZVNuFLJ7bTE1CPW3APAOVCrxJ xMGiREZDknqgPIvkOoL0hdGOyLzifOomlLDmFiVaqAS4yiKnxTWcV1ESiYDHVxugTB GNEO1pJ32+DSw== Received: by mail-ed1-f72.google.com with SMTP id l14-20020aa7cace000000b003f7f8e1cbbdso1452704edt.20 for ; Tue, 18 Jan 2022 23:53:07 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hsf4OWBu8gj1asXGvoAW6jPDrjEeTDLfH6tpVV1berI=; b=5sDF0enLNCawm68W7DQO6AYPlPrZ8MVZk6extj1cGaz2z9Nwk6jGRzYL4BUudsWfDk /rNZ611yE9GH55A7JUuFDpRZd3YhcMrEiiNENHNho0aRbxd4ZB95EZNvg2QUbD5WCeJ9 CSADC/MTgfJz+37RHeIf8QkwNakGfKDAmOqKX23bxw6lp/mVbT7AGtXrV4lbjvMNfDJd INYJVWYr/+H/eZBHLzI8PE+Pn11DvXi6gKC0TC5NvaNvLpjJlatX2bksA4KQSVprlGEb 0Emmc8l7z9pKCSzX0s+6AzA8wN5IufSsPrmHCf8Z+sD0Vi+qLncX5uXmmMtQjVpVKSBL J9OQ== X-Gm-Message-State: AOAM533qrqnUVQUIEDErc2SbmRbMnnOeOAukWQ4D83Ef2abcfzKHArCJ yBkTmjcHT+f5LVq7RtDnDIQhzft4jUf/VtY3UErVZXVK/JiIG7YJ9UZ8du4FWWe5QwexuuB17Zo V1e/pADhhi52+gFg/7m8WS2RgBGyS4qwl4A== X-Received: by 2002:a05:6402:11c9:: with SMTP id j9mr28608486edw.385.1642578786590; Tue, 18 Jan 2022 23:53:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJyns4WRsOdrGoSiLkUgMsRyEIUWZN7UKVXPDT+SQgr4x790RZ4Ep5Cqmw1oA9YvBvJZNQYpwg== X-Received: by 2002:a05:6402:11c9:: with SMTP id j9mr28608483edw.385.1642578786471; Tue, 18 Jan 2022 23:53:06 -0800 (PST) Received: from localhost.localdomain (xdsl-188-155-168-84.adslplus.ch. [188.155.168.84]) by smtp.gmail.com with ESMTPSA id w17sm805286edr.68.2022.01.18.23.53.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jan 2022 23:53:06 -0800 (PST) From: Krzysztof Kozlowski To: Krzysztof Kozlowski , "David S. Miller" , Jakub Kicinski , linux-nfc@lists.01.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/6] nfc: llcp: simplify llcp_sock_connect() error paths Date: Wed, 19 Jan 2022 08:52:57 +0100 Message-Id: <20220119075301.7346-3-krzysztof.kozlowski@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220119075301.7346-1-krzysztof.kozlowski@canonical.com> References: <20220119075301.7346-1-krzysztof.kozlowski@canonical.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org The llcp_sock_connect() error paths were using a mixed way of central exit (goto) and cleanup Signed-off-by: Krzysztof Kozlowski --- net/nfc/llcp_sock.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/net/nfc/llcp_sock.c b/net/nfc/llcp_sock.c index d951d4f0c87f..a1b245b399f8 100644 --- a/net/nfc/llcp_sock.c +++ b/net/nfc/llcp_sock.c @@ -712,10 +712,8 @@ static int llcp_sock_connect(struct socket *sock, struct sockaddr *_addr, llcp_sock->local = nfc_llcp_local_get(local); llcp_sock->ssap = nfc_llcp_get_local_ssap(local); if (llcp_sock->ssap == LLCP_SAP_MAX) { - nfc_llcp_local_put(llcp_sock->local); - llcp_sock->local = NULL; ret = -ENOMEM; - goto put_dev; + goto sock_llcp_put_local; } llcp_sock->reserved_ssap = llcp_sock->ssap; @@ -760,11 +758,13 @@ static int llcp_sock_connect(struct socket *sock, struct sockaddr *_addr, sock_llcp_release: nfc_llcp_put_ssap(local, llcp_sock->ssap); + +sock_llcp_put_local: nfc_llcp_local_put(llcp_sock->local); llcp_sock->local = NULL; + llcp_sock->dev = NULL; put_dev: - llcp_sock->dev = NULL; nfc_put_device(dev); error: From patchwork Wed Jan 19 07:52:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 12717185 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9CEDAC433F5 for ; Wed, 19 Jan 2022 07:53:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352236AbiASHxN (ORCPT ); Wed, 19 Jan 2022 02:53:13 -0500 Received: from smtp-relay-internal-0.canonical.com ([185.125.188.122]:38506 "EHLO smtp-relay-internal-0.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352196AbiASHxJ (ORCPT ); Wed, 19 Jan 2022 02:53:09 -0500 Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 6077F3F323 for ; Wed, 19 Jan 2022 07:53:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1642578788; bh=OSgZIsl6KSiVLFhGjCsmJG0C27mMplYwxlAMHo9H3Hk=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=tsu6/141bd5ZU9kliqnn43n9NcWILUIUArk75RTHVkwpVy10EbJ4b1VU5lOUvJEkH KQG8miHroWX53bnSSM3AdPrASmwAF7q9uk3DyoTYYHFyRJkBAYJ+6lJjbJixidWa8/ oLqO3zHKJJat3Qs/ETA3KwiaBi4cHso7r//YiqyJLwmtV0gC2AHlzjBJac3rgsWUxZ r6WWi0dBcV/oBtr92cWtm6rPe5qlzZxjc56054HsLXhCEzyDtpmDRfv536+be6PgaU hBDBJIwFvYf/5gvxVJL4e9lQSZbnuM8Xgy//w287qMnxIs30kxfY0ADI6u555rFxoh hbEM6dpC7aTuQ== Received: by mail-ed1-f70.google.com with SMTP id cf15-20020a0564020b8f00b0040284b671c6so1447616edb.22 for ; Tue, 18 Jan 2022 23:53:08 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OSgZIsl6KSiVLFhGjCsmJG0C27mMplYwxlAMHo9H3Hk=; b=wPkH2FsASr7W2FPrUL3HJ2w4u3M8LpZB1Apnt8MVp+tQiNGzINbwY8tIl8RL+qdxV2 fK/TRTzrGli16W9ixQwKUgW3PdgQgwyXkg+fhWoSdnnPj1JttdCiAXxqOwBZETjBqXtl WmQQsV3YBr5MEZbQ/TIoXpsViYaycsb8uEJMjbgOg3FIdcc1fXda3ZPdamiUMyQSHV9n Z6gIHTIcDs+LpiFwWiSM8pNyu/Ic5zinYQM/y6TduAMASl494jMu/t4A2Y6aR3YSk/oF GNiRMGjwFiGPF/it2qp9NRgWmpGoFGeeFT3NIh1964ZwCzEAbVJow1we+v2oafBmFt+c UZeA== X-Gm-Message-State: AOAM531yPZ5DVUqlRkR+kzJhm/1ee6iFKa7kNdRLoRF32vZMZLZq1+gA xc7ZnyU8jrCUh5yhEn/kQGZIW3VUiPz9LKRQ+9RvDubLu+KuL54EXQWWC1osEfm/d4+GxZL4Vw9 RKxVDBw0iLngYbj50aImexZz0SS4hq2JQrQ== X-Received: by 2002:a05:6402:3591:: with SMTP id y17mr29760633edc.386.1642578787482; Tue, 18 Jan 2022 23:53:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJx9+Xw3bqoaTUBpvw/QShf3ZRnJ6GIKmG4TS+FJXRB9XTPyk9rcHOG6g0FjU5rSXoXNUEWc/Q== X-Received: by 2002:a05:6402:3591:: with SMTP id y17mr29760621edc.386.1642578787366; Tue, 18 Jan 2022 23:53:07 -0800 (PST) Received: from localhost.localdomain (xdsl-188-155-168-84.adslplus.ch. [188.155.168.84]) by smtp.gmail.com with ESMTPSA id w17sm805286edr.68.2022.01.18.23.53.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jan 2022 23:53:06 -0800 (PST) From: Krzysztof Kozlowski To: Krzysztof Kozlowski , "David S. Miller" , Jakub Kicinski , linux-nfc@lists.01.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/6] nfc: llcp: use centralized exiting of bind on errors Date: Wed, 19 Jan 2022 08:52:58 +0100 Message-Id: <20220119075301.7346-4-krzysztof.kozlowski@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220119075301.7346-1-krzysztof.kozlowski@canonical.com> References: <20220119075301.7346-1-krzysztof.kozlowski@canonical.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org 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 --- net/nfc/llcp_sock.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/net/nfc/llcp_sock.c b/net/nfc/llcp_sock.c index a1b245b399f8..60985d1834a5 100644 --- a/net/nfc/llcp_sock.c +++ b/net/nfc/llcp_sock.c @@ -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); From patchwork Wed Jan 19 07:52:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 12717184 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9C464C4332F for ; Wed, 19 Jan 2022 07:53:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352226AbiASHxM (ORCPT ); Wed, 19 Jan 2022 02:53:12 -0500 Received: from smtp-relay-internal-0.canonical.com ([185.125.188.122]:38520 "EHLO smtp-relay-internal-0.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352204AbiASHxK (ORCPT ); Wed, 19 Jan 2022 02:53:10 -0500 Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id DCF023F1E0 for ; Wed, 19 Jan 2022 07:53:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1642578788; bh=15HOmnObJXsVXxZJ5x/3DtxcDfRhMgZoa5zrHrITnNA=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=MAf5F86XF4ZDlFIaJHfEwZPi9O9GLhPFwijdr8dFbdlCI6At0Iuh5MYpOKXrO0myS 0W//fbv3PiKD4GgINkDidqVMvg7pHIW+ze1rUbuH8498DoHexdPgDJJWlJKAPYuRso Ia4otCe5zbgRsmX2M+TMNuaKacxNsp5GaZSdP11ljnSATR2H1Thsp/uq60o89faYKi epbBgs/jbKysua3GBNTIc//zZs1Hi1sZ/bV5ueOQjSonxKAQC2+70sHRdtYSlITGPR VzWy/FtuVWq7z/etstKB8OQTlDpZ6FP+rHIaElbUUP6JF9wKHgsW6Ow7xXOdDo9bpr uj6V1tLXCT/sA== Received: by mail-ed1-f70.google.com with SMTP id t11-20020aa7d70b000000b004017521782dso1448545edq.19 for ; Tue, 18 Jan 2022 23:53:08 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=15HOmnObJXsVXxZJ5x/3DtxcDfRhMgZoa5zrHrITnNA=; b=dCJlhk3lP2smJChY4JH8SB301f+WK9Uy3Y/yyV6Gwc+cLjRWaEjqz/ugufCprEmHWU Fq6PGVKdWsi6kHTeT/OjlqfJAjAhrVGShlJtexHeIu56yp5aqIm5lnNLQzt6wlKol9cz IqaOi63SkW1peDTJ/9PHvhmrwWjNlPeHlA8M2D7V6p9w3THJwvKrpi8BYn4+djJtYPrV rQGWzFANPl4i8taaOtz7feMZD/7/xHr6fNJpYtKk4vLuXGGWUZLs4eox8wWHBHTBZoPK Hk5OZNDwj2Al2e0lKDsjciyLSkZYmpLZwFIC2ZxPKkFoDvxF2f1XFPLAqPjiQYquG9CU iZUw== X-Gm-Message-State: AOAM533I/5VKYkFtsAPjkBQJk80LDiXfaPS6IW3ywI/v3JJiWpjGC1wD w4cW/Liy9NYp1efhhwqi9ZgpocwNaafCxMc+jTgqGY01Zd2gnb5kMMl0vAjuY6h/AvCutxMOJIF mk46EmwD36W5voORR+FjWaOunNF3d81RA2w== X-Received: by 2002:a17:906:314f:: with SMTP id e15mr24089114eje.658.1642578788655; Tue, 18 Jan 2022 23:53:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJyvebYbkc+sDSvj+IhZAZlbGMQ8r2BM5qm9B1lRUqpsvTkhNAMQvZayhml1fBn9wG0q6LpOgQ== X-Received: by 2002:a17:906:314f:: with SMTP id e15mr24089106eje.658.1642578788503; Tue, 18 Jan 2022 23:53:08 -0800 (PST) Received: from localhost.localdomain (xdsl-188-155-168-84.adslplus.ch. [188.155.168.84]) by smtp.gmail.com with ESMTPSA id w17sm805286edr.68.2022.01.18.23.53.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jan 2022 23:53:08 -0800 (PST) From: Krzysztof Kozlowski To: Krzysztof Kozlowski , "David S. Miller" , Jakub Kicinski , linux-nfc@lists.01.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 4/6] nfc: llcp: use test_bit() Date: Wed, 19 Jan 2022 08:52:59 +0100 Message-Id: <20220119075301.7346-5-krzysztof.kozlowski@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220119075301.7346-1-krzysztof.kozlowski@canonical.com> References: <20220119075301.7346-1-krzysztof.kozlowski@canonical.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Use test_bit() instead of open-coding it, just like in other places touching the bitmap. Signed-off-by: Krzysztof Kozlowski --- net/nfc/llcp_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/nfc/llcp_core.c b/net/nfc/llcp_core.c index 5ad5157aa9c5..b70d5042bf74 100644 --- a/net/nfc/llcp_core.c +++ b/net/nfc/llcp_core.c @@ -383,7 +383,7 @@ u8 nfc_llcp_get_sdp_ssap(struct nfc_llcp_local *local, pr_debug("WKS %d\n", ssap); /* This is a WKS, let's check if it's free */ - if (local->local_wks & BIT(ssap)) { + if (test_bit(ssap, &local->local_wks)) { mutex_unlock(&local->sdp_lock); return LLCP_SAP_MAX; From patchwork Wed Jan 19 07:53:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 12717187 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 94053C43217 for ; Wed, 19 Jan 2022 07:53:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352249AbiASHxQ (ORCPT ); Wed, 19 Jan 2022 02:53:16 -0500 Received: from smtp-relay-internal-1.canonical.com ([185.125.188.123]:55312 "EHLO smtp-relay-internal-1.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352215AbiASHxL (ORCPT ); Wed, 19 Jan 2022 02:53:11 -0500 Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id DF7D13FFDD for ; Wed, 19 Jan 2022 07:53:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1642578789; bh=RM6CEuGCpivOsBpPPs3hkt8u1ijpOzgu/V3oCSO4jiM=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Ue7KA/6jXfRUvNGexglmYZadzYejZrCAR4nRVbSaeB7JnKnmmPYm8akSqqWUvGKuZ +rJaXZplTe4WJ6brWrO13VP8AcO0FY/INMphguv+biB24s+GLIT3Nw/wP+3QgEkc70 JXp8VX5tVb99Is2pRZDDehTN3qG6UcVNW1JHzWhs0AcOIrh2h9KJGEbUzQ3WzLH6fy SFLXyJW1WDNPrSztFIjbYrZMqhFnpvBR14pY4fd3iRT98vHjrt1DoFwL878ToisLY0 vRgJQXjMvJ3T2LkneMw12QYgQXDFIjlqwxNkly/yWpkCA8akQ8sgkjip3IG/Q3S6cA gWUOvMav4dvfA== Received: by mail-ed1-f69.google.com with SMTP id el8-20020a056402360800b00403bbdcef64so1470263edb.14 for ; Tue, 18 Jan 2022 23:53:09 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=RM6CEuGCpivOsBpPPs3hkt8u1ijpOzgu/V3oCSO4jiM=; b=YrhllgJTt5L/XDZ6Udv9W+Q0D9iL0oOTkKDIIgqcIvTMUE8g5wNo8pf3AQCzTquvIH cGzcBNu/qqbpo/DSEBaYzOoJ9MVPYnSx48USQiNTsvqRENLRcqBAq760McMDR6VAVAm1 Q9+mRgveX7PNiunfuiphdYpPROtPt2J4CDTecbmplNSvJJc8bDMXj5f4m7zw48G60U8q G/JuZkX/zdvC7eZFCSNsX+aIUGOEcsDDame3+dHhWkZFfCyaP4WmjgbVst6xq1yN4E/1 Of2ENiE5ff1wpT2b9kfZ5nKCFxzcxdklPuelKtycQS5TX4u9W98IXB3MQyIB+aOthrA6 P6jQ== X-Gm-Message-State: AOAM533g2elSaSkQ6YbnErmwIpXnOKihvk8dnkjH4EcByIyDyA5gNfTt qmvK2HwSvxC/N2aUFLjscVlm9CIUrwX8TtChAltUw615IHXEM9vtQJd8hTtWFq5+FI9572J4pX4 rmT0XtkD1nz+2S3vmVKZvSBFhtKqgUxWxXQ== X-Received: by 2002:a17:907:e93:: with SMTP id ho19mr11025872ejc.168.1642578789629; Tue, 18 Jan 2022 23:53:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJzJEcV3S0JFKK4d5B6hmyTEOPZMdJTa8RrL6S17NZ6W29g8Vt3dq4Dv7WMzhmOsFjUA/eVO+g== X-Received: by 2002:a17:907:e93:: with SMTP id ho19mr11025863ejc.168.1642578789450; Tue, 18 Jan 2022 23:53:09 -0800 (PST) Received: from localhost.localdomain (xdsl-188-155-168-84.adslplus.ch. [188.155.168.84]) by smtp.gmail.com with ESMTPSA id w17sm805286edr.68.2022.01.18.23.53.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jan 2022 23:53:08 -0800 (PST) From: Krzysztof Kozlowski To: Krzysztof Kozlowski , "David S. Miller" , Jakub Kicinski , linux-nfc@lists.01.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 5/6] nfc: llcp: protect nfc_llcp_sock_unlink() calls Date: Wed, 19 Jan 2022 08:53:00 +0100 Message-Id: <20220119075301.7346-6-krzysztof.kozlowski@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220119075301.7346-1-krzysztof.kozlowski@canonical.com> References: <20220119075301.7346-1-krzysztof.kozlowski@canonical.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org nfc_llcp_sock_link() is called in all paths (bind/connect) as a last action, still protected with lock_sock(). When cleaning up in llcp_sock_release(), call nfc_llcp_sock_unlink() in a mirrored way: earlier and still under the lock_sock(). Signed-off-by: Krzysztof Kozlowski --- net/nfc/llcp_sock.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/net/nfc/llcp_sock.c b/net/nfc/llcp_sock.c index 60985d1834a5..2d4cdce88a54 100644 --- a/net/nfc/llcp_sock.c +++ b/net/nfc/llcp_sock.c @@ -631,6 +631,11 @@ static int llcp_sock_release(struct socket *sock) } } + if (sock->type == SOCK_RAW) + nfc_llcp_sock_unlink(&local->raw_sockets, sk); + else + nfc_llcp_sock_unlink(&local->sockets, sk); + if (llcp_sock->reserved_ssap < LLCP_SAP_MAX) nfc_llcp_put_ssap(llcp_sock->local, llcp_sock->ssap); @@ -643,11 +648,6 @@ static int llcp_sock_release(struct socket *sock) if (sk->sk_state == LLCP_DISCONNECTING) return err; - if (sock->type == SOCK_RAW) - nfc_llcp_sock_unlink(&local->raw_sockets, sk); - else - nfc_llcp_sock_unlink(&local->sockets, sk); - out: sock_orphan(sk); sock_put(sk); From patchwork Wed Jan 19 07:53:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 12717186 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E6C30C433FE for ; Wed, 19 Jan 2022 07:53:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352239AbiASHxO (ORCPT ); Wed, 19 Jan 2022 02:53:14 -0500 Received: from smtp-relay-internal-1.canonical.com ([185.125.188.123]:55322 "EHLO smtp-relay-internal-1.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352227AbiASHxM (ORCPT ); Wed, 19 Jan 2022 02:53:12 -0500 Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id E6A18407F2 for ; Wed, 19 Jan 2022 07:53:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1642578790; bh=x/F9VAvKkrKoejYalm8chWtX9s0cqmjTeJU4WHXRJwU=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=JKpb4944cZlA4PYTH9/LWoHrEnXq1EUmhagnDfq0P3t6XKPMFE0XwEUm/9G2V+Jbc Rfp0X5zN+mFXBOPWGNgIpQ+LkaW2+oprsLMBPAfiYqpppxqDPEEiQ4FgQbDhbBwnbE X6vsiF3aulCy2pN+sBjEPVFFlf4RLkZ1XB2XQvG1BVNcKxw+xw+iKm19an1r7XiIXS l+JDJ5K1nSpWN1zue5xS1zb7haGd4bgte/hXU3q3is883ZmW84EOmLNuVaA3IKwgJA SeYSwsClxWoxsTfjIrI/mtZ+kf2GXhy/BK4BgWFGtGvanr21hqlb49BmZiVGHqc7NW 58YoVC+Qd2WYw== Received: by mail-ed1-f71.google.com with SMTP id i9-20020a05640242c900b003fe97faab62so1482311edc.9 for ; Tue, 18 Jan 2022 23:53:10 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=x/F9VAvKkrKoejYalm8chWtX9s0cqmjTeJU4WHXRJwU=; b=H5RNB/Sxt7X6L+1IV25VsAuBIkvG58Ixnh1FN8ZgVile4pWmilkqVcI8ot5sSZc909 SLKR71M/1vBQ8g1rDEFKZvsn3+YJeO/rxWy+CU+UXjAk5yQBn6FgbLAZESvhIPmvfj1p 5WuNzZNwmDvUwKJpBfdvq+L3Qn07wr6ilcasRTGcHJu1c1OEssbsz6SWWugYuITJfvfm 8ezPIPUsth1l5El9yjh1iFEigV1nA4TzWctHzKGN4FlL5hEO62CyvZahAe1ciOvWH7tL sSzd22EE9QXS19e1fn1WleGdU8qOXgCf4uv6lkz6/OkcURKYpPJNffXTtMKn3pDZzuQa CNFw== X-Gm-Message-State: AOAM533eNMmLpcNsx6+9huW7vwt3szmysID8GGO9cvqipVcF/ep6B8qD +1wVhWRKOb1b05VyYs7cOBfKvxkSotrWLOgr/N/1mDBK7frnKMDqaEDm2c2dDz86Z2hYw5Jto1+ BK7AP1GwfMgrvFR5ofeA5CrWqWX3IuSt+wA== X-Received: by 2002:a17:907:1c11:: with SMTP id nc17mr23091261ejc.513.1642578790606; Tue, 18 Jan 2022 23:53:10 -0800 (PST) X-Google-Smtp-Source: ABdhPJwLf3PxsIJN+w6STqoYgFU25Yxbhg0DD3ySt4Ezlf7rmSa4y3Co29oIvpjwl5lROKrswnJnbA== X-Received: by 2002:a17:907:1c11:: with SMTP id nc17mr23091253ejc.513.1642578790409; Tue, 18 Jan 2022 23:53:10 -0800 (PST) Received: from localhost.localdomain (xdsl-188-155-168-84.adslplus.ch. [188.155.168.84]) by smtp.gmail.com with ESMTPSA id w17sm805286edr.68.2022.01.18.23.53.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jan 2022 23:53:09 -0800 (PST) From: Krzysztof Kozlowski To: Krzysztof Kozlowski , "David S. Miller" , Jakub Kicinski , linux-nfc@lists.01.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 6/6] nfc: llcp: Revert "NFC: Keep socket alive until the DISC PDU is actually sent" Date: Wed, 19 Jan 2022 08:53:01 +0100 Message-Id: <20220119075301.7346-7-krzysztof.kozlowski@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220119075301.7346-1-krzysztof.kozlowski@canonical.com> References: <20220119075301.7346-1-krzysztof.kozlowski@canonical.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org This reverts commit 17f7ae16aef1f58bc4af4c7a16b8778a91a30255. The commit brought a new socket state LLCP_DISCONNECTING, which was never set, only read, so socket could never set to such state. Remove the dead code. Signed-off-by: Krzysztof Kozlowski --- net/nfc/llcp.h | 1 - net/nfc/llcp_core.c | 7 ------- net/nfc/llcp_sock.c | 7 ------- 3 files changed, 15 deletions(-) diff --git a/net/nfc/llcp.h b/net/nfc/llcp.h index d49d4bf2e37c..c1d9be636933 100644 --- a/net/nfc/llcp.h +++ b/net/nfc/llcp.h @@ -6,7 +6,6 @@ enum llcp_state { LLCP_CONNECTED = 1, /* wait_for_packet() wants that */ LLCP_CONNECTING, - LLCP_DISCONNECTING, LLCP_CLOSED, LLCP_BOUND, LLCP_LISTEN, diff --git a/net/nfc/llcp_core.c b/net/nfc/llcp_core.c index b70d5042bf74..3364caabef8b 100644 --- a/net/nfc/llcp_core.c +++ b/net/nfc/llcp_core.c @@ -737,13 +737,6 @@ static void nfc_llcp_tx_work(struct work_struct *work) print_hex_dump_debug("LLCP Tx: ", DUMP_PREFIX_OFFSET, 16, 1, skb->data, skb->len, true); - if (ptype == LLCP_PDU_DISC && sk != NULL && - sk->sk_state == LLCP_DISCONNECTING) { - nfc_llcp_sock_unlink(&local->sockets, sk); - sock_orphan(sk); - sock_put(sk); - } - if (ptype == LLCP_PDU_I) copy_skb = skb_copy(skb, GFP_ATOMIC); diff --git a/net/nfc/llcp_sock.c b/net/nfc/llcp_sock.c index 2d4cdce88a54..14afed5916d1 100644 --- a/net/nfc/llcp_sock.c +++ b/net/nfc/llcp_sock.c @@ -641,13 +641,6 @@ static int llcp_sock_release(struct socket *sock) release_sock(sk); - /* Keep this sock alive and therefore do not remove it from the sockets - * list until the DISC PDU has been actually sent. Otherwise we would - * reply with DM PDUs before sending the DISC one. - */ - if (sk->sk_state == LLCP_DISCONNECTING) - return err; - out: sock_orphan(sk); sock_put(sk);