[PATCH v1] ufs: core: Fix error handler host_sem issue

Bart Van Assche bvanassche at acm.org
Fri Oct 3 09:15:28 PDT 2025


On 10/3/25 3:10 AM, peter.wang at mediatek.com wrote:
> diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
> index 8185a7791923..9b1207dede64 100644
> --- a/drivers/ufs/core/ufshcd.c
> +++ b/drivers/ufs/core/ufshcd.c
> @@ -6670,6 +6670,14 @@ static void ufshcd_err_handler(struct work_struct *work)
>   		 hba->saved_uic_err, hba->force_reset,
>   		 ufshcd_is_link_broken(hba) ? "; link is broken" : "");
>   
> +	ufshcd_rpm_get_noresume(hba);
> +	if (hba->pm_op_in_progress) {
> +		ufshcd_link_recovery(hba);
> +		ufshcd_rpm_put(hba);
> +		return;
> +	}
> +	ufshcd_rpm_put(hba);
> +
>   	down(&hba->host_sem);
>   	spin_lock_irqsave(hba->host->host_lock, flags);
>   	if (ufshcd_err_handling_should_stop(hba)) {
> @@ -6681,14 +6689,6 @@ static void ufshcd_err_handler(struct work_struct *work)
>   	}
>   	spin_unlock_irqrestore(hba->host->host_lock, flags);
>   
> -	ufshcd_rpm_get_noresume(hba);
> -	if (hba->pm_op_in_progress) {
> -		ufshcd_link_recovery(hba);
> -		ufshcd_rpm_put(hba);
> -		return;
> -	}
> -	ufshcd_rpm_put(hba);
> -
>   	ufshcd_err_handling_prepare(hba);
>   
>   	spin_lock_irqsave(hba->host->host_lock, flags);

The purpose of hba->host_sem is to serialize power management
operations, error handling and sysfs callbacks. Hence, I think that
hba->host_sem should be held around the ufshcd_link_recovery() call
and hence that the code block that is moved by this patch should not
be moved.

Thanks,

Bart.



More information about the Linux-mediatek mailing list