[RFT,1/2] gpio: bcm-kona: Return error if requesting an already taken gpio
diff mbox

Message ID 1428629325.5384.1.camel@phoenix
State New
Headers show

Commit Message

Axel Lin April 10, 2015, 1:28 a.m. UTC
If a gpio is already taken, .gpio_request should return error.

Signed-off-by: Axel Lin <axel.lin@ingics.com>
---
 drivers/gpio/gpio-bcm-kona.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

Comments

Ray Jui April 10, 2015, 4:05 p.m. UTC | #1
Hi Axel,

On 4/9/2015 6:28 PM, Axel Lin wrote:
> If a gpio is already taken, .gpio_request should return error.

Isn't the protection logic already there at the higher layer in gpiolib?

Ray

> 
> Signed-off-by: Axel Lin <axel.lin@ingics.com>
> ---
>  drivers/gpio/gpio-bcm-kona.c | 12 +++++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpio/gpio-bcm-kona.c b/drivers/gpio/gpio-bcm-kona.c
> index b164ce8..632352d 100644
> --- a/drivers/gpio/gpio-bcm-kona.c
> +++ b/drivers/gpio/gpio-bcm-kona.c
> @@ -106,7 +106,7 @@ static void bcm_kona_gpio_lock_gpio(struct bcm_kona_gpio *kona_gpio,
>  	spin_unlock_irqrestore(&kona_gpio->lock, flags);
>  }
>  
> -static void bcm_kona_gpio_unlock_gpio(struct bcm_kona_gpio *kona_gpio,
> +static int bcm_kona_gpio_unlock_gpio(struct bcm_kona_gpio *kona_gpio,
>  					unsigned gpio)
>  {
>  	u32 val;
> @@ -116,10 +116,17 @@ static void bcm_kona_gpio_unlock_gpio(struct bcm_kona_gpio *kona_gpio,
>  	spin_lock_irqsave(&kona_gpio->lock, flags);
>  
>  	val = readl(kona_gpio->reg_base + GPIO_PWD_STATUS(bank_id));
> +	if (!(val & BIT(gpio))) {
> +		spin_unlock_irqrestore(&kona_gpio->lock, flags);
> +		return -EBUSY;
> +	}
> +
>  	val &= ~BIT(gpio);
>  	bcm_kona_gpio_write_lock_regs(kona_gpio->reg_base, bank_id, val);
>  
>  	spin_unlock_irqrestore(&kona_gpio->lock, flags);
> +
> +	return 0;
>  }
>  
>  static void bcm_kona_gpio_set(struct gpio_chip *chip, unsigned gpio, int value)
> @@ -185,8 +192,7 @@ static int bcm_kona_gpio_request(struct gpio_chip *chip, unsigned gpio)
>  {
>  	struct bcm_kona_gpio *kona_gpio = to_kona_gpio(chip);
>  
> -	bcm_kona_gpio_unlock_gpio(kona_gpio, gpio);
> -	return 0;
> +	return bcm_kona_gpio_unlock_gpio(kona_gpio, gpio);
>  }
>  
>  static void bcm_kona_gpio_free(struct gpio_chip *chip, unsigned gpio)
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Axel Lin April 10, 2015, 11:01 p.m. UTC | #2
2015-04-11 0:05 GMT+08:00 Ray Jui <rjui@broadcom.com>:
> Hi Axel,
>
> On 4/9/2015 6:28 PM, Axel Lin wrote:
>> If a gpio is already taken, .gpio_request should return error.
>
> Isn't the protection logic already there at the higher layer in gpiolib?

OK, you are right.
Thanks for the review.
Axel
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch
diff mbox

diff --git a/drivers/gpio/gpio-bcm-kona.c b/drivers/gpio/gpio-bcm-kona.c
index b164ce8..632352d 100644
--- a/drivers/gpio/gpio-bcm-kona.c
+++ b/drivers/gpio/gpio-bcm-kona.c
@@ -106,7 +106,7 @@  static void bcm_kona_gpio_lock_gpio(struct bcm_kona_gpio *kona_gpio,
 	spin_unlock_irqrestore(&kona_gpio->lock, flags);
 }
 
-static void bcm_kona_gpio_unlock_gpio(struct bcm_kona_gpio *kona_gpio,
+static int bcm_kona_gpio_unlock_gpio(struct bcm_kona_gpio *kona_gpio,
 					unsigned gpio)
 {
 	u32 val;
@@ -116,10 +116,17 @@  static void bcm_kona_gpio_unlock_gpio(struct bcm_kona_gpio *kona_gpio,
 	spin_lock_irqsave(&kona_gpio->lock, flags);
 
 	val = readl(kona_gpio->reg_base + GPIO_PWD_STATUS(bank_id));
+	if (!(val & BIT(gpio))) {
+		spin_unlock_irqrestore(&kona_gpio->lock, flags);
+		return -EBUSY;
+	}
+
 	val &= ~BIT(gpio);
 	bcm_kona_gpio_write_lock_regs(kona_gpio->reg_base, bank_id, val);
 
 	spin_unlock_irqrestore(&kona_gpio->lock, flags);
+
+	return 0;
 }
 
 static void bcm_kona_gpio_set(struct gpio_chip *chip, unsigned gpio, int value)
@@ -185,8 +192,7 @@  static int bcm_kona_gpio_request(struct gpio_chip *chip, unsigned gpio)
 {
 	struct bcm_kona_gpio *kona_gpio = to_kona_gpio(chip);
 
-	bcm_kona_gpio_unlock_gpio(kona_gpio, gpio);
-	return 0;
+	return bcm_kona_gpio_unlock_gpio(kona_gpio, gpio);
 }
 
 static void bcm_kona_gpio_free(struct gpio_chip *chip, unsigned gpio)