mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] driver: workaroud resource request that conflicts with errno PTR
@ 2015-01-08  7:09 Sascha Hauer
  2015-01-08 13:00 ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 1 reply; 2+ messages in thread
From: Sascha Hauer @ 2015-01-08  7:09 UTC (permalink / raw)
  To: Barebox List

From: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

broken since

commit ed6e965824303255cacc1c1a195d3684caa26bce
Author:     Sascha Hauer <s.hauer@pengutronix.de>
resource: Let dev_request_mem_region return an error pointer

Introduce dev_request_mem_region_err_null

only used on platform like at91 where the resource address conflicts
with errno PTR.

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/mach-at91/at91sam926x_time.c |  6 +++---
 drivers/base/driver.c                 | 16 ++++++++++++++++
 drivers/pinctrl/pinctrl-at91.c        |  6 +++---
 drivers/serial/atmel.c                |  6 +++---
 include/driver.h                      |  8 ++++++++
 5 files changed, 33 insertions(+), 9 deletions(-)

diff --git a/arch/arm/mach-at91/at91sam926x_time.c b/arch/arm/mach-at91/at91sam926x_time.c
index 789e1ec..cc7ad2f 100644
--- a/arch/arm/mach-at91/at91sam926x_time.c
+++ b/arch/arm/mach-at91/at91sam926x_time.c
@@ -89,9 +89,9 @@ static int at91_pit_probe(struct device_d *dev)
 		return ret;
 	}
 
-	pit_base = dev_request_mem_region(dev, 0);
-	if (IS_ERR(pit_base))
-		return PTR_ERR(pit_base);
+	pit_base = dev_request_mem_region_err_null(dev, 0);
+	if (!pit_base)
+		return -ENOENT;
 
 	pit_rate = clk_get_rate(clk) / 16;
 
diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index e0125a1..fd9c4d9 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -318,6 +318,22 @@ void __iomem *dev_request_mem_region_by_name(struct device_d *dev, const char *n
 }
 EXPORT_SYMBOL(dev_request_mem_region_by_name);
 
+void __iomem *dev_request_mem_region_err_null(struct device_d *dev, int num)
+{
+	struct resource *res;
+
+	res = dev_get_resource(dev, IORESOURCE_MEM, num);
+	if (IS_ERR(res))
+		return NULL;
+
+	res = request_iomem_region(dev_name(dev), res->start, res->end);
+	if (IS_ERR(res))
+		return NULL;
+
+	return (void __force __iomem *)res->start;
+}
+EXPORT_SYMBOL(dev_request_mem_region_err_null);
+
 void __iomem *dev_request_mem_region(struct device_d *dev, int num)
 {
 	struct resource *res;
diff --git a/drivers/pinctrl/pinctrl-at91.c b/drivers/pinctrl/pinctrl-at91.c
index 0d6d2e7..b803f89 100644
--- a/drivers/pinctrl/pinctrl-at91.c
+++ b/drivers/pinctrl/pinctrl-at91.c
@@ -652,9 +652,9 @@ static int at91_gpio_probe(struct device_d *dev)
 	}
 
 	gpio_banks = max(gpio_banks, alias_idx + 1);
-	at91_gpio->regbase = dev_request_mem_region(dev, 0);
-	if (IS_ERR(at91_gpio->regbase))
-		return PTR_ERR(at91_gpio->regbase);
+	at91_gpio->regbase = dev_request_mem_region_err_null(dev, 0);
+	if (!at91_gpio->regbase)
+		return -ENOENT;
 
 	at91_gpio->chip.ops = &at91_gpio_ops;
 	at91_gpio->chip.ngpio = MAX_NB_GPIO_PER_BANK;
diff --git a/drivers/serial/atmel.c b/drivers/serial/atmel.c
index 1f40692..4e4624e 100644
--- a/drivers/serial/atmel.c
+++ b/drivers/serial/atmel.c
@@ -398,9 +398,9 @@ static int atmel_serial_init_port(struct console_device *cdev)
 	struct device_d *dev = cdev->dev;
 	struct atmel_uart_port *uart = to_atmel_uart_port(cdev);
 
-	uart->base = dev_request_mem_region(dev, 0);
-	if (IS_ERR(uart->base))
-		return PTR_ERR(uart->base);
+	uart->base = dev_request_mem_region_err_null(dev, 0);
+	if (!uart->base)
+		return -ENOENT;
 
 	uart->clk = clk_get(dev, "usart");
 	clk_enable(uart->clk);
diff --git a/include/driver.h b/include/driver.h
index 53e1000..46aae4f 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -206,6 +206,14 @@ void *dev_get_mem_region(struct device_d *dev, int num);
  */
 void __iomem *dev_request_mem_region(struct device_d *dev, int num);
 
+/*
+ * exlusively request register base 'num' for a device
+ * will return NULL on error
+ * only used on platform like at91 where the Ressource address collision with
+ * PTR errno
+ */
+void __iomem *dev_request_mem_region_err_null(struct device_d *dev, int num);
+
 struct device_d *device_alloc(const char *devname, int id);
 
 int device_add_resources(struct device_d *dev, const struct resource *res, int num);
-- 
2.1.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-01-08 13:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-08  7:09 [PATCH] driver: workaroud resource request that conflicts with errno PTR Sascha Hauer
2015-01-08 13:00 ` Jean-Christophe PLAGNIOL-VILLARD

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox