linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] scsi: message: fusion: Adjustments for mptsas_find_phyinfo_by_phys_disk_num()
@ 2023-12-27 10:02 Markus Elfring
  2023-12-27 10:04 ` [PATCH 1/2] scsi: message: fusion: Improve data processing in mptsas_find_phyinfo_by_phys_disk_num() Markus Elfring
  2023-12-27 10:06 ` [PATCH 2/2] scsi: message: fusion: Move an assignment for the variable “phy_info” " Markus Elfring
  0 siblings, 2 replies; 3+ messages in thread
From: Markus Elfring @ 2023-12-27 10:02 UTC (permalink / raw)
  To: linux-scsi, MPT-FusionLinux.pdl, kernel-janitors, Sathya Prakash,
	Sreekanth Reddy, Suganath Prabu Subramani
  Cc: LKML, cocci

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 27 Dec 2023 10:54:32 +0100

A few update suggestions were taken into account
from static source code analysis.

Markus Elfring (2):
  Improve data processing
  Move an assignment for the variable “phy_info”

 drivers/message/fusion/mptsas.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

--
2.43.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] scsi: message: fusion: Improve data processing in mptsas_find_phyinfo_by_phys_disk_num()
  2023-12-27 10:02 [PATCH 0/2] scsi: message: fusion: Adjustments for mptsas_find_phyinfo_by_phys_disk_num() Markus Elfring
@ 2023-12-27 10:04 ` Markus Elfring
  2023-12-27 10:06 ` [PATCH 2/2] scsi: message: fusion: Move an assignment for the variable “phy_info” " Markus Elfring
  1 sibling, 0 replies; 3+ messages in thread
From: Markus Elfring @ 2023-12-27 10:04 UTC (permalink / raw)
  To: linux-scsi, MPT-FusionLinux.pdl, kernel-janitors, Sathya Prakash,
	Sreekanth Reddy, Suganath Prabu Subramani
  Cc: LKML, cocci

From: Markus Elfring <elfring@users.sourceforge.net>
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 <elfring@users.sourceforge.net>
---
 drivers/message/fusion/mptsas.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

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++) {
--
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] scsi: message: fusion: Move an assignment for the variable “phy_info” in mptsas_find_phyinfo_by_phys_disk_num()
  2023-12-27 10:02 [PATCH 0/2] scsi: message: fusion: Adjustments for mptsas_find_phyinfo_by_phys_disk_num() Markus Elfring
  2023-12-27 10:04 ` [PATCH 1/2] scsi: message: fusion: Improve data processing in mptsas_find_phyinfo_by_phys_disk_num() Markus Elfring
@ 2023-12-27 10:06 ` Markus Elfring
  1 sibling, 0 replies; 3+ messages in thread
From: Markus Elfring @ 2023-12-27 10:06 UTC (permalink / raw)
  To: linux-scsi, MPT-FusionLinux.pdl, kernel-janitors, Sathya Prakash,
	Sreekanth Reddy, Suganath Prabu Subramani
  Cc: LKML, cocci

From: Markus Elfring <elfring@users.sourceforge.net>
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 <elfring@users.sourceforge.net>
---
 drivers/message/fusion/mptsas.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

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 */
--
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-12-27 10:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-27 10:02 [PATCH 0/2] scsi: message: fusion: Adjustments for mptsas_find_phyinfo_by_phys_disk_num() Markus Elfring
2023-12-27 10:04 ` [PATCH 1/2] scsi: message: fusion: Improve data processing in mptsas_find_phyinfo_by_phys_disk_num() Markus Elfring
2023-12-27 10:06 ` [PATCH 2/2] scsi: message: fusion: Move an assignment for the variable “phy_info” " Markus Elfring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).