All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] xen: char: Remove unnecessary (uart->irq > 0) check
@ 2018-04-28  9:08 Amit Singh Tomar
  2018-04-30  8:19 ` Jan Beulich
  2018-04-30 14:32 ` Andre Przywara
  0 siblings, 2 replies; 4+ messages in thread
From: Amit Singh Tomar @ 2018-04-28  9:08 UTC (permalink / raw)
  To: xen-devel
  Cc: edgar.iglesias, sstabellini, wei.liu2, George.Dunlap,
	andre.przywara, ian.jackson, tim, julien.grall, jbeulich,
	andrew.cooper3, baozich, Amit Singh Tomar

While working on MVEBU uart driver, Julien pointed out that (uart->irq > 0)
check is unnecessary during irq set up.if ever there is an invalid irq, driver
initialization itself would be bailed out from platform_get_irq.

This patch would remove similar check for other uart drivers present in XEN.

Signed-off-by: Amit Singh Tomar <amittomer25@gmail.com>
---
    * This patch is only compiled tested.
---
 xen/drivers/char/cadence-uart.c | 15 ++++++++-------
 xen/drivers/char/ns16550.c      | 35 ++++++++++++++---------------------
 xen/drivers/char/omap-uart.c    |  2 +-
 xen/drivers/char/pl011.c        | 13 +++++++------
 4 files changed, 30 insertions(+), 35 deletions(-)

diff --git a/xen/drivers/char/cadence-uart.c b/xen/drivers/char/cadence-uart.c
index 22905ba..1575787 100644
--- a/xen/drivers/char/cadence-uart.c
+++ b/xen/drivers/char/cadence-uart.c
@@ -72,13 +72,14 @@ static void __init cuart_init_postirq(struct serial_port *port)
     struct cuart *uart = port->uart;
     int rc;
 
-    if ( uart->irq > 0 )
+    uart->irqaction.handler = cuart_interrupt;
+    uart->irqaction.name    = "cadence-uart";
+    uart->irqaction.dev_id  = port;
+
+    if ( (rc = setup_irq(uart->irq, 0, &uart->irqaction)) != 0 )
     {
-        uart->irqaction.handler = cuart_interrupt;
-        uart->irqaction.name    = "cadence-uart";
-        uart->irqaction.dev_id  = port;
-        if ( (rc = setup_irq(uart->irq, 0, &uart->irqaction)) != 0 )
-            printk("ERROR: Failed to allocate cadence-uart IRQ %d\n", uart->irq);
+        printk("ERROR: Failed to allocate cadence-uart IRQ %d\n", uart->irq);
+        return;
     }
 
     /* Clear pending error interrupts */
@@ -130,7 +131,7 @@ static int __init cuart_irq(struct serial_port *port)
 {
     struct cuart *uart = port->uart;
 
-    return ( (uart->irq > 0) ? uart->irq : -1 );
+    return uart->irq;
 }
 
 static const struct vuart_info *cuart_vuart(struct serial_port *port)
diff --git a/xen/drivers/char/ns16550.c b/xen/drivers/char/ns16550.c
index f32dbd3..ba50a1e 100644
--- a/xen/drivers/char/ns16550.c
+++ b/xen/drivers/char/ns16550.c
@@ -714,18 +714,12 @@ static void __init ns16550_init_preirq(struct serial_port *port)
 
 static void ns16550_setup_postirq(struct ns16550 *uart)
 {
-    if ( uart->irq > 0 )
-    {
-        /* Master interrupt enable; also keep DTR/RTS asserted. */
-        ns_write_reg(uart,
-                     UART_MCR, UART_MCR_OUT2 | UART_MCR_DTR | UART_MCR_RTS);
-
-        /* Enable receive interrupts. */
-        ns_write_reg(uart, UART_IER, UART_IER_ERDAI);
-    }
+    /* Master interrupt enable; also keep DTR/RTS asserted. */
+    ns_write_reg(uart, UART_MCR, UART_MCR_OUT2 | UART_MCR_DTR | UART_MCR_RTS);
+    /* Enable receive interrupts. */
+    ns_write_reg(uart, UART_IER, UART_IER_ERDAI);
 
-    if ( uart->irq >= 0 )
-        set_timer(&uart->timer, NOW() + MILLISECS(uart->timeout_ms));
+    set_timer(&uart->timer, NOW() + MILLISECS(uart->timeout_ms));
 }
 
 static void __init ns16550_init_postirq(struct serial_port *port)
@@ -733,9 +727,6 @@ static void __init ns16550_init_postirq(struct serial_port *port)
     struct ns16550 *uart = port->uart;
     int rc, bits;
 
-    if ( uart->irq < 0 )
-        return;
-
     serial_async_transmit(port);
 
     init_timer(&uart->timer, ns16550_poll, port, 0);
@@ -746,13 +737,14 @@ static void __init ns16550_init_postirq(struct serial_port *port)
     uart->timeout_ms = max_t(
         unsigned int, 1, (bits * uart->fifo_size * 1000) / uart->baud);
 
-    if ( uart->irq > 0 )
+    uart->irqaction.handler = ns16550_interrupt;
+    uart->irqaction.name    = "ns16550";
+    uart->irqaction.dev_id  = port;
+
+    if ( (rc = setup_irq(uart->irq, 0, &uart->irqaction)) != 0 )
     {
-        uart->irqaction.handler = ns16550_interrupt;
-        uart->irqaction.name    = "ns16550";
-        uart->irqaction.dev_id  = port;
-        if ( (rc = setup_irq(uart->irq, 0, &uart->irqaction)) != 0 )
-            printk("ERROR: Failed to allocate ns16550 IRQ %d\n", uart->irq);
+        printk("ERROR: Failed to allocate ns16550 IRQ %d\n", uart->irq);
+        return;
     }
 
     ns16550_setup_postirq(uart);
@@ -874,7 +866,8 @@ static void __init ns16550_endboot(struct serial_port *port)
 static int __init ns16550_irq(struct serial_port *port)
 {
     struct ns16550 *uart = port->uart;
-    return ((uart->irq > 0) ? uart->irq : -1);
+
+    return uart->irq;
 }
 
 static void ns16550_start_tx(struct serial_port *port)
diff --git a/xen/drivers/char/omap-uart.c b/xen/drivers/char/omap-uart.c
index d6a5d59..2ce4e71 100644
--- a/xen/drivers/char/omap-uart.c
+++ b/xen/drivers/char/omap-uart.c
@@ -294,7 +294,7 @@ static int __init omap_uart_irq(struct serial_port *port)
 {
     struct omap_uart *uart = port->uart;
 
-    return ((uart->irq > 0) ? uart->irq : -1);
+    return uart->irq;
 }
 
 static const struct vuart_info *omap_vuart_info(struct serial_port *port)
diff --git a/xen/drivers/char/pl011.c b/xen/drivers/char/pl011.c
index be67242..e007918 100644
--- a/xen/drivers/char/pl011.c
+++ b/xen/drivers/char/pl011.c
@@ -128,13 +128,14 @@ static void __init pl011_init_postirq(struct serial_port *port)
     struct pl011 *uart = port->uart;
     int rc;
 
-    if ( uart->irq > 0 )
+    uart->irqaction.handler = pl011_interrupt;
+    uart->irqaction.name    = "pl011";
+    uart->irqaction.dev_id  = port;
+
+    if ( (rc = setup_irq(uart->irq, 0, &uart->irqaction)) != 0 )
     {
-        uart->irqaction.handler = pl011_interrupt;
-        uart->irqaction.name    = "pl011";
-        uart->irqaction.dev_id  = port;
-        if ( (rc = setup_irq(uart->irq, 0, &uart->irqaction)) != 0 )
-            printk("ERROR: Failed to allocate pl011 IRQ %d\n", uart->irq);
+        printk("ERROR: Failed to allocate pl011 IRQ %d\n", uart->irq);
+        return;
     }
 
     /* Clear pending error interrupts */
-- 
1.9.1


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

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

* Re: [PATCH] xen: char: Remove unnecessary (uart->irq > 0) check
  2018-04-28  9:08 [PATCH] xen: char: Remove unnecessary (uart->irq > 0) check Amit Singh Tomar
@ 2018-04-30  8:19 ` Jan Beulich
  2018-04-30 14:31   ` Julien Grall
  2018-04-30 14:32 ` Andre Przywara
  1 sibling, 1 reply; 4+ messages in thread
From: Jan Beulich @ 2018-04-30  8:19 UTC (permalink / raw)
  To: Amit Singh Tomar
  Cc: edgar.iglesias, Stefano Stabellini, Wei Liu, George Dunlap,
	andre.przywara, Ian Jackson, Tim Deegan, Julien Grall,
	Andrew Cooper, xen-devel, baozich

>>> On 28.04.18 at 11:08, <amittomer25@gmail.com> wrote:
> While working on MVEBU uart driver, Julien pointed out that (uart->irq > 0)
> check is unnecessary during irq set up.if ever there is an invalid irq, driver
> initialization itself would be bailed out from platform_get_irq.
> 
> This patch would remove similar check for other uart drivers present in XEN.

At the example of the changes to ns16550.c you do, this is not correct. I
can't judge about the various ARM specific drivers, but the 16550 can well
be run in polling mode, and hence failure to set up an interrupt is not fatal
to overall driver initialization.

> Signed-off-by: Amit Singh Tomar <amittomer25@gmail.com>
> ---
>     * This patch is only compiled tested.

In which case this should be marked RFC imo.

Jan



_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

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

* Re: [PATCH] xen: char: Remove unnecessary (uart->irq > 0) check
  2018-04-30  8:19 ` Jan Beulich
@ 2018-04-30 14:31   ` Julien Grall
  0 siblings, 0 replies; 4+ messages in thread
From: Julien Grall @ 2018-04-30 14:31 UTC (permalink / raw)
  To: Jan Beulich, Amit Singh Tomar
  Cc: edgar.iglesias, Stefano Stabellini, Wei Liu, George Dunlap,
	andre.przywara, Ian Jackson, Tim Deegan, Andrew Cooper,
	xen-devel, baozich

Hi,

On 30/04/18 09:19, Jan Beulich wrote:
>>>> On 28.04.18 at 11:08, <amittomer25@gmail.com> wrote:
>> While working on MVEBU uart driver, Julien pointed out that (uart->irq > 0)
>> check is unnecessary during irq set up.if ever there is an invalid irq, driver
>> initialization itself would be bailed out from platform_get_irq.
>>
>> This patch would remove similar check for other uart drivers present in XEN.
> 
> At the example of the changes to ns16550.c you do, this is not correct. I
> can't judge about the various ARM specific drivers, but the 16550 can well
> be run in polling mode, and hence failure to set up an interrupt is not fatal
> to overall driver initialization.

This makes sense for any ARM only UART driver because they don't support 
polling. However, I agree that if the driver is supporting polling (such 
as NS16550) then you should keep the irq check around.

Cheers,

> 
>> Signed-off-by: Amit Singh Tomar <amittomer25@gmail.com>
>> ---
>>      * This patch is only compiled tested.
> 
> In which case this should be marked RFC imo.
> 
> Jan
> 
> 

-- 
Julien Grall

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

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

* Re: [PATCH] xen: char: Remove unnecessary (uart->irq > 0) check
  2018-04-28  9:08 [PATCH] xen: char: Remove unnecessary (uart->irq > 0) check Amit Singh Tomar
  2018-04-30  8:19 ` Jan Beulich
@ 2018-04-30 14:32 ` Andre Przywara
  1 sibling, 0 replies; 4+ messages in thread
From: Andre Przywara @ 2018-04-30 14:32 UTC (permalink / raw)
  To: Amit Singh Tomar, xen-devel
  Cc: edgar.iglesias, sstabellini, wei.liu2, George.Dunlap,
	ian.jackson, tim, julien.grall, jbeulich, andrew.cooper3,
	baozich

Hi,

On 28/04/18 10:08, Amit Singh Tomar wrote:
> While working on MVEBU uart driver, Julien pointed out that (uart->irq > 0)
> check is unnecessary during irq set up.if ever there is an invalid irq, driver
> initialization itself would be bailed out from platform_get_irq.
> 
> This patch would remove similar check for other uart drivers present in XEN.
> 
> Signed-off-by: Amit Singh Tomar <amittomer25@gmail.com>
> ---
>     * This patch is only compiled tested.
> ---
>  xen/drivers/char/cadence-uart.c | 15 ++++++++-------
>  xen/drivers/char/ns16550.c      | 35 ++++++++++++++---------------------
>  xen/drivers/char/omap-uart.c    |  2 +-
>  xen/drivers/char/pl011.c        | 13 +++++++------
>  4 files changed, 30 insertions(+), 35 deletions(-)
> 
> diff --git a/xen/drivers/char/cadence-uart.c b/xen/drivers/char/cadence-uart.c
> index 22905ba..1575787 100644
> --- a/xen/drivers/char/cadence-uart.c
> +++ b/xen/drivers/char/cadence-uart.c
> @@ -72,13 +72,14 @@ static void __init cuart_init_postirq(struct serial_port *port)
>      struct cuart *uart = port->uart;
>      int rc;
>  
> -    if ( uart->irq > 0 )
> +    uart->irqaction.handler = cuart_interrupt;
> +    uart->irqaction.name    = "cadence-uart";
> +    uart->irqaction.dev_id  = port;
> +
> +    if ( (rc = setup_irq(uart->irq, 0, &uart->irqaction)) != 0 )
>      {
> -        uart->irqaction.handler = cuart_interrupt;
> -        uart->irqaction.name    = "cadence-uart";
> -        uart->irqaction.dev_id  = port;
> -        if ( (rc = setup_irq(uart->irq, 0, &uart->irqaction)) != 0 )
> -            printk("ERROR: Failed to allocate cadence-uart IRQ %d\n", uart->irq);
> +        printk("ERROR: Failed to allocate cadence-uart IRQ %d\n", uart->irq);
> +        return;

Careful, this changes the behaviour here:
Formerly a failure in setup_irq() led to just the warning, but then
execution (and initialisation) continued, even without an IRQ properly
set up. Depending on the UART and its driver this may or may not work.
But at least it deserves some mentioning in the commit message.

I quickly tested with an PL011: if setup_irq() does not succeed (hacked
it to use the VGIC IRQ, which is already taken), the UART ignores any
input, because it never actively polls or checks for incoming
characters. But output works perfectly fine, and the system works as
excepted (I can login via ssh, but not on the console).
So we might want to upgrade the error message to state the fatality of
this failure, but proceed anyway (as we do right now).

I haven't (and mostly can't) test other UARTs, but I expect the
behaviour to be the same (even with 16550), at least on ARM, as nothing
polls the UART periodically.

Cheers,
Andre.

>      }
>  
>      /* Clear pending error interrupts */
> @@ -130,7 +131,7 @@ static int __init cuart_irq(struct serial_port *port)
>  {
>      struct cuart *uart = port->uart;
>  
> -    return ( (uart->irq > 0) ? uart->irq : -1 );
> +    return uart->irq;
>  }
>  
>  static const struct vuart_info *cuart_vuart(struct serial_port *port)
> diff --git a/xen/drivers/char/ns16550.c b/xen/drivers/char/ns16550.c
> index f32dbd3..ba50a1e 100644
> --- a/xen/drivers/char/ns16550.c
> +++ b/xen/drivers/char/ns16550.c
> @@ -714,18 +714,12 @@ static void __init ns16550_init_preirq(struct serial_port *port)
>  
>  static void ns16550_setup_postirq(struct ns16550 *uart)
>  {
> -    if ( uart->irq > 0 )
> -    {
> -        /* Master interrupt enable; also keep DTR/RTS asserted. */
> -        ns_write_reg(uart,
> -                     UART_MCR, UART_MCR_OUT2 | UART_MCR_DTR | UART_MCR_RTS);
> -
> -        /* Enable receive interrupts. */
> -        ns_write_reg(uart, UART_IER, UART_IER_ERDAI);
> -    }
> +    /* Master interrupt enable; also keep DTR/RTS asserted. */
> +    ns_write_reg(uart, UART_MCR, UART_MCR_OUT2 | UART_MCR_DTR | UART_MCR_RTS);
> +    /* Enable receive interrupts. */
> +    ns_write_reg(uart, UART_IER, UART_IER_ERDAI);
>  
> -    if ( uart->irq >= 0 )
> -        set_timer(&uart->timer, NOW() + MILLISECS(uart->timeout_ms));
> +    set_timer(&uart->timer, NOW() + MILLISECS(uart->timeout_ms));
>  }
>  
>  static void __init ns16550_init_postirq(struct serial_port *port)
> @@ -733,9 +727,6 @@ static void __init ns16550_init_postirq(struct serial_port *port)
>      struct ns16550 *uart = port->uart;
>      int rc, bits;
>  
> -    if ( uart->irq < 0 )
> -        return;
> -
>      serial_async_transmit(port);
>  
>      init_timer(&uart->timer, ns16550_poll, port, 0);
> @@ -746,13 +737,14 @@ static void __init ns16550_init_postirq(struct serial_port *port)
>      uart->timeout_ms = max_t(
>          unsigned int, 1, (bits * uart->fifo_size * 1000) / uart->baud);
>  
> -    if ( uart->irq > 0 )
> +    uart->irqaction.handler = ns16550_interrupt;
> +    uart->irqaction.name    = "ns16550";
> +    uart->irqaction.dev_id  = port;
> +
> +    if ( (rc = setup_irq(uart->irq, 0, &uart->irqaction)) != 0 )
>      {
> -        uart->irqaction.handler = ns16550_interrupt;
> -        uart->irqaction.name    = "ns16550";
> -        uart->irqaction.dev_id  = port;
> -        if ( (rc = setup_irq(uart->irq, 0, &uart->irqaction)) != 0 )
> -            printk("ERROR: Failed to allocate ns16550 IRQ %d\n", uart->irq);
> +        printk("ERROR: Failed to allocate ns16550 IRQ %d\n", uart->irq);
> +        return;
>      }
>  
>      ns16550_setup_postirq(uart);
> @@ -874,7 +866,8 @@ static void __init ns16550_endboot(struct serial_port *port)
>  static int __init ns16550_irq(struct serial_port *port)
>  {
>      struct ns16550 *uart = port->uart;
> -    return ((uart->irq > 0) ? uart->irq : -1);
> +
> +    return uart->irq;
>  }
>  
>  static void ns16550_start_tx(struct serial_port *port)
> diff --git a/xen/drivers/char/omap-uart.c b/xen/drivers/char/omap-uart.c
> index d6a5d59..2ce4e71 100644
> --- a/xen/drivers/char/omap-uart.c
> +++ b/xen/drivers/char/omap-uart.c
> @@ -294,7 +294,7 @@ static int __init omap_uart_irq(struct serial_port *port)
>  {
>      struct omap_uart *uart = port->uart;
>  
> -    return ((uart->irq > 0) ? uart->irq : -1);
> +    return uart->irq;
>  }
>  
>  static const struct vuart_info *omap_vuart_info(struct serial_port *port)
> diff --git a/xen/drivers/char/pl011.c b/xen/drivers/char/pl011.c
> index be67242..e007918 100644
> --- a/xen/drivers/char/pl011.c
> +++ b/xen/drivers/char/pl011.c
> @@ -128,13 +128,14 @@ static void __init pl011_init_postirq(struct serial_port *port)
>      struct pl011 *uart = port->uart;
>      int rc;
>  
> -    if ( uart->irq > 0 )
> +    uart->irqaction.handler = pl011_interrupt;
> +    uart->irqaction.name    = "pl011";
> +    uart->irqaction.dev_id  = port;
> +
> +    if ( (rc = setup_irq(uart->irq, 0, &uart->irqaction)) != 0 )
>      {
> -        uart->irqaction.handler = pl011_interrupt;
> -        uart->irqaction.name    = "pl011";
> -        uart->irqaction.dev_id  = port;
> -        if ( (rc = setup_irq(uart->irq, 0, &uart->irqaction)) != 0 )
> -            printk("ERROR: Failed to allocate pl011 IRQ %d\n", uart->irq);
> +        printk("ERROR: Failed to allocate pl011 IRQ %d\n", uart->irq);
> +        return;
>      }
>  
>      /* Clear pending error interrupts */
> 

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

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

end of thread, other threads:[~2018-04-30 14:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-28  9:08 [PATCH] xen: char: Remove unnecessary (uart->irq > 0) check Amit Singh Tomar
2018-04-30  8:19 ` Jan Beulich
2018-04-30 14:31   ` Julien Grall
2018-04-30 14:32 ` Andre Przywara

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.