Commit b12a21e0 authored by Xingui Yang's avatar Xingui Yang Committed by Slim6882
Browse files

[Backport]scsi: libsas: Add a helper sas_get_sas_addr_and_dev_type()

mainline inclusion
from mainline-v6.8-rc1
commit a57345279fd311ba679b8083feb0eec5272c7729
category: cleanup
bugzilla: https://gitee.com/openeuler/kernel/issues/IB18PN
CVE: NA

Reference: https://lore.kernel.org/r/20240307141413.48049-2-yangxingui@huawei.com



------------------------------------------------------------------

Add a helper to get attached_sas_addr and device type from disc_resp.

Suggested-by: default avatarJohn Garry <john.g.garry@oracle.com>
Signed-off-by: default avatarXingui Yang <yangxingui@huawei.com>
Link: https://lore.kernel.org/r/20240307141413.48049-2-yangxingui@huawei.com


Reviewed-by: default avatarJohn Garry <john.g.garry@oracle.com>
Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: default avatarSlim6882 <yangjunshuo@huawei.com>
parent 291646a2
Loading
Loading
Loading
Loading
+12 −7
Original line number Diff line number Diff line
@@ -1694,6 +1694,16 @@ int sas_discover_root_expander(struct domain_device *dev)

/* ---------- Domain revalidation ---------- */

static void sas_get_sas_addr_and_dev_type(struct smp_disc_resp *disc_resp,
					  u8 *sas_addr,
					  enum sas_device_type *type)
{
	memcpy(sas_addr, disc_resp->disc.attached_sas_addr, SAS_ADDR_SIZE);
	*type = to_dev_type(&disc_resp->disc);
	if (*type == SAS_PHY_UNUSED)
		memset(sas_addr, 0, SAS_ADDR_SIZE);
}

static int sas_get_phy_discover(struct domain_device *dev,
				int phy_id, struct smp_disc_resp *disc_resp)
{
@@ -1747,13 +1757,8 @@ int sas_get_phy_attached_dev(struct domain_device *dev, int phy_id,
		return -ENOMEM;

	res = sas_get_phy_discover(dev, phy_id, disc_resp);
	if (res == 0) {
		memcpy(sas_addr, disc_resp->disc.attached_sas_addr,
		       SAS_ADDR_SIZE);
		*type = to_dev_type(&disc_resp->disc);
		if (*type == 0)
			memset(sas_addr, 0, SAS_ADDR_SIZE);
	}
	if (res == 0)
		sas_get_sas_addr_and_dev_type(disc_resp, sas_addr, type);
	kfree(disc_resp);
	return res;
}