linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mpc52xx/serial: fix error paths in probe function
@ 2008-11-27 15:33 Wolfram Sang
  2008-11-27 16:40 ` Jon Smirl
  2008-12-19 15:32 ` [PATCH V2] " Wolfram Sang
  0 siblings, 2 replies; 4+ messages in thread
From: Wolfram Sang @ 2008-11-27 15:33 UTC (permalink / raw)
  To: grant.likely; +Cc: linuxppc-dev

- error cases for mapbase and irq were unbundled
- mapped irq now gets disposed on error
- errors return ENODEV instead of EINVAL as they are not dependant on
  arguments

Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
---
 drivers/serial/mpc52xx_uart.c |   27 +++++++++++++++++----------
 1 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/drivers/serial/mpc52xx_uart.c b/drivers/serial/mpc52xx_uart.c
index 3234100..93e8893 100644
--- a/drivers/serial/mpc52xx_uart.c
+++ b/drivers/serial/mpc52xx_uart.c
@@ -1113,14 +1113,14 @@ mpc52xx_uart_of_probe(struct of_device *op, const struct of_device_id *match)
 		if (mpc52xx_uart_nodes[idx] == op->node)
 			break;
 	if (idx >= MPC52xx_PSC_MAXNUM)
-		return -EINVAL;
+		return -ENODEV;
 	pr_debug("Found %s assigned to ttyPSC%x\n",
 		 mpc52xx_uart_nodes[idx]->full_name, idx);
 
 	uartclk = psc_ops->getuartclk(op->node);
 	if (uartclk == 0) {
 		dev_dbg(&op->dev, "Could not find uart clock frequency!\n");
-		return -EINVAL;
+		return -ENODEV;
 	}
 
 	/* Init the port structure */
@@ -1142,22 +1142,29 @@ mpc52xx_uart_of_probe(struct of_device *op, const struct of_device_id *match)
 		return ret;
 
 	port->mapbase = res.start;
+	if (!port->mapbase) {
+		dev_err(&op->dev, "Could not allocate resources for PSC\n");
+		return -ENODEV;
+	}
+
 	port->irq = irq_of_parse_and_map(op->node, 0);
+	if (port->irq == NO_IRQ) {
+		dev_err(&op->dev, "Could not get irq\n");
+		return -ENODEV;
+	}
 
 	dev_dbg(&op->dev, "mpc52xx-psc uart at %p, irq=%x, freq=%i\n",
 		(void *)port->mapbase, port->irq, port->uartclk);
 
-	if ((port->irq == NO_IRQ) || !port->mapbase) {
-		printk(KERN_ERR "Could not allocate resources for PSC\n");
-		return -EINVAL;
-	}
-
 	/* Add the port to the uart sub-system */
 	ret = uart_add_one_port(&mpc52xx_uart_driver, port);
-	if (!ret)
-		dev_set_drvdata(&op->dev, (void *)port);
+	if (ret) {
+		irq_dispose_mapping(port->irq);
+		return -ENODEV;
+	}
 
-	return ret;
+	dev_set_drvdata(&op->dev, (void *)port);
+	return 0;
 }
 
 static int
-- 
1.5.6.5

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

* Re: [PATCH] mpc52xx/serial: fix error paths in probe function
  2008-11-27 15:33 [PATCH] mpc52xx/serial: fix error paths in probe function Wolfram Sang
@ 2008-11-27 16:40 ` Jon Smirl
  2008-11-27 20:30   ` Wolfram Sang
  2008-12-19 15:32 ` [PATCH V2] " Wolfram Sang
  1 sibling, 1 reply; 4+ messages in thread
From: Jon Smirl @ 2008-11-27 16:40 UTC (permalink / raw)
  To: Wolfram Sang; +Cc: linuxppc-dev

On Thu, Nov 27, 2008 at 10:33 AM, Wolfram Sang <w.sang@pengutronix.de> wrote:
> - error cases for mapbase and irq were unbundled
> - mapped irq now gets disposed on error
> - errors return ENODEV instead of EINVAL as they are not dependant on
>  arguments
>
> Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
> ---
>  drivers/serial/mpc52xx_uart.c |   27 +++++++++++++++++----------
>  1 files changed, 17 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/serial/mpc52xx_uart.c b/drivers/serial/mpc52xx_uart.c
> index 3234100..93e8893 100644
> --- a/drivers/serial/mpc52xx_uart.c
> +++ b/drivers/serial/mpc52xx_uart.c
> @@ -1113,14 +1113,14 @@ mpc52xx_uart_of_probe(struct of_device *op, const struct of_device_id *match)
>                if (mpc52xx_uart_nodes[idx] == op->node)
>                        break;
>        if (idx >= MPC52xx_PSC_MAXNUM)
> -               return -EINVAL;
> +               return -ENODEV;
>        pr_debug("Found %s assigned to ttyPSC%x\n",
>                 mpc52xx_uart_nodes[idx]->full_name, idx);
>
>        uartclk = psc_ops->getuartclk(op->node);
>        if (uartclk == 0) {
>                dev_dbg(&op->dev, "Could not find uart clock frequency!\n");
> -               return -EINVAL;
> +               return -ENODEV;
>        }
>
>        /* Init the port structure */
> @@ -1142,22 +1142,29 @@ mpc52xx_uart_of_probe(struct of_device *op, const struct of_device_id *match)
>                return ret;
>
>        port->mapbase = res.start;
> +       if (!port->mapbase) {
> +               dev_err(&op->dev, "Could not allocate resources for PSC\n");
> +               return -ENODEV;
> +       }
> +
>        port->irq = irq_of_parse_and_map(op->node, 0);
> +       if (port->irq == NO_IRQ) {
> +               dev_err(&op->dev, "Could not get irq\n");
> +               return -ENODEV;
> +       }

Doesn't NO_IRQ imply polling, not an error?

>
>        dev_dbg(&op->dev, "mpc52xx-psc uart at %p, irq=%x, freq=%i\n",
>                (void *)port->mapbase, port->irq, port->uartclk);
>
> -       if ((port->irq == NO_IRQ) || !port->mapbase) {
> -               printk(KERN_ERR "Could not allocate resources for PSC\n");
> -               return -EINVAL;
> -       }
> -
>        /* Add the port to the uart sub-system */
>        ret = uart_add_one_port(&mpc52xx_uart_driver, port);
> -       if (!ret)
> -               dev_set_drvdata(&op->dev, (void *)port);
> +       if (ret) {
> +               irq_dispose_mapping(port->irq);
> +               return -ENODEV;
> +       }
>
> -       return ret;
> +       dev_set_drvdata(&op->dev, (void *)port);
> +       return 0;
>  }
>
>  static int
> --
> 1.5.6.5
>
> _______________________________________________
> Linuxppc-dev mailing list
> Linuxppc-dev@ozlabs.org
> https://ozlabs.org/mailman/listinfo/linuxppc-dev
>



-- 
Jon Smirl
jonsmirl@gmail.com

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

* Re: [PATCH] mpc52xx/serial: fix error paths in probe function
  2008-11-27 16:40 ` Jon Smirl
@ 2008-11-27 20:30   ` Wolfram Sang
  0 siblings, 0 replies; 4+ messages in thread
From: Wolfram Sang @ 2008-11-27 20:30 UTC (permalink / raw)
  To: Jon Smirl; +Cc: linuxppc-dev

[-- Attachment #1: Type: text/plain, Size: 974 bytes --]


On Thu, Nov 27, 2008 at 11:40:55AM -0500, Jon Smirl wrote:

> > +       if (port->irq == NO_IRQ) {
> > +               dev_err(&op->dev, "Could not get irq\n");
> > +               return -ENODEV;
> > +       }
> 
> Doesn't NO_IRQ imply polling, not an error?

See below, I just copied the original behaviour. Having another look at
mpc52xx_uart_setup, I don't see any polling option there, so I think it
is correct to do this.

> 
> >
> >        dev_dbg(&op->dev, "mpc52xx-psc uart at %p, irq=%x, freq=%i\n",
> >                (void *)port->mapbase, port->irq, port->uartclk);
> >
> > -       if ((port->irq == NO_IRQ) || !port->mapbase) {
> > -               printk(KERN_ERR "Could not allocate resources for PSC\n");
> > -               return -EINVAL;
> > -       }

(Originaly dropout for NO_IRQ)

Regards,

   Wolfram

-- 
  Dipl.-Ing. Wolfram Sang | http://www.pengutronix.de
 Pengutronix - Linux Solutions for Science and Industry

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 197 bytes --]

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

* [PATCH V2] mpc52xx/serial: fix error paths in probe function
  2008-11-27 15:33 [PATCH] mpc52xx/serial: fix error paths in probe function Wolfram Sang
  2008-11-27 16:40 ` Jon Smirl
@ 2008-12-19 15:32 ` Wolfram Sang
  1 sibling, 0 replies; 4+ messages in thread
From: Wolfram Sang @ 2008-12-19 15:32 UTC (permalink / raw)
  To: grant.likely; +Cc: linuxppc-dev

- error cases for mapbase and irq were unbundled
- mapped irq now gets disposed on error

Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
---

Tested with 2.6.28-rc9 on a phyCORE-MPC5200B-IO.

Changes since V1:

after following a discussion on LKML, it seems better to:

- use -EINVAL again instead of -ENODEV
- use dev_dbg instead of dev_err

 drivers/serial/mpc52xx_uart.c |   23 +++++++++++++++--------
 1 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/drivers/serial/mpc52xx_uart.c b/drivers/serial/mpc52xx_uart.c
index 28c00c3..172f61f 100644
--- a/drivers/serial/mpc52xx_uart.c
+++ b/drivers/serial/mpc52xx_uart.c
@@ -1109,22 +1109,29 @@ mpc52xx_uart_of_probe(struct of_device *op, const struct of_device_id *match)
 		return ret;
 
 	port->mapbase = res.start;
+	if (!port->mapbase) {
+		dev_dbg(&op->dev, "Could not allocate resources for PSC\n");
+		return -EINVAL;
+	}
+
 	port->irq = irq_of_parse_and_map(op->node, 0);
+	if (port->irq == NO_IRQ) {
+		dev_dbg(&op->dev, "Could not get irq\n");
+		return -EINVAL;
+	}
 
 	dev_dbg(&op->dev, "mpc52xx-psc uart at %p, irq=%x, freq=%i\n",
 		(void *)port->mapbase, port->irq, port->uartclk);
 
-	if ((port->irq == NO_IRQ) || !port->mapbase) {
-		printk(KERN_ERR "Could not allocate resources for PSC\n");
-		return -EINVAL;
-	}
-
 	/* Add the port to the uart sub-system */
 	ret = uart_add_one_port(&mpc52xx_uart_driver, port);
-	if (!ret)
-		dev_set_drvdata(&op->dev, (void *)port);
+	if (ret) {
+		irq_dispose_mapping(port->irq);
+		return ret;
+	}
 
-	return ret;
+	dev_set_drvdata(&op->dev, (void *)port);
+	return 0;
 }
 
 static int
-- 
1.5.6.5

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

end of thread, other threads:[~2008-12-19 15:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-11-27 15:33 [PATCH] mpc52xx/serial: fix error paths in probe function Wolfram Sang
2008-11-27 16:40 ` Jon Smirl
2008-11-27 20:30   ` Wolfram Sang
2008-12-19 15:32 ` [PATCH V2] " Wolfram Sang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).