public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH] ufs: Use str_enable_disable-like helpers
@ 2025-01-14 20:07 ` Krzysztof Kozlowski
  2025-01-15  4:02   ` Alim Akhtar
                     ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Krzysztof Kozlowski @ 2025-01-14 20:07 UTC (permalink / raw)
  To: Alim Akhtar, Avri Altman, Bart Van Assche, James E.J. Bottomley,
	Martin K. Petersen, Peter Wang, Stanley Jhu, Matthias Brugger,
	AngeloGioacchino Del Regno, linux-scsi, linux-kernel,
	linux-mediatek, linux-arm-kernel
  Cc: Krzysztof Kozlowski

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(-)

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;
 	}
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* RE: [PATCH] ufs: Use str_enable_disable-like helpers
  2025-01-14 20:07 ` [PATCH] ufs: Use str_enable_disable-like helpers Krzysztof Kozlowski
@ 2025-01-15  4:02   ` Alim Akhtar
  2025-01-15 11:50   ` Peter Wang (王信友)
  2025-01-15 17:53   ` Bart Van Assche
  2 siblings, 0 replies; 5+ messages in thread
From: Alim Akhtar @ 2025-01-15  4:02 UTC (permalink / raw)
  To: 'Krzysztof Kozlowski', 'Avri Altman',
	'Bart Van Assche', 'James E.J. Bottomley',
	'Martin K. Petersen', 'Peter Wang',
	'Stanley	Jhu', 'Matthias Brugger',
	'AngeloGioacchino Del Regno', linux-scsi, linux-kernel,
	linux-mediatek, linux-arm-kernel
  Cc: cpgs

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





^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] ufs: Use str_enable_disable-like helpers
  2025-01-14 20:07 ` [PATCH] ufs: Use str_enable_disable-like helpers Krzysztof Kozlowski
  2025-01-15  4:02   ` Alim Akhtar
@ 2025-01-15 11:50   ` Peter Wang (王信友)
  2025-01-15 17:53   ` Bart Van Assche
  2 siblings, 0 replies; 5+ messages in thread
From: Peter Wang (王信友) @ 2025-01-15 11:50 UTC (permalink / raw)
  To: avri.altman@wdc.com, chu.stanley@gmail.com,
	krzysztof.kozlowski@linaro.org, AngeloGioacchino Del Regno,
	bvanassche@acm.org, linux-kernel@vger.kernel.org,
	alim.akhtar@samsung.com, linux-arm-kernel@lists.infradead.org,
	matthias.bgg@gmail.com, martin.petersen@oracle.com,
	James.Bottomley@HansenPartnership.com,
	linux-mediatek@lists.infradead.org, linux-scsi@vger.kernel.org

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>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] ufs: Use str_enable_disable-like helpers
  2025-01-14 20:07 ` [PATCH] ufs: Use str_enable_disable-like helpers Krzysztof Kozlowski
  2025-01-15  4:02   ` Alim Akhtar
  2025-01-15 11:50   ` Peter Wang (王信友)
@ 2025-01-15 17:53   ` Bart Van Assche
  2025-01-15 19:20     ` Krzysztof Kozlowski
  2 siblings, 1 reply; 5+ messages in thread
From: Bart Van Assche @ 2025-01-15 17:53 UTC (permalink / raw)
  To: Krzysztof Kozlowski, Alim Akhtar, Avri Altman,
	James E.J. Bottomley, Martin K. Petersen, Peter Wang, Stanley Jhu,
	Matthias Brugger, AngeloGioacchino Del Regno, linux-scsi,
	linux-kernel, linux-mediatek, linux-arm-kernel

On 1/14/25 12:07 PM, Krzysztof Kozlowski wrote:
> 2. Is slightly shorter thus also easier to read.

Does this change really make code easier to read? It forces readers
of the code to look up a function definition. Isn't there a general
preference in the Linux kernel to inline function definitions if the
function body is shorter than or close to the length of the function
name? I'm referring to functions like this one:

static inline const char *str_up_down(bool v)
{
	return v ? "up" : "down";
}

Bart.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] ufs: Use str_enable_disable-like helpers
  2025-01-15 17:53   ` Bart Van Assche
@ 2025-01-15 19:20     ` Krzysztof Kozlowski
  0 siblings, 0 replies; 5+ messages in thread
From: Krzysztof Kozlowski @ 2025-01-15 19:20 UTC (permalink / raw)
  To: Bart Van Assche, Alim Akhtar, Avri Altman, James E.J. Bottomley,
	Martin K. Petersen, Peter Wang, Stanley Jhu, Matthias Brugger,
	AngeloGioacchino Del Regno, linux-scsi, linux-kernel,
	linux-mediatek, linux-arm-kernel

On 15/01/2025 18:53, Bart Van Assche wrote:
> On 1/14/25 12:07 PM, Krzysztof Kozlowski wrote:
>> 2. Is slightly shorter thus also easier to read.
> 
> Does this change really make code easier to read? It forces readers
> of the code to look up a function definition. Isn't there a general

There is no general preference, up to you.

> preference in the Linux kernel to inline function definitions if the
> function body is shorter than or close to the length of the function
> name? I'm referring to functions like this one:
> 
> static inline const char *str_up_down(bool v)
> {
> 	return v ? "up" : "down";
> }
> 
> Bart.


It's subjective - in some places ternary is really complicating, from my
other patch:

	data & XCSI_DLXINFR_SOTERR ? "true" : "false",
	video->hq_mode ? "on" : "off", video->jpeg_hq_quality);

note that's ternary is split here:

	dstat & BT848_DSTATUS_HLOC
	? "yes" : "no");

I understand if you don't find the code here better.

Best regards,
Krzysztof


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-01-15 19:22 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <CGME20250114200726epcas5p4dc896686dd6cdcc449344dbef87af21d@epcas5p4.samsung.com>
2025-01-14 20:07 ` [PATCH] ufs: Use str_enable_disable-like helpers Krzysztof Kozlowski
2025-01-15  4:02   ` Alim Akhtar
2025-01-15 11:50   ` Peter Wang (王信友)
2025-01-15 17:53   ` Bart Van Assche
2025-01-15 19:20     ` Krzysztof Kozlowski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox