* [PATCH] iio: Use str_enable_disable-like helpers
@ 2025-01-14 19:27 Krzysztof Kozlowski
2025-01-18 15:56 ` Jonathan Cameron
0 siblings, 1 reply; 2+ messages in thread
From: Krzysztof Kozlowski @ 2025-01-14 19:27 UTC (permalink / raw)
To: Jonathan Cameron, Lars-Peter Clausen, linux-iio, linux-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/iio/humidity/dht11.c | 3 ++-
drivers/iio/proximity/irsd200.c | 3 ++-
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/iio/humidity/dht11.c b/drivers/iio/humidity/dht11.c
index c97e25448772..48c59d09eea7 100644
--- a/drivers/iio/humidity/dht11.c
+++ b/drivers/iio/humidity/dht11.c
@@ -11,6 +11,7 @@
#include <linux/kernel.h>
#include <linux/printk.h>
#include <linux/slab.h>
+#include <linux/string_choices.h>
#include <linux/sysfs.h>
#include <linux/io.h>
#include <linux/mod_devicetable.h>
@@ -99,7 +100,7 @@ static void dht11_edges_print(struct dht11 *dht11)
for (i = 1; i < dht11->num_edges; ++i) {
dev_dbg(dht11->dev, "%d: %lld ns %s\n", i,
dht11->edges[i].ts - dht11->edges[i - 1].ts,
- dht11->edges[i - 1].value ? "high" : "low");
+ str_high_low(dht11->edges[i - 1].value));
}
}
#endif /* CONFIG_DYNAMIC_DEBUG */
diff --git a/drivers/iio/proximity/irsd200.c b/drivers/iio/proximity/irsd200.c
index b09d15230111..b0ffd3574013 100644
--- a/drivers/iio/proximity/irsd200.c
+++ b/drivers/iio/proximity/irsd200.c
@@ -10,6 +10,7 @@
#include <linux/i2c.h>
#include <linux/module.h>
#include <linux/regmap.h>
+#include <linux/string_choices.h>
#include <linux/iio/buffer.h>
#include <linux/iio/events.h>
@@ -783,7 +784,7 @@ static int irsd200_set_trigger_state(struct iio_trigger *trig, bool state)
ret = regmap_field_write(data->regfields[IRS_REGF_INTR_DATA], state);
if (ret) {
dev_err(data->dev, "Could not %s data interrupt source (%d)\n",
- state ? "enable" : "disable", ret);
+ str_enable_disable(state), ret);
}
return ret;
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] iio: Use str_enable_disable-like helpers
2025-01-14 19:27 [PATCH] iio: Use str_enable_disable-like helpers Krzysztof Kozlowski
@ 2025-01-18 15:56 ` Jonathan Cameron
0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Cameron @ 2025-01-18 15:56 UTC (permalink / raw)
To: Krzysztof Kozlowski; +Cc: Lars-Peter Clausen, linux-iio, linux-kernel
On Tue, 14 Jan 2025 20:27:16 +0100
Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org> wrote:
> 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>
I can't claim to get excited about this, but I don't mind using
these functions. So applied to the testing branch of iio.git.
I'll be rebasing on rc1 once available.
Thanks,
Jonathan
> ---
> drivers/iio/humidity/dht11.c | 3 ++-
> drivers/iio/proximity/irsd200.c | 3 ++-
> 2 files changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/iio/humidity/dht11.c b/drivers/iio/humidity/dht11.c
> index c97e25448772..48c59d09eea7 100644
> --- a/drivers/iio/humidity/dht11.c
> +++ b/drivers/iio/humidity/dht11.c
> @@ -11,6 +11,7 @@
> #include <linux/kernel.h>
> #include <linux/printk.h>
> #include <linux/slab.h>
> +#include <linux/string_choices.h>
> #include <linux/sysfs.h>
> #include <linux/io.h>
> #include <linux/mod_devicetable.h>
> @@ -99,7 +100,7 @@ static void dht11_edges_print(struct dht11 *dht11)
> for (i = 1; i < dht11->num_edges; ++i) {
> dev_dbg(dht11->dev, "%d: %lld ns %s\n", i,
> dht11->edges[i].ts - dht11->edges[i - 1].ts,
> - dht11->edges[i - 1].value ? "high" : "low");
> + str_high_low(dht11->edges[i - 1].value));
> }
> }
> #endif /* CONFIG_DYNAMIC_DEBUG */
> diff --git a/drivers/iio/proximity/irsd200.c b/drivers/iio/proximity/irsd200.c
> index b09d15230111..b0ffd3574013 100644
> --- a/drivers/iio/proximity/irsd200.c
> +++ b/drivers/iio/proximity/irsd200.c
> @@ -10,6 +10,7 @@
> #include <linux/i2c.h>
> #include <linux/module.h>
> #include <linux/regmap.h>
> +#include <linux/string_choices.h>
>
> #include <linux/iio/buffer.h>
> #include <linux/iio/events.h>
> @@ -783,7 +784,7 @@ static int irsd200_set_trigger_state(struct iio_trigger *trig, bool state)
> ret = regmap_field_write(data->regfields[IRS_REGF_INTR_DATA], state);
> if (ret) {
> dev_err(data->dev, "Could not %s data interrupt source (%d)\n",
> - state ? "enable" : "disable", ret);
> + str_enable_disable(state), ret);
> }
>
> return ret;
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-01-18 15:57 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-14 19:27 [PATCH] iio: Use str_enable_disable-like helpers Krzysztof Kozlowski
2025-01-18 15:56 ` Jonathan Cameron
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox