diff mbox series

[v4,06/10] scsi: ufs: core: Move the ufshcd_device_init(hba, true) call

Message ID 20240905220214.738506-7-bvanassche@acm.org
State New
Headers show
Series Simplify the UFS driver initialization code | expand

Commit Message

Bart Van Assche Sept. 5, 2024, 10:01 p.m. UTC
Move the ufshcd_device_init(hba, true) call from ufshcd_async_scan()
into ufshcd_init(). This patch prepares for moving both scsi_add_host()
calls into ufshcd_add_scsi_host(). Calling ufshcd_device_init() from
ufshcd_init() without holding hba->host_sem is safe. This is safe because
hba->host_sem serializes core code and sysfs callbacks. The
ufshcd_device_init() call is moved before the scsi_add_host() call and
hence happens before any SCSI sysfs attributes are created.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
 drivers/ufs/core/ufshcd.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

Comments

Bao D. Nguyen Sept. 7, 2024, 7:38 p.m. UTC | #1
On 9/5/2024 3:01 PM, Bart Van Assche wrote:
> Move the ufshcd_device_init(hba, true) call from ufshcd_async_scan()
> into ufshcd_init(). This patch prepares for moving both scsi_add_host()
> calls into ufshcd_add_scsi_host(). Calling ufshcd_device_init() from
> ufshcd_init() without holding hba->host_sem is safe. This is safe because
> hba->host_sem serializes core code and sysfs callbacks. The
> ufshcd_device_init() call is moved before the scsi_add_host() call and
> hence happens before any SCSI sysfs attributes are created.
> 
> Signed-off-by: Bart Van Assche <bvanassche@acm.org>
> ---
>   drivers/ufs/core/ufshcd.c | 9 +++++----
>   1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
> index 6e3cffcdf9a6..843566720afa 100644
> --- a/drivers/ufs/core/ufshcd.c
> +++ b/drivers/ufs/core/ufshcd.c
> @@ -8908,10 +8908,7 @@ static void ufshcd_async_scan(void *data, async_cookie_t cookie)
>   	int ret;
>   
>   	down(&hba->host_sem);
> -	/* Initialize hba, detect and initialize UFS device */
> -	ret = ufshcd_device_init(hba, /*init_dev_params=*/true);
> -	if (ret == 0)
> -		ret = ufshcd_probe_hba(hba);
> +	ret = ufshcd_probe_hba(hba);
>   	up(&hba->host_sem);
>   	if (ret)
>   		goto out;
> @@ -10605,6 +10602,10 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq)
>   	 */
>   	ufshcd_set_ufs_dev_active(hba);
>   
> +	err = ufshcd_device_init(hba, /*init_dev_params=*/true);
> +	if (err)
> +		goto out_disable;
> +

In SDB mode, the order of execution for these two functions changed by 
this patch. In the original code, the scsi_add_host() happens first, 
then the code within ufshcd_post_device_init(). Here it is the opposite. 
However, it seems the order can be swapped without any issue.

>   	err = ufshcd_add_scsi_host(hba);
>   	if (err)
>   		goto out_disable;
>
diff mbox series

Patch

diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
index 6e3cffcdf9a6..843566720afa 100644
--- a/drivers/ufs/core/ufshcd.c
+++ b/drivers/ufs/core/ufshcd.c
@@ -8908,10 +8908,7 @@  static void ufshcd_async_scan(void *data, async_cookie_t cookie)
 	int ret;
 
 	down(&hba->host_sem);
-	/* Initialize hba, detect and initialize UFS device */
-	ret = ufshcd_device_init(hba, /*init_dev_params=*/true);
-	if (ret == 0)
-		ret = ufshcd_probe_hba(hba);
+	ret = ufshcd_probe_hba(hba);
 	up(&hba->host_sem);
 	if (ret)
 		goto out;
@@ -10605,6 +10602,10 @@  int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq)
 	 */
 	ufshcd_set_ufs_dev_active(hba);
 
+	err = ufshcd_device_init(hba, /*init_dev_params=*/true);
+	if (err)
+		goto out_disable;
+
 	err = ufshcd_add_scsi_host(hba);
 	if (err)
 		goto out_disable;