Linux SCSI subsystem development
 help / color / mirror / Atom feed
From: Damien Le Moal <dlemoal@kernel.org>
To: Chaohai Chen <wdhh6@aliyun.com>,
	john.g.garry@oracle.com, yanaijie@huawei.com,
	James.Bottomley@HansenPartnership.com,
	martin.petersen@oracle.com
Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] scsi: libsas: Add error handling in the sas_register_phys()
Date: Fri, 5 Dec 2025 17:27:46 +0900	[thread overview]
Message-ID: <fbaefe65-3400-48a7-903a-708fa1ffcf00@kernel.org> (raw)
In-Reply-To: <20251205080252.1020028-1-wdhh6@aliyun.com>

On 12/5/25 17:02, Chaohai Chen wrote:
> If an error is triggered in the loop process, we need to roll back
> the resources that have already been requested.
> 
> Signed-off-by: Chaohai Chen <wdhh6@aliyun.com>
> ---
>  drivers/scsi/libsas/sas_phy.c | 21 ++++++++++++++++++---
>  1 file changed, 18 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/scsi/libsas/sas_phy.c b/drivers/scsi/libsas/sas_phy.c
> index 635835c28ecd..455118c7e889 100644
> --- a/drivers/scsi/libsas/sas_phy.c
> +++ b/drivers/scsi/libsas/sas_phy.c
> @@ -116,6 +116,7 @@ static void sas_phye_shutdown(struct work_struct *work)
>  int sas_register_phys(struct sas_ha_struct *sas_ha)
>  {
>  	int i;
> +	int ret = 0;

"= 0" assignment does not seem to be needed here.

>  
>  	/* Now register the phys. */
>  	for (i = 0; i < sas_ha->num_phys; i++) {
> @@ -132,8 +133,10 @@ int sas_register_phys(struct sas_ha_struct *sas_ha)
>  		phy->frame_rcvd_size = 0;
>  
>  		phy->phy = sas_phy_alloc(&sas_ha->shost->shost_gendev, i);
> -		if (!phy->phy)
> -			return -ENOMEM;
> +		if (!phy->phy) {
> +			ret = -ENOMEM;
> +			goto fail;

Please call the label using a descriptive name. E.g. "goto delete_phy;"

> +		}
>  
>  		phy->phy->identify.initiator_port_protocols =
>  			phy->iproto;
> @@ -146,10 +149,22 @@ int sas_register_phys(struct sas_ha_struct *sas_ha)
>  		phy->phy->maximum_linkrate = SAS_LINK_RATE_UNKNOWN;
>  		phy->phy->negotiated_linkrate = SAS_LINK_RATE_UNKNOWN;
>  
> -		sas_phy_add(phy->phy);
> +		ret = sas_phy_add(phy->phy);
> +		if (ret) {
> +			sas_phy_free(phy->phy);
> +			goto fail;
> +		}
>  	}
>  
>  	return 0;
> +fail:
> +	for (i--; i >= 0; i--) {
> +		struct asd_sas_phy *phy = sas_ha->sas_phy[i];
> +
> +		sas_phy_delete(phy->phy);
> +		sas_phy_free(phy);
> +	}
> +	return ret;
>  }
>  
>  const work_func_t sas_phy_event_fns[PHY_NUM_EVENTS] = {


-- 
Damien Le Moal
Western Digital Research

  reply	other threads:[~2025-12-05  8:27 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-05  8:02 [PATCH] scsi: libsas: Add error handling in the sas_register_phys() Chaohai Chen
2025-12-05  8:27 ` Damien Le Moal [this message]
2025-12-05  9:52 ` Jason Yan
2025-12-06  4:32 ` kernel test robot
2025-12-06  7:39 ` kernel test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=fbaefe65-3400-48a7-903a-708fa1ffcf00@kernel.org \
    --to=dlemoal@kernel.org \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=john.g.garry@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=wdhh6@aliyun.com \
    --cc=yanaijie@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox