diff mbox series

[v4,1/8] scsi: libsas: introduce sas address comparison helpers

Message ID 20220927032605.78103-2-yanaijie@huawei.com (mailing list archive)
State Superseded
Headers show
Series scsi: libsas: sas address comparison refactor | expand

Commit Message

Jason Yan Sept. 27, 2022, 3:25 a.m. UTC
Sas address comparison is widely used in libsas. However they are all
opencoded and to avoid the line spill over 80 columns, are mostly split
into multi-lines. Introduce some helpers to prepare some refactor.

Signed-off-by: Jason Yan <yanaijie@huawei.com>
Reviewed-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>
---
 drivers/scsi/libsas/sas_internal.h | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

Comments

John Garry Sept. 27, 2022, 8:38 a.m. UTC | #1
On 27/09/2022 04:25, Jason Yan wrote:
> Sas address comparison is widely used in libsas. However they are all
> opencoded and to avoid the line spill over 80 columns, are mostly split
> into multi-lines. Introduce some helpers to prepare some refactor.
> 
> Signed-off-by: Jason Yan <yanaijie@huawei.com>
> Reviewed-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>

Reviewed-by: John Garry <john.garry@huawei.com>

> ---
>   drivers/scsi/libsas/sas_internal.h | 17 +++++++++++++++++
>   1 file changed, 17 insertions(+)
> 
> diff --git a/drivers/scsi/libsas/sas_internal.h b/drivers/scsi/libsas/sas_internal.h
> index 8d0ad3abc7b5..3384429b7eb0 100644
> --- a/drivers/scsi/libsas/sas_internal.h
> +++ b/drivers/scsi/libsas/sas_internal.h
> @@ -111,6 +111,23 @@ static inline void sas_smp_host_handler(struct bsg_job *job,
>   }
>   #endif
>   
> +static inline bool sas_phy_match_dev_addr(struct domain_device *dev,
> +					 struct ex_phy *phy)
> +{
> +	return SAS_ADDR(dev->sas_addr) == SAS_ADDR(phy->attached_sas_addr);
> +}
> +
> +static inline bool sas_phy_match_port_addr(struct asd_sas_port *port,
> +					   struct ex_phy *phy)
> +{
> +	return SAS_ADDR(port->sas_addr) == SAS_ADDR(phy->attached_sas_addr);
> +}
> +
> +static inline bool sas_phy_addr_match(struct ex_phy *p1, struct ex_phy *p2)
> +{
> +	return  SAS_ADDR(p1->attached_sas_addr) == SAS_ADDR(p2->attached_sas_addr);
> +}
> +

note: I did think that we could use a macro as a generic matching API, like:

#define sas_phy_match_addr_common(x, ex_phy) \
	({ typeof(x) __dummy; \
	if (__builtin_types_compatible_p(typeof(__dummy), struct asd_sas_port))\
	sas_phy_match_port_addr(x, ex_phy);\
	if (__builtin_types_compatible_p(typeof(__dummy), struct domain_device))\
	sas_phy_match_dev_addr(x, ex_phy);\
	0; \
})

But I couldn't get it to work after 60 minutes of messing ... indeed, 
that latest code doesn't even compile..

Thanks,
John

>   static inline void sas_fail_probe(struct domain_device *dev, const char *func, int err)
>   {
>   	pr_warn("%s: for %s device %016llx returned %d\n",
diff mbox series

Patch

diff --git a/drivers/scsi/libsas/sas_internal.h b/drivers/scsi/libsas/sas_internal.h
index 8d0ad3abc7b5..3384429b7eb0 100644
--- a/drivers/scsi/libsas/sas_internal.h
+++ b/drivers/scsi/libsas/sas_internal.h
@@ -111,6 +111,23 @@  static inline void sas_smp_host_handler(struct bsg_job *job,
 }
 #endif
 
+static inline bool sas_phy_match_dev_addr(struct domain_device *dev,
+					 struct ex_phy *phy)
+{
+	return SAS_ADDR(dev->sas_addr) == SAS_ADDR(phy->attached_sas_addr);
+}
+
+static inline bool sas_phy_match_port_addr(struct asd_sas_port *port,
+					   struct ex_phy *phy)
+{
+	return SAS_ADDR(port->sas_addr) == SAS_ADDR(phy->attached_sas_addr);
+}
+
+static inline bool sas_phy_addr_match(struct ex_phy *p1, struct ex_phy *p2)
+{
+	return  SAS_ADDR(p1->attached_sas_addr) == SAS_ADDR(p2->attached_sas_addr);
+}
+
 static inline void sas_fail_probe(struct domain_device *dev, const char *func, int err)
 {
 	pr_warn("%s: for %s device %016llx returned %d\n",