diff mbox

[U-Boot] gpio: at91: add sanity check for the NULL pointer

Message ID 1399452645-26490-1-git-send-email-josh.wu@atmel.com
State Accepted, archived
Delegated to: Andreas Bießmann
Headers show

Commit Message

Josh Wu May 7, 2014, 8:50 a.m. UTC
We need check the NULL pointer as at91_pio_get_port() may return NULL.

Also print a error message when at91_pio_get_port() failed otherwise we
cannot notice the failure.

Signed-off-by: Josh Wu <josh.wu@atmel.com>
---
 drivers/gpio/at91_gpio.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Andreas Bießmann May 26, 2014, 10:12 p.m. UTC | #1
Dear Josh Wu,

Josh Wu <Josh.wu@atmel.com> writes:
>We need check the NULL pointer as at91_pio_get_port() may return NULL.
>
>Also print a error message when at91_pio_get_port() failed otherwise we
>cannot notice the failure.
>
>Signed-off-by: Josh Wu <josh.wu@atmel.com>
>
>---
>drivers/gpio/at91_gpio.c |    3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)

applied to u-boot-atmel/master, thanks!

Best regards,
Andreas Bießmann
diff mbox

Patch

diff --git a/drivers/gpio/at91_gpio.c b/drivers/gpio/at91_gpio.c
index 0b70071..6517af1 100644
--- a/drivers/gpio/at91_gpio.c
+++ b/drivers/gpio/at91_gpio.c
@@ -34,6 +34,7 @@  static struct at91_port *at91_pio_get_port(unsigned port)
 #endif
 #endif
 	default:
+		printf("Error: at91_gpio: Fail to get PIO base!\n");
 		return NULL;
 	}
 }
@@ -200,7 +201,7 @@  int at91_set_pio_output(unsigned port, u32 pin, int value)
 	struct at91_port *at91_port = at91_pio_get_port(port);
 	u32 mask;
 
-	if ((port < ATMEL_PIO_PORTS) && (pin < 32)) {
+	if (at91_port && (port < ATMEL_PIO_PORTS) && (pin < 32)) {
 		mask = 1 << pin;
 		writel(mask, &at91_port->idr);
 		writel(mask, &at91_port->pudr);