From patchwork Wed Dec 27 10:04:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Markus Elfring X-Patchwork-Id: 759807 Received: from mout.web.de (mout.web.de [212.227.17.11]) (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 D136A2C688; Wed, 27 Dec 2023 10:04:57 +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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=web.de header.i=markus.elfring@web.de header.b="i0yqvxdi" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1703671494; x=1704276294; i=markus.elfring@web.de; bh=xHDdrd92yyItWY6iNqPqDxvi3VGdAbzM/GdBjxnBIjU=; h=X-UI-Sender-Class:Date:Subject:From:To:Cc:References: In-Reply-To; b=i0yqvxdibEe/ej4aoOGhrJ+jRkN1c/4v7nVEuREJzalFp5jep2qKiJb9N8EutEY7 jWLfSSEM0Fk3F0tu2FXYK+vH/P3q8U831CsjHNIHkepOKsGspQp/x30qYHjHRZDjw x9zOqgYs8BQd8jB2AgRYajo1aPr6Qlx6mwAcxD65Vgu1+wtoXsM/Idvv+4P0ZvJKu hFLV7n2Wthsgo1dWHb6PxpZMkOIBJODEeV6WOXwMzukKLr3LvNn6VQ6MkrcA8eCBj gUqerzoYx2ff56ezZjXb7PwinNy8EXOQeCpQek1sscOdzAshyax8cCCy/g6jTHF8j BhhZXSzU62GAeqh44Q== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from [192.168.178.21] ([94.31.85.95]) by smtp.web.de (mrweb105 [213.165.67.124]) with ESMTPSA (Nemesis) id 1M59jC-1rJWi20DFk-001LeM; Wed, 27 Dec 2023 11:04:54 +0100 Message-ID: <3d16ddfe-f10a-4188-a9c6-e92655c0b01a@web.de> Date: Wed, 27 Dec 2023 11:04:53 +0100 Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH 1/2] scsi: message: fusion: Improve data processing in mptsas_find_phyinfo_by_phys_disk_num() Content-Language: en-GB From: Markus Elfring To: linux-scsi@vger.kernel.org, MPT-FusionLinux.pdl@broadcom.com, kernel-janitors@vger.kernel.org, Sathya Prakash , Sreekanth Reddy , Suganath Prabu Subramani Cc: LKML , cocci@inria.fr References: In-Reply-To: X-Provags-ID: V03:K1:BXTXEcL23YW2+L4v3sU1O+CqZc9VLmoulmh0iGtLNO9bLfdJ2Py qEWNjvHmkGprxRLQJFq38Tl2jiUPQ2Yflt8EDKQOgoBsVCqGoFoEmEK0hxdNS1FgzAUaNji 5Dc7sKFUWHs3BqAPNJ72IqbzZbCVecbHkDAdnag9IVBBLDg04WWMFyka/2jb4iXJeC0xrd6 ZbmBv/W860kVn6g5bl7gg== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:aqVwaolc6BE=;EIRN57N0btRcuRJ3W4C5usXyncP stxFd72pw0T5isIca5Thm+fqD9O8fOUsGKshK/83BZBiR9e07lir80XRa78D/u/wGvJocyQr8 WvKhzEjt+ndqNGXLYTLGg4GtBX1PvdrVUkFjQ2dgfmpEj4N/Waad/yrZh4sfkUDfChErWyi0t M4Ci/lOY5fYbRyUj7rrd1nJvrrmFad4m5eUaFupyuPy4qUlNjiAEovVJW/l0l0CvpshGRjWaV r5EFHh9jRIAt+P2yKEDflAAFkLSqDbKKCbnZ+xlCUf3pe2GfRtVxFH/p1uIY90LCaZbLMoBPK /67jghay0/WfqfSZyOpZEibZuz7oSRTSuMmXmS36Klv+aRhepaE1GIIA3/Duzmk2ZCJbLTFkE 0j7Il9O0OHuXMEUjn1Sm3/apTXBeN+SHvif33yA7w3fHm+rIDpsfuwNVHrGQwbiKTQU9C/V7M WTtue0Sn0dNO9NWLhGIG6rIGzUeBJq5iargl8JE6+4RUJEEtWOPAW4bGEJfC+VhSqa2/ebglw rheV4n/Hdphy/r72r5NyzjMa/GZJAex+QZNnr/2GMmEbiGhlv9v/LVvm7b/SsEKjd+zyrN5dk KuNWKzKSV9OrMbTai5sYf+2aerR7w5G4DcQ6/ZfjP9Ij12F4Mg3K/wkYU5be+ZcVIL9EXzNr4 p8zW5b8BdJ8DFqiySuhLttyX7TJFQOtFiUUZJVePRb8MLlAXbKpug2uRVa0w6TiqaCwnGOq6g CNim5BeYCRDPbm4mlil5MiicZsh+g5yaAJy3zTl7c/VXHStiGsP9hYyvw36ny4SwLLpxjHFgZ Jzka5W3eFkdZVGcJ+T1iEGUVAWAS1l9DFEKAfCltopP29NAY7YkR1g1+3CUqHpkRFLOwyL3o1 wOwgv7bLW0S+ls2Oy486bROCWlzKL4cuR/M7fV2U0wRnqbwypJiF4ShRrI7J22UbpLY5THMSO aexB4TtOW3FeZmGDRBMRbq9utgs= From: Markus Elfring Date: Wed, 27 Dec 2023 10:23:09 +0100 The kfree() function was called in one case by the mptsas_find_phyinfo_by_phys_disk_num() function during error handling even if the passed variable contained a null pointer. This issue was detected by using the Coccinelle software. 1. Thus use another label. 2. Delete an initialisation for the variable “phys_disk” which became unnecessary with this refactoring. Signed-off-by: Markus Elfring --- drivers/message/fusion/mptsas.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) -- 2.43.0 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c index 300f8e955a53..452635a50c4c 100644 --- a/drivers/message/fusion/mptsas.c +++ b/drivers/message/fusion/mptsas.c @@ -4171,7 +4171,7 @@ mptsas_find_phyinfo_by_phys_disk_num(MPT_ADAPTER *ioc, u8 phys_disk_num, { struct mptsas_phyinfo *phy_info = NULL; struct mptsas_portinfo *port_info; - RaidPhysDiskPage1_t *phys_disk = NULL; + RaidPhysDiskPage1_t *phys_disk; int num_paths; u64 sas_address = 0; int i; @@ -4182,11 +4182,13 @@ mptsas_find_phyinfo_by_phys_disk_num(MPT_ADAPTER *ioc, u8 phys_disk_num, /* dual port support */ num_paths = mpt_raid_phys_disk_get_num_paths(ioc, phys_disk_num); if (!num_paths) - goto out; + goto lock_mutex; + phys_disk = kzalloc(offsetof(RaidPhysDiskPage1_t, Path) + (num_paths * sizeof(RAID_PHYS_DISK1_PATH)), GFP_KERNEL); if (!phys_disk) - goto out; + goto lock_mutex; + mpt_raid_phys_disk_pg1(ioc, phys_disk_num, phys_disk); for (i = 0; i < num_paths; i++) { if ((phys_disk->Path[i].Flags & 1) != 0) @@ -4211,6 +4213,7 @@ mptsas_find_phyinfo_by_phys_disk_num(MPT_ADAPTER *ioc, u8 phys_disk_num, * Extra code to handle RAID0 case, where the sas_address is not updated * in phys_disk_page_1 when hotswapped */ +lock_mutex: mutex_lock(&ioc->sas_topology_mutex); list_for_each_entry(port_info, &ioc->sas_topology, list) { for (i = 0; i < port_info->num_phys && !phy_info; i++) { From patchwork Wed Dec 27 10:06:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Markus Elfring X-Patchwork-Id: 758570 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 904A32D787; Wed, 27 Dec 2023 10:07:01 +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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=web.de header.i=markus.elfring@web.de header.b="nzD+b5Td" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1703671610; x=1704276410; i=markus.elfring@web.de; bh=jn1IbyEVOZrfvN7XBCt9j+uuHZsv/fW9fsgamye8t/8=; h=X-UI-Sender-Class:Date:Subject:From:To:Cc:References: In-Reply-To; b=nzD+b5TdpN+n+8NxtQNY4AU5fCw+GUxGO+l30gVKS2BB8EQS/oIGaanY0qd1le67 z5ONw168vZxrvn5SQUI6/jy4XFBEECPLA8z7KB4J193PprPn8nDnKlMhPyBqskpaH e9UFE4MD16FpGve+SIHiCYc4j+USRnTTPRHijmRnAtVf12cI7EfnxPNqFIL6ag8O0 U88kXehW0ybP7ZZGpJ1Xkg2c83OhMvMIPmvhCRHQK2DP2JKOqJT2QlREWVnIwjaib Bj/rSJ7HVtJ8cOJXihsZQSe8DPFDGogQL6jsb89dI37j8lpHv2ElejRJXi8y6tdSs c1xaKXfPTidhkNd19g== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from [192.168.178.21] ([94.31.85.95]) by smtp.web.de (mrweb006 [213.165.67.108]) with ESMTPSA (Nemesis) id 1M2Phi-1rGmeK2Ir0-004HkY; Wed, 27 Dec 2023 11:06:50 +0100 Message-ID: <3c6ebb2b-b3d5-4698-aa89-9960872cbb4c@web.de> Date: Wed, 27 Dec 2023 11:06:49 +0100 Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: =?utf-8?q?=5BPATCH_2/2=5D_scsi=3A_message=3A_fusion=3A_Move_an_assi?= =?utf-8?q?gnment_for_the_variable_=E2=80=9Cphy=5Finfo=E2=80=9D_in_mptsas=5F?= =?utf-8?q?find=5Fphyinfo=5Fby=5Fphys=5Fdisk=5Fnum=28=29?= Content-Language: en-GB From: Markus Elfring To: linux-scsi@vger.kernel.org, MPT-FusionLinux.pdl@broadcom.com, kernel-janitors@vger.kernel.org, Sathya Prakash , Sreekanth Reddy , Suganath Prabu Subramani Cc: LKML , cocci@inria.fr References: In-Reply-To: X-Provags-ID: V03:K1:gkazMb/O4l2GzERn48IcvpwT5y8HvZR1g45mK2lRunaPBwbiMdd TRJ8HoTpw/tsxHi5+rASq8Op6y7D41VS3CrLChjltMjsYIdfY6ToXfF/i6HBQJIDjWI1QOm nk/r6J69+UBrf8TjzIotfhmZXVBDkUhT1qrJg825ztHtHcjo+22VfAY/w9w3cYl0qu8Ppf9 VnDUk9T3JCK+TeziBuCTg== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:xMCx7VgZ08M=;IAkFRS512RJ3iuU4GJ7SK9fOEKu Gqy65n38ZJpJYi7mBsUhtWPhM1vMlT4lg9/7Bp0uOp7L1AiDvG9j7aS5UWbEWuSKlVrNTyegO lq+T3Wjul3GOBU2d0zJZaob9emJIfVEuvmJbU03JHlJG4ILhiSrZr7YCvpvaiINtbLktpOLOh ujB9RXqwLmda1sQ6cAWJYpWRL7n3R4y1pcnBd0SO7lqydhngJv2K8E09gndhxFfT1GqA+wWWu V1gzqW52bxzYykEaIb3kMpXpzz6Lm4oslsGpxBWD2JotW9FI29Vkt3x09PvVTaNgb9e3E7lTS bpDr5bZlWRCqi94mqGR6vY3P4ARWPtWh2xQpbTiVNxFl/mEavOU+Egg7spifMEPhSLUpFiwZX xg+YJvVb5yEQI8N05KE/y7syNkvXrqvNWqFmpID466PrsCz3Vmt1xHLE6B4IHMGyx5cP04E1h NcOdSNOhsCnbpiOJNJOdN/vJdACLZXenyZrtmMLabYisyl9blyCb1KB3z3SPuxJ//RNFCKgQK WzvVtHuKtStfguYEV5rETXTXDO+o8QfbpnxDz6elU9OEV1J+bdSUdjdh+0COSPQQ58sFow+4E OuPU5E4QWmBXReDnJsjQKwxpMSEm9WjA74T3bgZIHqdTyOazFUFmzgZVtIL+/T9M9+qnrgaQL x0TTwLD8BNVRMx3I1ysaWy6WkwreHuKegXI4tVjU5Ar0Qb0bn1G1sZIWlnrvRIBBtgsMkDKde ehn5uCf2E+R0QRBNNPc9Z/uhwFkc9F5yjmguiwXTqSGnFOHc4riSIN0M5EN/Z8odwOeLhLwCJ wGHtQmJOqPFIvpXpxx6aawibzxXg0JVqs/A6UMRAuFz7xF0dbfxpyCZWi8YWouMeh3DfbYV4w 8hKAAKcW1NdDth4mthohG30ypbyeCQLEYWh9RABBpfpYJKTSLtegW+conJQy1Vdk185yY751Z ifBF9Jttev8m7ncWCL47erxIwR8= From: Markus Elfring Date: Wed, 27 Dec 2023 10:42:03 +0100 Move one assignment for the variable “phy_info” closer to the place where this pointer is used. Signed-off-by: Markus Elfring --- drivers/message/fusion/mptsas.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) -- 2.43.0 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c index 452635a50c4c..02f7d11fd828 100644 --- a/drivers/message/fusion/mptsas.c +++ b/drivers/message/fusion/mptsas.c @@ -4169,14 +4169,13 @@ static struct mptsas_phyinfo * mptsas_find_phyinfo_by_phys_disk_num(MPT_ADAPTER *ioc, u8 phys_disk_num, u8 channel, u8 id) { - struct mptsas_phyinfo *phy_info = NULL; + struct mptsas_phyinfo *phy_info; struct mptsas_portinfo *port_info; RaidPhysDiskPage1_t *phys_disk; int num_paths; u64 sas_address = 0; int i; - phy_info = NULL; if (!ioc->raid_data.pIocPg3) return NULL; /* dual port support */ @@ -4190,6 +4189,7 @@ mptsas_find_phyinfo_by_phys_disk_num(MPT_ADAPTER *ioc, u8 phys_disk_num, goto lock_mutex; mpt_raid_phys_disk_pg1(ioc, phys_disk_num, phys_disk); + phy_info = NULL; for (i = 0; i < num_paths; i++) { if ((phys_disk->Path[i].Flags & 1) != 0) /* entry no longer valid */