[v1,4/4] pinctrl: intel: simplify exit path of gpio_request_enable hook

Message ID 20230608070017.28072-5-raag.jadav@intel.com
State New
Headers
Series Minor optimizations for Intel pinctrl |

Commit Message

Raag Jadav June 8, 2023, 7 a.m. UTC
  Simplify exit path of ->gpio_request_enable() hook
and save a few bytes.

add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-36 (-36)
Function                                     old     new   delta
intel_gpio_request_enable                    186     150     -36
Total: Before=10431, After=10395, chg -0.35%

Signed-off-by: Raag Jadav <raag.jadav@intel.com>
---
 drivers/pinctrl/intel/pinctrl-intel.c | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)
  

Comments

Mika Westerberg June 8, 2023, 8:10 a.m. UTC | #1
On Thu, Jun 08, 2023 at 12:30:17PM +0530, Raag Jadav wrote:
> Simplify exit path of ->gpio_request_enable() hook
> and save a few bytes.
> 
> add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-36 (-36)
> Function                                     old     new   delta
> intel_gpio_request_enable                    186     150     -36
> Total: Before=10431, After=10395, chg -0.35%
> 
> Signed-off-by: Raag Jadav <raag.jadav@intel.com>
> ---
>  drivers/pinctrl/intel/pinctrl-intel.c | 23 ++++++++++++-----------
>  1 file changed, 12 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/pinctrl/intel/pinctrl-intel.c b/drivers/pinctrl/intel/pinctrl-intel.c
> index 1b5745202058..947797d87c93 100644
> --- a/drivers/pinctrl/intel/pinctrl-intel.c
> +++ b/drivers/pinctrl/intel/pinctrl-intel.c
> @@ -489,20 +489,22 @@ static int intel_gpio_request_enable(struct pinctrl_dev *pctldev,
>  	struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
>  	void __iomem *padcfg0;
>  	unsigned long flags;
> +	int ret;
>  
>  	padcfg0 = intel_get_padcfg(pctrl, pin, PADCFG0);
>  
> +	/* For positive cases */
> +	ret = 0;

You can set it

	int ret = 0;

and drop the useless comment.

> +
>  	raw_spin_lock_irqsave(&pctrl->lock, flags);
>  
>  	if (!intel_pad_owned_by_host(pctrl, pin)) {
> -		raw_spin_unlock_irqrestore(&pctrl->lock, flags);
> -		return -EBUSY;
> +		ret = -EBUSY;
> +		goto out_unlock;
>  	}
>  
> -	if (!intel_pad_is_unlocked(pctrl, pin)) {
> -		raw_spin_unlock_irqrestore(&pctrl->lock, flags);
> -		return 0;
> -	}
> +	if (!intel_pad_is_unlocked(pctrl, pin))
> +		goto out_unlock;
>  
>  	/*
>  	 * If pin is already configured in GPIO mode, we assume that
> @@ -510,16 +512,15 @@ static int intel_gpio_request_enable(struct pinctrl_dev *pctldev,
>  	 * potential glitches on the pin. Otherwise, for the pin in
>  	 * alternative mode, consumer has to supply respective flags.
>  	 */
> -	if (intel_gpio_get_gpio_mode(padcfg0) == PADCFG0_PMODE_GPIO) {
> -		raw_spin_unlock_irqrestore(&pctrl->lock, flags);
> -		return 0;
> -	}
> +	if (intel_gpio_get_gpio_mode(padcfg0) == PADCFG0_PMODE_GPIO)
> +		goto out_unlock;
>  
>  	intel_gpio_set_gpio_mode(padcfg0);
>  
> +out_unlock:
>  	raw_spin_unlock_irqrestore(&pctrl->lock, flags);
>  
> -	return 0;
> +	return ret;
>  }
>  
>  static int intel_gpio_set_direction(struct pinctrl_dev *pctldev,
> -- 
> 2.17.1
  

Patch

diff --git a/drivers/pinctrl/intel/pinctrl-intel.c b/drivers/pinctrl/intel/pinctrl-intel.c
index 1b5745202058..947797d87c93 100644
--- a/drivers/pinctrl/intel/pinctrl-intel.c
+++ b/drivers/pinctrl/intel/pinctrl-intel.c
@@ -489,20 +489,22 @@  static int intel_gpio_request_enable(struct pinctrl_dev *pctldev,
 	struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
 	void __iomem *padcfg0;
 	unsigned long flags;
+	int ret;
 
 	padcfg0 = intel_get_padcfg(pctrl, pin, PADCFG0);
 
+	/* For positive cases */
+	ret = 0;
+
 	raw_spin_lock_irqsave(&pctrl->lock, flags);
 
 	if (!intel_pad_owned_by_host(pctrl, pin)) {
-		raw_spin_unlock_irqrestore(&pctrl->lock, flags);
-		return -EBUSY;
+		ret = -EBUSY;
+		goto out_unlock;
 	}
 
-	if (!intel_pad_is_unlocked(pctrl, pin)) {
-		raw_spin_unlock_irqrestore(&pctrl->lock, flags);
-		return 0;
-	}
+	if (!intel_pad_is_unlocked(pctrl, pin))
+		goto out_unlock;
 
 	/*
 	 * If pin is already configured in GPIO mode, we assume that
@@ -510,16 +512,15 @@  static int intel_gpio_request_enable(struct pinctrl_dev *pctldev,
 	 * potential glitches on the pin. Otherwise, for the pin in
 	 * alternative mode, consumer has to supply respective flags.
 	 */
-	if (intel_gpio_get_gpio_mode(padcfg0) == PADCFG0_PMODE_GPIO) {
-		raw_spin_unlock_irqrestore(&pctrl->lock, flags);
-		return 0;
-	}
+	if (intel_gpio_get_gpio_mode(padcfg0) == PADCFG0_PMODE_GPIO)
+		goto out_unlock;
 
 	intel_gpio_set_gpio_mode(padcfg0);
 
+out_unlock:
 	raw_spin_unlock_irqrestore(&pctrl->lock, flags);
 
-	return 0;
+	return ret;
 }
 
 static int intel_gpio_set_direction(struct pinctrl_dev *pctldev,