diff mbox series

ufs: Use str_enable_disable-like helpers

Message ID 20250114200716.969457-1-krzysztof.kozlowski@linaro.org (mailing list archive)
State New
Headers show
Series ufs: Use str_enable_disable-like helpers | expand

Commit Message

Krzysztof Kozlowski Jan. 14, 2025, 8:07 p.m. UTC
Replace ternary (condition ? "enable" : "disable") syntax with helpers
from string_choices.h because:
1. Simple function call with one argument is easier to read.  Ternary
   operator has three arguments and with wrapping might lead to quite
   long code.
2. Is slightly shorter thus also easier to read.
3. It brings uniformity in the text - same string.
4. Allows deduping by the linker, which results in a smaller binary
   file.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
 drivers/ufs/core/ufshcd.c       | 11 ++++++-----
 drivers/ufs/host/ufs-mediatek.c |  7 +++----
 2 files changed, 9 insertions(+), 9 deletions(-)

Comments

Alim Akhtar Jan. 15, 2025, 4:02 a.m. UTC | #1
Hello Krzysztof,

> -----Original Message-----
> From: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> Sent: Wednesday, January 15, 2025 1:37 AM
> To: Alim Akhtar <alim.akhtar@samsung.com>; Avri Altman
> <avri.altman@wdc.com>; Bart Van Assche <bvanassche@acm.org>; James
> E.J. Bottomley <James.Bottomley@HansenPartnership.com>; Martin K.
> Petersen <martin.petersen@oracle.com>; Peter Wang
> <peter.wang@mediatek.com>; Stanley Jhu <chu.stanley@gmail.com>;
> Matthias Brugger <matthias.bgg@gmail.com>; AngeloGioacchino Del Regno
> <angelogioacchino.delregno@collabora.com>; linux-scsi@vger.kernel.org;
> linux-kernel@vger.kernel.org; linux-mediatek@lists.infradead.org; linux-
> arm-kernel@lists.infradead.org
> Cc: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> Subject: [PATCH] ufs: Use str_enable_disable-like helpers
> 
> Replace ternary (condition ? "enable" : "disable") syntax with helpers
from
> string_choices.h because:
> 1. Simple function call with one argument is easier to read.  Ternary
>    operator has three arguments and with wrapping might lead to quite
>    long code.
> 2. Is slightly shorter thus also easier to read.
> 3. It brings uniformity in the text - same string.
> 4. Allows deduping by the linker, which results in a smaller binary
>    file.
> 
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> ---
>  drivers/ufs/core/ufshcd.c       | 11 ++++++-----
>  drivers/ufs/host/ufs-mediatek.c |  7 +++----
>  2 files changed, 9 insertions(+), 9 deletions(-)
> 
Reviewed-by: Alim Akhtar <alim.akhtar@samsung.com>

On a side note, there are other host controller driver (e.g. exynos and
Qcomm) which also uses few conditional operators, But I didn't find a
matching helper in string_choices.h, so may be that can be taken separately
in future.


> diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index
> 27154a5dcb7b..5225d48a47f8 100644
> --- a/drivers/ufs/core/ufshcd.c
> +++ b/drivers/ufs/core/ufshcd.c
[Snip]
> --
> 2.43.0
Peter Wang (王信友) Jan. 15, 2025, 11:50 a.m. UTC | #2
On Tue, 2025-01-14 at 21:07 +0100, Krzysztof Kozlowski wrote:
> 
> External email : Please do not click links or open attachments until
> you have verified the sender or the content.
> 
> 
> Replace ternary (condition ? "enable" : "disable") syntax with
> helpers
> from string_choices.h because:
> 1. Simple function call with one argument is easier to read.  Ternary
>    operator has three arguments and with wrapping might lead to quite
>    long code.
> 2. Is slightly shorter thus also easier to read.
> 3. It brings uniformity in the text - same string.
> 4. Allows deduping by the linker, which results in a smaller binary
>    file.
> 
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> ---
>  drivers/ufs/core/ufshcd.c       | 11 ++++++-----
>  drivers/ufs/host/ufs-mediatek.c |  7 +++----
>  2 files changed, 9 insertions(+), 9 deletions(-)
> 

Reviewed-by: Peter Wang <peter.wang@mediatek.com>
diff mbox series

Patch

diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
index 27154a5dcb7b..5225d48a47f8 100644
--- a/drivers/ufs/core/ufshcd.c
+++ b/drivers/ufs/core/ufshcd.c
@@ -23,6 +23,7 @@ 
 #include <linux/pm_opp.h>
 #include <linux/regulator/consumer.h>
 #include <linux/sched/clock.h>
+#include <linux/string_choices.h>
 #include <linux/iopoll.h>
 #include <scsi/scsi_cmnd.h>
 #include <scsi/scsi_dbg.h>
@@ -1187,7 +1188,7 @@  static int ufshcd_scale_clks(struct ufs_hba *hba, unsigned long freq,
 
 out:
 	trace_ufshcd_profile_clk_scaling(dev_name(hba->dev),
-			(scale_up ? "up" : "down"),
+			str_up_down(scale_up),
 			ktime_to_us(ktime_sub(ktime_get(), start)), ret);
 	return ret;
 }
@@ -1549,7 +1550,7 @@  static int ufshcd_devfreq_target(struct device *dev,
 		hba->clk_scaling.target_freq = *freq;
 
 	trace_ufshcd_profile_clk_scaling(dev_name(hba->dev),
-		(scale_up ? "up" : "down"),
+		str_up_down(scale_up),
 		ktime_to_us(ktime_sub(ktime_get(), start)), ret);
 
 out:
@@ -6026,7 +6027,7 @@  int ufshcd_wb_toggle(struct ufs_hba *hba, bool enable)
 
 	hba->dev_info.wb_enabled = enable;
 	dev_dbg(hba->dev, "%s: Write Booster %s\n",
-			__func__, enable ? "enabled" : "disabled");
+			__func__, str_enabled_disabled(enable));
 
 	return ret;
 }
@@ -6044,7 +6045,7 @@  static void ufshcd_wb_toggle_buf_flush_during_h8(struct ufs_hba *hba,
 		return;
 	}
 	dev_dbg(hba->dev, "%s: WB-Buf Flush during H8 %s\n",
-			__func__, enable ? "enabled" : "disabled");
+			__func__, str_enabled_disabled(enable));
 }
 
 int ufshcd_wb_toggle_buf_flush(struct ufs_hba *hba, bool enable)
@@ -6064,7 +6065,7 @@  int ufshcd_wb_toggle_buf_flush(struct ufs_hba *hba, bool enable)
 
 	hba->dev_info.wb_buf_flush_enabled = enable;
 	dev_dbg(hba->dev, "%s: WB-Buf Flush %s\n",
-			__func__, enable ? "enabled" : "disabled");
+			__func__, str_enabled_disabled(enable));
 
 	return ret;
 }
diff --git a/drivers/ufs/host/ufs-mediatek.c b/drivers/ufs/host/ufs-mediatek.c
index 135cd78109e2..a7804fe387e9 100644
--- a/drivers/ufs/host/ufs-mediatek.c
+++ b/drivers/ufs/host/ufs-mediatek.c
@@ -19,6 +19,7 @@ 
 #include <linux/platform_device.h>
 #include <linux/regulator/consumer.h>
 #include <linux/reset.h>
+#include <linux/string_choices.h>
 
 #include <ufs/ufshcd.h>
 #include "ufshcd-pltfrm.h"
@@ -480,10 +481,8 @@  static int ufs_mtk_mphy_power_on(struct ufs_hba *hba, bool on)
 	}
 out:
 	if (ret) {
-		dev_info(hba->dev,
-			 "failed to %s va09: %d\n",
-			 on ? "enable" : "disable",
-			 ret);
+		dev_info(hba->dev, "failed to %s va09: %d\n",
+			 str_enable_disable(on), ret);
 	} else {
 		host->mphy_powered_on = on;
 	}