diff mbox series

[6/6] scsi: libsas: factor out sas_ex_add_dev()

Message ID 20221204081643.3835966-7-yanaijie@huawei.com (mailing list archive)
State Superseded
Headers show
Series scsi: libsas: Some coding style fixes and cleanups | expand

Commit Message

Jason Yan Dec. 4, 2022, 8:16 a.m. UTC
Factor out sas_ex_add_dev() to be consistent with sas_ata_add_dev() and
unify the error handling.

Cc: John Garry <john.g.garry@oracle.com>
Signed-off-by: Jason Yan <yanaijie@huawei.com>
---
 drivers/scsi/libsas/sas_expander.c | 68 +++++++++++++++++-------------
 1 file changed, 39 insertions(+), 29 deletions(-)

Comments

John Garry Dec. 5, 2022, 9:31 a.m. UTC | #1
On 04/12/2022 08:16, Jason Yan wrote:
> Factor out sas_ex_add_dev() to be consistent with sas_ata_add_dev() and
> unify the error handling.
> 
> Cc: John Garry <john.g.garry@oracle.com>
> Signed-off-by: Jason Yan <yanaijie@huawei.com>
> ---
>   drivers/scsi/libsas/sas_expander.c | 68 +++++++++++++++++-------------
>   1 file changed, 39 insertions(+), 29 deletions(-)
> 
> diff --git a/drivers/scsi/libsas/sas_expander.c b/drivers/scsi/libsas/sas_expander.c
> index 747f4fc795f4..3c72b167d43a 100644
> --- a/drivers/scsi/libsas/sas_expander.c
> +++ b/drivers/scsi/libsas/sas_expander.c
> @@ -751,13 +751,46 @@ static void sas_ex_get_linkrate(struct domain_device *parent,
>   	child->pathways = min(child->pathways, parent->pathways);
>   }
>   
> +static int sas_ex_add_dev(struct domain_device *parent, struct ex_phy *phy,
> +			  struct domain_device *child, int phy_id)
> +{
> +	struct sas_rphy *rphy;
> +	int res;
> +
> +	child->dev_type = SAS_END_DEVICE;
> +	rphy = sas_end_device_alloc(phy->port);
> +	if (unlikely(!rphy))

nit: this is not fastpath so unlikely can be avoided

> +		return -ENOMEM;
> +
> +	child->tproto = phy->attached_tproto;
> +	sas_init_dev(child);
> +
> +	child->rphy = rphy;
> +	get_device(&rphy->dev);
> +	rphy->identify.phy_identifier = phy_id;
> +	sas_fill_in_rphy(child, rphy);
> +
> +	list_add_tail(&child->disco_list_node, &parent->port->disco_list);
> +
> +	res = sas_notify_lldd_dev_found(child);
> +	if (res) {
> +		pr_notice("notify lldd for device %016llx at %016llx:%02d returned 0x%x\n",
> +				SAS_ADDR(child->sas_addr),
> +				SAS_ADDR(parent->sas_addr), phy_id, res);

nit: these lines could be aligned with (, as it was before

> +		sas_rphy_free(child->rphy);
> +		list_del(&child->disco_list_node);
> +		return res;
> +	}
> +
> +	return 0;
> +}
> +
>   static struct domain_device *sas_ex_discover_end_dev(
>   	struct domain_device *parent, int phy_id)
>   {
>   	struct expander_device *parent_ex = &parent->ex_dev;
>   	struct ex_phy *phy = &parent_ex->ex_phy[phy_id];
>   	struct domain_device *child = NULL;
> -	struct sas_rphy *rphy;
>   	int res;
>   
>   	if (phy->attached_sata_host || phy->attached_sata_ps)
> @@ -787,44 +820,21 @@ static struct domain_device *sas_ex_discover_end_dev(
>   
>   	if ((phy->attached_tproto & SAS_PROTOCOL_STP) || phy->attached_sata_dev) {
>   		res = sas_ata_add_dev(parent, phy, child, phy_id);
> -		if (res)
> -			goto out_free;
>   	} else if (phy->attached_tproto & SAS_PROTOCOL_SSP) {
> -		child->dev_type = SAS_END_DEVICE;
> -		rphy = sas_end_device_alloc(phy->port);
> -		/* FIXME: error handling */

so has the error handling been fixed now?

> -		if (unlikely(!rphy))
> -			goto out_free;
> -		child->tproto = phy->attached_tproto;
> -		sas_init_dev(child);
> -
> -		child->rphy = rphy;
> -		get_device(&rphy->dev);
> -		rphy->identify.phy_identifier = phy_id;
> -		sas_fill_in_rphy(child, rphy);
> -
> -		list_add_tail(&child->disco_list_node, &parent->port->disco_list);
> -
> -		res = sas_notify_lldd_dev_found(child);
> -		if (res) {
> -			pr_notice("notify lldd for device %016llx at %016llx:%02d returned 0x%x\n",
> -				  SAS_ADDR(child->sas_addr),
> -				  SAS_ADDR(parent->sas_addr), phy_id, res);
> -			goto out_list_del;
> -		}
> +		res = sas_ex_add_dev(parent, phy, child, phy_id);
>   	} else {
>   		pr_notice("target proto 0x%x at %016llx:0x%x not handled\n",
>   			  phy->attached_tproto, SAS_ADDR(parent->sas_addr),
>   			  phy_id);
> -		goto out_free;
> +		res = -ENODEV;
>   	}
>   
> +	if (res)
> +		goto out_free;
> +
>   	list_add_tail(&child->siblings, &parent_ex->children);
>   	return child;
>   
> - out_list_del:
> -	sas_rphy_free(child->rphy);
> -	list_del(&child->disco_list_node);
>    out_free:
>   	sas_port_delete(phy->port);
>    out_err:
Jason Yan Dec. 8, 2022, 8:07 a.m. UTC | #2
On 2022/12/5 17:31, John Garry wrote:
> On 04/12/2022 08:16, Jason Yan wrote:
>> Factor out sas_ex_add_dev() to be consistent with sas_ata_add_dev() and
>> unify the error handling.
>>
>> Cc: John Garry <john.g.garry@oracle.com>
>> Signed-off-by: Jason Yan <yanaijie@huawei.com>
>> ---
>>   drivers/scsi/libsas/sas_expander.c | 68 +++++++++++++++++-------------
>>   1 file changed, 39 insertions(+), 29 deletions(-)
>>
>> diff --git a/drivers/scsi/libsas/sas_expander.c 
>> b/drivers/scsi/libsas/sas_expander.c
>> index 747f4fc795f4..3c72b167d43a 100644
>> --- a/drivers/scsi/libsas/sas_expander.c
>> +++ b/drivers/scsi/libsas/sas_expander.c
>> @@ -751,13 +751,46 @@ static void sas_ex_get_linkrate(struct 
>> domain_device *parent,
>>       child->pathways = min(child->pathways, parent->pathways);
>>   }
>> +static int sas_ex_add_dev(struct domain_device *parent, struct ex_phy 
>> *phy,
>> +              struct domain_device *child, int phy_id)
>> +{
>> +    struct sas_rphy *rphy;
>> +    int res;
>> +
>> +    child->dev_type = SAS_END_DEVICE;
>> +    rphy = sas_end_device_alloc(phy->port);
>> +    if (unlikely(!rphy))
> 
> nit: this is not fastpath so unlikely can be avoided
> 

ok. It is only a hint for the compiler so not a big deal. I can delete it.

>> +        return -ENOMEM;
>> +
>> +    child->tproto = phy->attached_tproto;
>> +    sas_init_dev(child);
>> +
>> +    child->rphy = rphy;
>> +    get_device(&rphy->dev);
>> +    rphy->identify.phy_identifier = phy_id;
>> +    sas_fill_in_rphy(child, rphy);
>> +
>> +    list_add_tail(&child->disco_list_node, &parent->port->disco_list);
>> +
>> +    res = sas_notify_lldd_dev_found(child);
>> +    if (res) {
>> +        pr_notice("notify lldd for device %016llx at %016llx:%02d 
>> returned 0x%x\n",
>> +                SAS_ADDR(child->sas_addr),
>> +                SAS_ADDR(parent->sas_addr), phy_id, res);
> 
> nit: these lines could be aligned with (, as it was before

Nice catch. Will fix.

> 
>> +        sas_rphy_free(child->rphy);
>> +        list_del(&child->disco_list_node);
>> +        return res;
>> +    }
>> +
>> +    return 0;
>> +}
>> +
>>   static struct domain_device *sas_ex_discover_end_dev(
>>       struct domain_device *parent, int phy_id)
>>   {
>>       struct expander_device *parent_ex = &parent->ex_dev;
>>       struct ex_phy *phy = &parent_ex->ex_phy[phy_id];
>>       struct domain_device *child = NULL;
>> -    struct sas_rphy *rphy;
>>       int res;
>>       if (phy->attached_sata_host || phy->attached_sata_ps)
>> @@ -787,44 +820,21 @@ static struct domain_device 
>> *sas_ex_discover_end_dev(
>>       if ((phy->attached_tproto & SAS_PROTOCOL_STP) || 
>> phy->attached_sata_dev) {
>>           res = sas_ata_add_dev(parent, phy, child, phy_id);
>> -        if (res)
>> -            goto out_free;
>>       } else if (phy->attached_tproto & SAS_PROTOCOL_SSP) {
>> -        child->dev_type = SAS_END_DEVICE;
>> -        rphy = sas_end_device_alloc(phy->port);
>> -        /* FIXME: error handling */
> 
> so has the error handling been fixed now?

IIUC, the error handling is ok so this comment can be deleted.

Thanks,
Jason
diff mbox series

Patch

diff --git a/drivers/scsi/libsas/sas_expander.c b/drivers/scsi/libsas/sas_expander.c
index 747f4fc795f4..3c72b167d43a 100644
--- a/drivers/scsi/libsas/sas_expander.c
+++ b/drivers/scsi/libsas/sas_expander.c
@@ -751,13 +751,46 @@  static void sas_ex_get_linkrate(struct domain_device *parent,
 	child->pathways = min(child->pathways, parent->pathways);
 }
 
+static int sas_ex_add_dev(struct domain_device *parent, struct ex_phy *phy,
+			  struct domain_device *child, int phy_id)
+{
+	struct sas_rphy *rphy;
+	int res;
+
+	child->dev_type = SAS_END_DEVICE;
+	rphy = sas_end_device_alloc(phy->port);
+	if (unlikely(!rphy))
+		return -ENOMEM;
+
+	child->tproto = phy->attached_tproto;
+	sas_init_dev(child);
+
+	child->rphy = rphy;
+	get_device(&rphy->dev);
+	rphy->identify.phy_identifier = phy_id;
+	sas_fill_in_rphy(child, rphy);
+
+	list_add_tail(&child->disco_list_node, &parent->port->disco_list);
+
+	res = sas_notify_lldd_dev_found(child);
+	if (res) {
+		pr_notice("notify lldd for device %016llx at %016llx:%02d returned 0x%x\n",
+				SAS_ADDR(child->sas_addr),
+				SAS_ADDR(parent->sas_addr), phy_id, res);
+		sas_rphy_free(child->rphy);
+		list_del(&child->disco_list_node);
+		return res;
+	}
+
+	return 0;
+}
+
 static struct domain_device *sas_ex_discover_end_dev(
 	struct domain_device *parent, int phy_id)
 {
 	struct expander_device *parent_ex = &parent->ex_dev;
 	struct ex_phy *phy = &parent_ex->ex_phy[phy_id];
 	struct domain_device *child = NULL;
-	struct sas_rphy *rphy;
 	int res;
 
 	if (phy->attached_sata_host || phy->attached_sata_ps)
@@ -787,44 +820,21 @@  static struct domain_device *sas_ex_discover_end_dev(
 
 	if ((phy->attached_tproto & SAS_PROTOCOL_STP) || phy->attached_sata_dev) {
 		res = sas_ata_add_dev(parent, phy, child, phy_id);
-		if (res)
-			goto out_free;
 	} else if (phy->attached_tproto & SAS_PROTOCOL_SSP) {
-		child->dev_type = SAS_END_DEVICE;
-		rphy = sas_end_device_alloc(phy->port);
-		/* FIXME: error handling */
-		if (unlikely(!rphy))
-			goto out_free;
-		child->tproto = phy->attached_tproto;
-		sas_init_dev(child);
-
-		child->rphy = rphy;
-		get_device(&rphy->dev);
-		rphy->identify.phy_identifier = phy_id;
-		sas_fill_in_rphy(child, rphy);
-
-		list_add_tail(&child->disco_list_node, &parent->port->disco_list);
-
-		res = sas_notify_lldd_dev_found(child);
-		if (res) {
-			pr_notice("notify lldd for device %016llx at %016llx:%02d returned 0x%x\n",
-				  SAS_ADDR(child->sas_addr),
-				  SAS_ADDR(parent->sas_addr), phy_id, res);
-			goto out_list_del;
-		}
+		res = sas_ex_add_dev(parent, phy, child, phy_id);
 	} else {
 		pr_notice("target proto 0x%x at %016llx:0x%x not handled\n",
 			  phy->attached_tproto, SAS_ADDR(parent->sas_addr),
 			  phy_id);
-		goto out_free;
+		res = -ENODEV;
 	}
 
+	if (res)
+		goto out_free;
+
 	list_add_tail(&child->siblings, &parent_ex->children);
 	return child;
 
- out_list_del:
-	sas_rphy_free(child->rphy);
-	list_del(&child->disco_list_node);
  out_free:
 	sas_port_delete(phy->port);
  out_err: