diff mbox series

[03/29] scsi: ufs: Simplify statements that return a boolean

Message ID 20220331223424.1054715-4-bvanassche@acm.org
State New
Headers show
Series UFS patches for kernel v5.19 | expand

Commit Message

Bart Van Assche March 31, 2022, 10:33 p.m. UTC
Convert "if (expr) return true; else return false;" into "return expr;"
if either 'expr' is a boolean expression or the return type of the
function is 'bool'.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
 drivers/scsi/ufs/ufs-qcom.h |  5 +----
 drivers/scsi/ufs/ufshcd.c   | 22 +++++-----------------
 2 files changed, 6 insertions(+), 21 deletions(-)

Comments

Bjorn Andersson March 31, 2022, 11:45 p.m. UTC | #1
On Thu 31 Mar 15:33 PDT 2022, Bart Van Assche wrote:

> Convert "if (expr) return true; else return false;" into "return expr;"
> if either 'expr' is a boolean expression or the return type of the
> function is 'bool'.
> 
> Signed-off-by: Bart Van Assche <bvanassche@acm.org>

Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>

> ---
>  drivers/scsi/ufs/ufs-qcom.h |  5 +----
>  drivers/scsi/ufs/ufshcd.c   | 22 +++++-----------------
>  2 files changed, 6 insertions(+), 21 deletions(-)
> 
> diff --git a/drivers/scsi/ufs/ufs-qcom.h b/drivers/scsi/ufs/ufs-qcom.h
> index 8208e3a3ef59..51570224a6e2 100644
> --- a/drivers/scsi/ufs/ufs-qcom.h
> +++ b/drivers/scsi/ufs/ufs-qcom.h
> @@ -239,10 +239,7 @@ int ufs_qcom_testbus_config(struct ufs_qcom_host *host);
>  
>  static inline bool ufs_qcom_cap_qunipro(struct ufs_qcom_host *host)
>  {
> -	if (host->caps & UFS_QCOM_CAP_QUNIPRO)
> -		return true;
> -	else
> -		return false;
> +	return host->caps & UFS_QCOM_CAP_QUNIPRO;
>  }
>  
>  /* ufs-qcom-ice.c */
> diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
> index 983fac14b7cd..c60519372b3b 100644
> --- a/drivers/scsi/ufs/ufshcd.c
> +++ b/drivers/scsi/ufs/ufshcd.c
> @@ -939,10 +939,7 @@ static bool ufshcd_is_unipro_pa_params_tuning_req(struct ufs_hba *hba)
>  	 * logic simple, we will only do manual tuning if local unipro version
>  	 * doesn't support ver1.6 or later.
>  	 */
> -	if (ufshcd_get_local_unipro_ver(hba) < UFS_UNIPRO_VER_1_6)
> -		return true;
> -	else
> -		return false;
> +	return ufshcd_get_local_unipro_ver(hba) < UFS_UNIPRO_VER_1_6;
>  }
>  
>  /**
> @@ -2216,10 +2213,7 @@ static inline int ufshcd_hba_capabilities(struct ufs_hba *hba)
>   */
>  static inline bool ufshcd_ready_for_uic_cmd(struct ufs_hba *hba)
>  {
> -	if (ufshcd_readl(hba, REG_CONTROLLER_STATUS) & UIC_COMMAND_READY)
> -		return true;
> -	else
> -		return false;
> +	return ufshcd_readl(hba, REG_CONTROLLER_STATUS) & UIC_COMMAND_READY;
>  }
>  
>  /**
> @@ -5781,10 +5775,7 @@ static bool ufshcd_wb_presrv_usrspc_keep_vcc_on(struct ufs_hba *hba,
>  		return false;
>  	}
>  	/* Let it continue to flush when available buffer exceeds threshold */
> -	if (avail_buf < hba->vps->wb_flush_threshold)
> -		return true;
> -
> -	return false;
> +	return avail_buf < hba->vps->wb_flush_threshold;
>  }
>  
>  static void ufshcd_wb_force_disable(struct ufs_hba *hba)
> @@ -5863,11 +5854,8 @@ static bool ufshcd_wb_need_flush(struct ufs_hba *hba)
>  		return false;
>  	}
>  
> -	if (!hba->dev_info.b_presrv_uspc_en) {
> -		if (avail_buf <= UFS_WB_BUF_REMAIN_PERCENT(10))
> -			return true;
> -		return false;
> -	}
> +	if (!hba->dev_info.b_presrv_uspc_en)
> +		return avail_buf <= UFS_WB_BUF_REMAIN_PERCENT(10);
>  
>  	return ufshcd_wb_presrv_usrspc_keep_vcc_on(hba, avail_buf);
>  }
Avri Altman April 1, 2022, 6:49 p.m. UTC | #2
> Convert "if (expr) return true; else return false;" into "return expr;"
> if either 'expr' is a boolean expression or the return type of the function is 'bool'.
> 
> Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Maybe also add ufshpb_is_pinned_region()

Thanks,
Avri

> ---
>  drivers/scsi/ufs/ufs-qcom.h |  5 +----
>  drivers/scsi/ufs/ufshcd.c   | 22 +++++-----------------
>  2 files changed, 6 insertions(+), 21 deletions(-)
> 
> diff --git a/drivers/scsi/ufs/ufs-qcom.h b/drivers/scsi/ufs/ufs-qcom.h index
> 8208e3a3ef59..51570224a6e2 100644
> --- a/drivers/scsi/ufs/ufs-qcom.h
> +++ b/drivers/scsi/ufs/ufs-qcom.h
> @@ -239,10 +239,7 @@ int ufs_qcom_testbus_config(struct ufs_qcom_host
> *host);
> 
>  static inline bool ufs_qcom_cap_qunipro(struct ufs_qcom_host *host)  {
> -       if (host->caps & UFS_QCOM_CAP_QUNIPRO)
> -               return true;
> -       else
> -               return false;
> +       return host->caps & UFS_QCOM_CAP_QUNIPRO;
>  }
> 
>  /* ufs-qcom-ice.c */
> diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index
> 983fac14b7cd..c60519372b3b 100644
> --- a/drivers/scsi/ufs/ufshcd.c
> +++ b/drivers/scsi/ufs/ufshcd.c
> @@ -939,10 +939,7 @@ static bool
> ufshcd_is_unipro_pa_params_tuning_req(struct ufs_hba *hba)
>          * logic simple, we will only do manual tuning if local unipro version
>          * doesn't support ver1.6 or later.
>          */
> -       if (ufshcd_get_local_unipro_ver(hba) < UFS_UNIPRO_VER_1_6)
> -               return true;
> -       else
> -               return false;
> +       return ufshcd_get_local_unipro_ver(hba) < UFS_UNIPRO_VER_1_6;
>  }
> 
>  /**
> @@ -2216,10 +2213,7 @@ static inline int ufshcd_hba_capabilities(struct
> ufs_hba *hba)
>   */
>  static inline bool ufshcd_ready_for_uic_cmd(struct ufs_hba *hba)  {
> -       if (ufshcd_readl(hba, REG_CONTROLLER_STATUS) &
> UIC_COMMAND_READY)
> -               return true;
> -       else
> -               return false;
> +       return ufshcd_readl(hba, REG_CONTROLLER_STATUS) &
> + UIC_COMMAND_READY;
>  }
> 
>  /**
> @@ -5781,10 +5775,7 @@ static bool
> ufshcd_wb_presrv_usrspc_keep_vcc_on(struct ufs_hba *hba,
>                 return false;
>         }
>         /* Let it continue to flush when available buffer exceeds threshold */
> -       if (avail_buf < hba->vps->wb_flush_threshold)
> -               return true;
> -
> -       return false;
> +       return avail_buf < hba->vps->wb_flush_threshold;
>  }
> 
>  static void ufshcd_wb_force_disable(struct ufs_hba *hba) @@ -5863,11
> +5854,8 @@ static bool ufshcd_wb_need_flush(struct ufs_hba *hba)
>                 return false;
>         }
> 
> -       if (!hba->dev_info.b_presrv_uspc_en) {
> -               if (avail_buf <= UFS_WB_BUF_REMAIN_PERCENT(10))
> -                       return true;
> -               return false;
> -       }
> +       if (!hba->dev_info.b_presrv_uspc_en)
> +               return avail_buf <= UFS_WB_BUF_REMAIN_PERCENT(10);
> 
>         return ufshcd_wb_presrv_usrspc_keep_vcc_on(hba, avail_buf);  }
Bart Van Assche April 3, 2022, 3:30 a.m. UTC | #3
On 4/1/22 11:49, Avri Altman wrote:
>   
>> Convert "if (expr) return true; else return false;" into "return expr;"
>> if either 'expr' is a boolean expression or the return type of the function is 'bool'.
>>
>> Signed-off-by: Bart Van Assche <bvanassche@acm.org>
> Maybe also add ufshpb_is_pinned_region()

Thanks for the feedback. I will take a look at that function.

Bart.
diff mbox series

Patch

diff --git a/drivers/scsi/ufs/ufs-qcom.h b/drivers/scsi/ufs/ufs-qcom.h
index 8208e3a3ef59..51570224a6e2 100644
--- a/drivers/scsi/ufs/ufs-qcom.h
+++ b/drivers/scsi/ufs/ufs-qcom.h
@@ -239,10 +239,7 @@  int ufs_qcom_testbus_config(struct ufs_qcom_host *host);
 
 static inline bool ufs_qcom_cap_qunipro(struct ufs_qcom_host *host)
 {
-	if (host->caps & UFS_QCOM_CAP_QUNIPRO)
-		return true;
-	else
-		return false;
+	return host->caps & UFS_QCOM_CAP_QUNIPRO;
 }
 
 /* ufs-qcom-ice.c */
diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index 983fac14b7cd..c60519372b3b 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -939,10 +939,7 @@  static bool ufshcd_is_unipro_pa_params_tuning_req(struct ufs_hba *hba)
 	 * logic simple, we will only do manual tuning if local unipro version
 	 * doesn't support ver1.6 or later.
 	 */
-	if (ufshcd_get_local_unipro_ver(hba) < UFS_UNIPRO_VER_1_6)
-		return true;
-	else
-		return false;
+	return ufshcd_get_local_unipro_ver(hba) < UFS_UNIPRO_VER_1_6;
 }
 
 /**
@@ -2216,10 +2213,7 @@  static inline int ufshcd_hba_capabilities(struct ufs_hba *hba)
  */
 static inline bool ufshcd_ready_for_uic_cmd(struct ufs_hba *hba)
 {
-	if (ufshcd_readl(hba, REG_CONTROLLER_STATUS) & UIC_COMMAND_READY)
-		return true;
-	else
-		return false;
+	return ufshcd_readl(hba, REG_CONTROLLER_STATUS) & UIC_COMMAND_READY;
 }
 
 /**
@@ -5781,10 +5775,7 @@  static bool ufshcd_wb_presrv_usrspc_keep_vcc_on(struct ufs_hba *hba,
 		return false;
 	}
 	/* Let it continue to flush when available buffer exceeds threshold */
-	if (avail_buf < hba->vps->wb_flush_threshold)
-		return true;
-
-	return false;
+	return avail_buf < hba->vps->wb_flush_threshold;
 }
 
 static void ufshcd_wb_force_disable(struct ufs_hba *hba)
@@ -5863,11 +5854,8 @@  static bool ufshcd_wb_need_flush(struct ufs_hba *hba)
 		return false;
 	}
 
-	if (!hba->dev_info.b_presrv_uspc_en) {
-		if (avail_buf <= UFS_WB_BUF_REMAIN_PERCENT(10))
-			return true;
-		return false;
-	}
+	if (!hba->dev_info.b_presrv_uspc_en)
+		return avail_buf <= UFS_WB_BUF_REMAIN_PERCENT(10);
 
 	return ufshcd_wb_presrv_usrspc_keep_vcc_on(hba, avail_buf);
 }