From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2AF71C6FA83 for ; Tue, 27 Sep 2022 08:39:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229617AbiI0Ij1 (ORCPT ); Tue, 27 Sep 2022 04:39:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231278AbiI0IjD (ORCPT ); Tue, 27 Sep 2022 04:39:03 -0400 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E906345069; Tue, 27 Sep 2022 01:38:30 -0700 (PDT) Received: from fraeml711-chm.china.huawei.com (unknown [172.18.147.226]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4McCh34XGDz687w4; Tue, 27 Sep 2022 16:38:27 +0800 (CST) Received: from lhrpeml500003.china.huawei.com (7.191.162.67) by fraeml711-chm.china.huawei.com (10.206.15.60) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 27 Sep 2022 10:38:28 +0200 Received: from [10.48.156.245] (10.48.156.245) by lhrpeml500003.china.huawei.com (7.191.162.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 27 Sep 2022 09:38:27 +0100 Message-ID: Date: Tue, 27 Sep 2022 09:38:30 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.6.1 Subject: Re: [PATCH v4 1/8] scsi: libsas: introduce sas address comparison helpers To: Jason Yan , , CC: , , , , , , References: <20220927032605.78103-1-yanaijie@huawei.com> <20220927032605.78103-2-yanaijie@huawei.com> From: John Garry In-Reply-To: <20220927032605.78103-2-yanaijie@huawei.com> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [10.48.156.245] X-ClientProxiedBy: lhrpeml100002.china.huawei.com (7.191.160.241) To lhrpeml500003.china.huawei.com (7.191.162.67) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > Reviewed-by: Damien Le Moal Reviewed-by: John Garry > --- > 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",