diff mbox series

[v3,1/3] rtc: m41t80: probe: use IS_ENABLED for CONFIG_OF

Message ID 20230119213903.899756-2-dennis@sparkcharge.io
State New
Headers show
Series rtc: Set M41T82 & M41T83 xtal load capacitance from DT | expand

Commit Message

Dennis Lambe Jan. 19, 2023, 9:39 p.m. UTC
The style guide recommends IS_ENABLED rather than ifdef for wrapping
conditional code wherever possible.

Functions that are only called on DeviceTree platforms would otherwise
need to be cluttered up with __maybe_unused, which is especially
undesirable if there's nothing inherently DT-specific about those
functions.

Signed-off-by: Dennis Lambe Jr <dennis@sparkcharge.io>
---

Notes:
    v1 -> v2: spelling fix in changelog

 drivers/rtc/rtc-m41t80.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

Comments

Alexandre Belloni Jan. 19, 2023, 10:20 p.m. UTC | #1
On 19/01/2023 21:39:01+0000, Dennis Lambe Jr wrote:
> The style guide recommends IS_ENABLED rather than ifdef for wrapping
> conditional code wherever possible.
> 
> Functions that are only called on DeviceTree platforms would otherwise
> need to be cluttered up with __maybe_unused, which is especially
> undesirable if there's nothing inherently DT-specific about those
> functions.
> 
> Signed-off-by: Dennis Lambe Jr <dennis@sparkcharge.io>
> ---
> 
> Notes:
>     v1 -> v2: spelling fix in changelog
> 
>  drivers/rtc/rtc-m41t80.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/rtc/rtc-m41t80.c b/drivers/rtc/rtc-m41t80.c
> index 494052dbd39f..f963b76e5fc0 100644
> --- a/drivers/rtc/rtc-m41t80.c
> +++ b/drivers/rtc/rtc-m41t80.c
> @@ -909,10 +909,11 @@ static int m41t80_probe(struct i2c_client *client)
>  	if (IS_ERR(m41t80_data->rtc))
>  		return PTR_ERR(m41t80_data->rtc);
>  
> -#ifdef CONFIG_OF
> -	wakeup_source = of_property_read_bool(client->dev.of_node,
> -					      "wakeup-source");
> -#endif
> +	if (IS_ENABLED(CONFIG_OF)) {
> +		wakeup_source = of_property_read_bool(client->dev.of_node,
> +						      "wakeup-source");
> +	}
> +

A way better patch would switch to fwnode_property_read_bool

>  	if (client->irq > 0) {
>  		rc = devm_request_threaded_irq(&client->dev, client->irq,
>  					       NULL, m41t80_handle_irq,
> -- 
> 2.25.1
>
Dennis Lambe Jan. 19, 2023, 11:17 p.m. UTC | #2
On Thu, Jan 19, 2023 at 5:21 PM Alexandre Belloni
<alexandre.belloni@bootlin.com> wrote:

> > -#ifdef CONFIG_OF
> > -     wakeup_source = of_property_read_bool(client->dev.of_node,
> > -                                           "wakeup-source");
> > -#endif
> > +     if (IS_ENABLED(CONFIG_OF)) {
> > +             wakeup_source = of_property_read_bool(client->dev.of_node,
> > +                                                   "wakeup-source");
> > +     }
> > +
>
> A way better patch would switch to fwnode_property_read_bool

If you like that better, I'll make sure that's how I do it in future
revs of the patchset. I didn't know if it was appropriate since I
don't know if it would ever make sense to call acpi_dev_prop_get on
"wakeup-source" or "quartz-load-femtofarads", or if that kind of
consideration should even matter when choosing to use fwnode_* instead
of of_*.
diff mbox series

Patch

diff --git a/drivers/rtc/rtc-m41t80.c b/drivers/rtc/rtc-m41t80.c
index 494052dbd39f..f963b76e5fc0 100644
--- a/drivers/rtc/rtc-m41t80.c
+++ b/drivers/rtc/rtc-m41t80.c
@@ -909,10 +909,11 @@  static int m41t80_probe(struct i2c_client *client)
 	if (IS_ERR(m41t80_data->rtc))
 		return PTR_ERR(m41t80_data->rtc);
 
-#ifdef CONFIG_OF
-	wakeup_source = of_property_read_bool(client->dev.of_node,
-					      "wakeup-source");
-#endif
+	if (IS_ENABLED(CONFIG_OF)) {
+		wakeup_source = of_property_read_bool(client->dev.of_node,
+						      "wakeup-source");
+	}
+
 	if (client->irq > 0) {
 		rc = devm_request_threaded_irq(&client->dev, client->irq,
 					       NULL, m41t80_handle_irq,