Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp5569187rdb; Sun, 31 Dec 2023 07:01:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IFWwNSMmqKUwJBJw8YZ71a4VzhODQ8f3TxOHVK5tC5BKHudvakUb/k2pJ+ieOF6BFYtVoXx X-Received: by 2002:a05:6830:4105:b0:6db:d549:9045 with SMTP id w5-20020a056830410500b006dbd5499045mr9375152ott.34.1704034863917; Sun, 31 Dec 2023 07:01:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704034863; cv=none; d=google.com; s=arc-20160816; b=WiOUi0w6iCuZBPhtzFnkVXJ0iNsQyS5b32/XILC6XubXl+ADSHuB0Ilki4JF7SSQz7 sss6Kx+Uy4hUKcpTKgn3bFxG/PUJEkM3d7KeUBX9xa4/9xPh/py+WEs2rDHvFASFrM8r Y3iJZUJV9Rkl+R+YsQP7QfBr6q3wmB5l2+VQYT26RlFnqw60wW4xW8iza75YVs+QpzOF v+/7swssjJvcVP0tr+VQX1+5Hy61bZnk4KI9KJZ66s0rOLbycq/FrgxM2DRU6QxnBBwG miPtA+e8RrJSv5rG8WERgXAlwYOIzjFjvxKMY5K61Jo0uNq1r9wsZwHRimChL4AhUUke UVsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=ui-outboundreport:content-transfer-encoding:in-reply-to:cc :references:to:from:content-language:subject:user-agent:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:date:message-id :dkim-signature; bh=kZt+FGun412VVDmUPqPk8ZCl0XMBmzHyTpnWgdymHXo=; fh=4Rj64+qyQ+cAnjNez0+aC2KGHhHHcDJhw4cjpbQ3SP8=; b=BKNPJcCFjfqvkS4fl65fZG7eQlcR3s5pCfvTlXrCBDqZJUtk2aF49Bb4nHz37NgKju Y37/hObPyHx/aVg7Ij4zY9FjEMBJ8s2+FNMMVePDBlG4o8JJlE9iCvH4IJwG0k5xKKoA MP56hXX42yRtx68xX2U/iFaRX9bujMiKrI6IDlKLpvybukLxmpuEwuD2EtfUZyjI0NNO hO62AOH1ToLNY1lYCbWuGI7f/yOmT5/wfcz5JAgSp8J7C2stmzkkoliD0d097cp+jWOH ofUxeqwPqIr9i6YKQ6n6/e69lMdlX6fIzLyOPQhPuZEg+NmALsUQFP2HR5yEDAUJ3Mzy Yb6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@web.de header.s=s29768273 header.b=lAjUuHKK; spf=pass (google.com: domain of linux-kernel+bounces-13724-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-13724-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=web.de Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id h15-20020a67fd6f000000b0046726529e69si1272179vsa.288.2023.12.31.07.01.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 31 Dec 2023 07:01:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-13724-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@web.de header.s=s29768273 header.b=lAjUuHKK; spf=pass (google.com: domain of linux-kernel+bounces-13724-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-13724-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=web.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 9EEB71C20A99 for ; Sun, 31 Dec 2023 15:01:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5E7628F42; Sun, 31 Dec 2023 15:00:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=web.de header.i=markus.elfring@web.de header.b="lAjUuHKK" X-Original-To: linux-kernel@vger.kernel.org Received: from mout.web.de (mout.web.de [212.227.15.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B3BCC8F49; Sun, 31 Dec 2023 15:00:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=web.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=web.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1704034824; x=1704639624; i=markus.elfring@web.de; bh=/EkgIbiDfFiW79s9a4Ba4KIcoGQRr5fomhIzMuL4pkQ=; h=X-UI-Sender-Class:Date:Subject:From:To:References:Cc: In-Reply-To; b=lAjUuHKKLLMTacaMrIMsZ/OOnph36OFk831BnfBHFvGXMU6lzBhtImXYS3zv606E c8NGymPNhvF51C0QZkIpcN0a5BfUPz5m/2kF9n1yIc3pDj2+HgYt/OZUl044Gc22t 9V/Q+VVFcz76aP7wn7ZttOaOHEvrgSqQC1e3CiDP3paFIIizR2PecBv5iOks3sAw6 awakye2XLnopEWguxPSGEkpDETMIWsOpT+LRRO73RMuPtXgx65mj+hkKKRVywEmAI nyE57tCLrAi204EQagySrf+hJ4fu3xxaXhPbQRFHYj2V9QZro4RuDEiERQGC/680K 699MZbZnBVYLTEh+Fg== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from [192.168.178.21] ([94.31.90.95]) by smtp.web.de (mrweb006 [213.165.67.108]) with ESMTPSA (Nemesis) id 1MwA1A-1r3OQ81xBs-00sG9F; Sun, 31 Dec 2023 16:00:24 +0100 Message-ID: <5253e660-6b66-4775-ae2f-06f5a1d40be5@web.de> Date: Sun, 31 Dec 2023 16:00:22 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH 2/2] net/smc: Improve exception handling in smc_llc_cli_add_link_invite() Content-Language: en-GB From: Markus Elfring To: linux-s390@vger.kernel.org, netdev@vger.kernel.org, kernel-janitors@vger.kernel.org, "David S. Miller" , "D. Wythe" , Eric Dumazet , Jakub Kicinski , Jan Karcher , Paolo Abeni , Tony Lu , Wen Gu , Wenjia Zhang References: <8ba404fd-7f41-44a9-9869-84f3af18fb46@web.de> Cc: LKML In-Reply-To: <8ba404fd-7f41-44a9-9869-84f3af18fb46@web.de> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:oG3OmE7p+Zndch/Dj/BnQFbZ4YKWANLuDuOJVlDnyB2QnqSTIfO FN4K3UkD8+tYea+OsaPrlTrg2oWgGiEcCvW11H69MqsCeSl7thehurwIksrf1kwil0QGIDw ufE7jsBAHe0kQLj0of+zeF/MIm/8bxPktR6HnHU5qMM6gz2p/WIF3q7arKIq2QB6FVjKZHe oNKjkRrfxbvdfzZcUSciA== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:6M1bFLtV6zc=;k7xX0Go5mPnhUg1AtvOiS4tVGyu sES+x3UIFXs/aJtn6JOx64gVuddsXky1mfoDSyu1RGPsHVSaUK5cHvPypQzcxp3Q0TooNHPWt 7Gfk8dPEHSEk4Nb+055lRygnhv+Wo5qa0TeG8fvp+YuXPnrj8Pyz0aSQGC92NUV0QdDKLF1Dp qSiRVjsUL/30IXQQn5TQC+VJq2SgYtZJVQ53DecR0EBGJlT09c4Z1BsNQmH8c0VJVfL8Oq0gA /sD9kamMNuOAUhRONYRMxnzz6jOBKF7P8tvR8liB5pUHftM29nCxnpA1tsD5fq58OofoD4DI1 gYo/PXdvoGvtW3BQVrIfJo7/Tn8JYA4Nu9/Y5c2tCtASy1b296nO17gAQJEgoeinyQuHLBg6a bOO31at2WB6IJ7Z4JOqE/MKW6zsNDTGabnpFQwHxKyLf9boybLk7WRBV7jF2UdG9iyNjiby3g k2RdesvHAdzxKnLVyKAudjVkDqtc320aXXL6x2YdDQ0RbBBONQY740+Md1Q9evT50IAP/gn8h 41NKKrF+hDKHqIH8yNZ2U9vWPACVE3M2g2DrkjHCysWxApje9nugAgcqViFF410qNfa2gzEDz gKM9vCJ3bGP02sQZy6vuOClXKQL+2VoJCggqyLlUdmhN4oRgjn8i3iP75bTF3uOrgqWS+3Rw1 qoXn/TC3Erf0hqJl0l0uCHoP8gT6lqTFgIWKzwKfQgZ7mT3sT3LIWjU1keydEt0ukfK/gJznK 5q4QLYxq9qUN4xgBU+FBLCnCweA3trW13AjRSP+cD/XSlI+OWMPGEmh8TyGZaN1XKANeab43f yj3Ieb18vyXBf1QDY47mXGDlt6TNm4DpsE+hnAlsfjyqt2tE+0amYXV8WY36zew6vnsfndb6X 9FSVQPPSNKPx6PzJu4aTUggy+B8/8WQfPD+b5ZmW6Que1IHm8LVKKFkpNxCau6Vp0imQX+Cup rgELGg== From: Markus Elfring Date: Sun, 31 Dec 2023 15:42:07 +0100 The kfree() function was called in some cases by the smc_llc_cli_add_link_invite() function during error handling even if the passed variable contained a null pointer. This issue was detected by using the Coccinelle software. * Thus use another label. * Merge two if statements. * Omit an initialisation (for the variable =E2=80=9Cini=E2=80=9D) which became unnecessary with this refactoring. Signed-off-by: Markus Elfring =2D-- net/smc/smc_llc.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/net/smc/smc_llc.c b/net/smc/smc_llc.c index 018ce8133b02..2ff24a7feb26 100644 =2D-- a/net/smc/smc_llc.c +++ b/net/smc/smc_llc.c @@ -1163,23 +1163,21 @@ static void smc_llc_cli_add_link_invite(struct smc= _link *link, struct smc_llc_qentry *qentry) { struct smc_link_group *lgr =3D smc_get_lgr(link); - struct smc_init_info *ini =3D NULL; + struct smc_init_info *ini; if (lgr->smc_version =3D=3D SMC_V2) { smc_llc_send_request_add_link(link); - goto out; + goto free_qentry; } if (lgr->type =3D=3D SMC_LGR_SYMMETRIC || - lgr->type =3D=3D SMC_LGR_ASYMMETRIC_PEER) - goto out; - - if (lgr->type =3D=3D SMC_LGR_SINGLE && lgr->max_links <=3D 1) - goto out; + lgr->type =3D=3D SMC_LGR_ASYMMETRIC_PEER || + lgr->type =3D=3D SMC_LGR_SINGLE && lgr->max_links <=3D 1) + goto free_qentry; ini =3D kzalloc(sizeof(*ini), GFP_KERNEL); if (!ini) - goto out; + goto free_qentry; ini->vlan_id =3D lgr->vlan_id; smc_pnet_find_alt_roce(lgr, ini, link->smcibdev); @@ -1190,6 +1188,7 @@ static void smc_llc_cli_add_link_invite(struct smc_l= ink *link, ini->ib_gid, NULL, SMC_LLC_REQ); out: kfree(ini); +free_qentry: kfree(qentry); } =2D- 2.43.0