diff mbox series

[v2,1/3] pinctrl: intel: Replace ifdeffery by pm_sleep_ptr() macro

Message ID 20240906113710.467716-2-andriy.shevchenko@linux.intel.com
State New
Headers show
Series pinctrl: intel: Replace ifdeffery by pm_sleep_ptr() macro Andy Shevchenko | expand

Commit Message

Andy Shevchenko Sept. 6, 2024, 11:36 a.m. UTC
Explicit ifdeffery is ugly and theoretically might be not synchronised
with the rest of functions that are assigned via pm_sleep_ptr() macro.
Replace ifdeffery by pm_sleep_ptr() macro to improve this.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/pinctrl/intel/pinctrl-intel.c |  5 +----
 drivers/pinctrl/intel/pinctrl-intel.h | 14 ++++++++++++++
 2 files changed, 15 insertions(+), 4 deletions(-)

Comments

Mika Westerberg Sept. 6, 2024, 12:02 p.m. UTC | #1
On Fri, Sep 06, 2024 at 02:36:06PM +0300, Andy Shevchenko wrote:
> Explicit ifdeffery is ugly and theoretically might be not synchronised
> with the rest of functions that are assigned via pm_sleep_ptr() macro.
> Replace ifdeffery by pm_sleep_ptr() macro to improve this.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  drivers/pinctrl/intel/pinctrl-intel.c |  5 +----
>  drivers/pinctrl/intel/pinctrl-intel.h | 14 ++++++++++++++
>  2 files changed, 15 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/pinctrl/intel/pinctrl-intel.c b/drivers/pinctrl/intel/pinctrl-intel.c
> index f6f6d3970d5d..e3f9d4d9667c 100644
> --- a/drivers/pinctrl/intel/pinctrl-intel.c
> +++ b/drivers/pinctrl/intel/pinctrl-intel.c
> @@ -1482,7 +1482,6 @@ static int intel_pinctrl_add_padgroups_by_size(struct intel_pinctrl *pctrl,
>  
>  static int intel_pinctrl_pm_init(struct intel_pinctrl *pctrl)
>  {
> -#ifdef CONFIG_PM_SLEEP
>  	const struct intel_pinctrl_soc_data *soc = pctrl->soc;
>  	struct intel_community_context *communities;
>  	struct intel_pad_context *pads;
> @@ -1497,7 +1496,6 @@ static int intel_pinctrl_pm_init(struct intel_pinctrl *pctrl)
>  	if (!communities)
>  		return -ENOMEM;
>  
> -
>  	for (i = 0; i < pctrl->ncommunities; i++) {
>  		struct intel_community *community = &pctrl->communities[i];
>  		u32 *intmask, *hostown;
> @@ -1519,7 +1517,6 @@ static int intel_pinctrl_pm_init(struct intel_pinctrl *pctrl)
>  
>  	pctrl->context.pads = pads;
>  	pctrl->context.communities = communities;
> -#endif
>  
>  	return 0;
>  }
> @@ -1649,7 +1646,7 @@ int intel_pinctrl_probe(struct platform_device *pdev,
>  	if (irq < 0)
>  		return irq;
>  
> -	ret = intel_pinctrl_pm_init(pctrl);
> +	ret = intel_pinctrl_context_alloc(pctrl, intel_pinctrl_pm_init);
>  	if (ret)
>  		return ret;
>  
> diff --git a/drivers/pinctrl/intel/pinctrl-intel.h b/drivers/pinctrl/intel/pinctrl-intel.h
> index 4d4e1257afdf..7d8d1c5668d3 100644
> --- a/drivers/pinctrl/intel/pinctrl-intel.h
> +++ b/drivers/pinctrl/intel/pinctrl-intel.h
> @@ -256,6 +256,20 @@ struct intel_pinctrl {
>  	int irq;
>  };
>  
> +typedef int (*intel_pinctrl_context_alloc_fn)(struct intel_pinctrl *pctrl);
> +
> +static inline int intel_pinctrl_context_alloc(struct intel_pinctrl *pctrl,
> +					      intel_pinctrl_context_alloc_fn alloc_fn)
> +{
> +	intel_pinctrl_context_alloc_fn fn;
> +
> +	fn = pm_sleep_ptr(alloc_fn);
> +	if (fn)
> +		return fn(pctrl);
> +
> +	return 0;
> +}

No way, this looks even worse :(

Let's not do this change please.
diff mbox series

Patch

diff --git a/drivers/pinctrl/intel/pinctrl-intel.c b/drivers/pinctrl/intel/pinctrl-intel.c
index f6f6d3970d5d..e3f9d4d9667c 100644
--- a/drivers/pinctrl/intel/pinctrl-intel.c
+++ b/drivers/pinctrl/intel/pinctrl-intel.c
@@ -1482,7 +1482,6 @@  static int intel_pinctrl_add_padgroups_by_size(struct intel_pinctrl *pctrl,
 
 static int intel_pinctrl_pm_init(struct intel_pinctrl *pctrl)
 {
-#ifdef CONFIG_PM_SLEEP
 	const struct intel_pinctrl_soc_data *soc = pctrl->soc;
 	struct intel_community_context *communities;
 	struct intel_pad_context *pads;
@@ -1497,7 +1496,6 @@  static int intel_pinctrl_pm_init(struct intel_pinctrl *pctrl)
 	if (!communities)
 		return -ENOMEM;
 
-
 	for (i = 0; i < pctrl->ncommunities; i++) {
 		struct intel_community *community = &pctrl->communities[i];
 		u32 *intmask, *hostown;
@@ -1519,7 +1517,6 @@  static int intel_pinctrl_pm_init(struct intel_pinctrl *pctrl)
 
 	pctrl->context.pads = pads;
 	pctrl->context.communities = communities;
-#endif
 
 	return 0;
 }
@@ -1649,7 +1646,7 @@  int intel_pinctrl_probe(struct platform_device *pdev,
 	if (irq < 0)
 		return irq;
 
-	ret = intel_pinctrl_pm_init(pctrl);
+	ret = intel_pinctrl_context_alloc(pctrl, intel_pinctrl_pm_init);
 	if (ret)
 		return ret;
 
diff --git a/drivers/pinctrl/intel/pinctrl-intel.h b/drivers/pinctrl/intel/pinctrl-intel.h
index 4d4e1257afdf..7d8d1c5668d3 100644
--- a/drivers/pinctrl/intel/pinctrl-intel.h
+++ b/drivers/pinctrl/intel/pinctrl-intel.h
@@ -256,6 +256,20 @@  struct intel_pinctrl {
 	int irq;
 };
 
+typedef int (*intel_pinctrl_context_alloc_fn)(struct intel_pinctrl *pctrl);
+
+static inline int intel_pinctrl_context_alloc(struct intel_pinctrl *pctrl,
+					      intel_pinctrl_context_alloc_fn alloc_fn)
+{
+	intel_pinctrl_context_alloc_fn fn;
+
+	fn = pm_sleep_ptr(alloc_fn);
+	if (fn)
+		return fn(pctrl);
+
+	return 0;
+}
+
 int intel_pinctrl_probe(struct platform_device *pdev,
 			const struct intel_pinctrl_soc_data *soc_data);