Skip to contentSkip to conversation

cadence_uart: check for serial backend before using it.

PATCH In review [email protected] 2 participants 3 messages Jul 15, 2014 – Jul 16, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cadence_uart: check for serial backend before using it.

From: KONRAD Frederic <[email protected]>

This checks that s->chr is not NULL before using it.

---
 hw/char/cadence_uart.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
hw/char/cadence_uart.c +11 -4
index dbbc167..a5736cb 100644
@@ -175,8 +175,10 @@ static void uart_send_breaks(UartState *s)
 {
     int break_enabled = 1;
 
-    qemu_chr_fe_ioctl(s->chr, CHR_IOCTL_SERIAL_SET_BREAK,
-                               &break_enabled);
+    if (s->chr) {
+        qemu_chr_fe_ioctl(s->chr, CHR_IOCTL_SERIAL_SET_BREAK,
+                                   &break_enabled);
+    }
 }
 
 static void uart_parameters_setup(UartState *s)
@@ -227,7 +229,9 @@ static void uart_parameters_setup(UartState *s)
 
     packet_size += ssp.data_bits + ssp.stop_bits;
     s->char_tx_time = (get_ticks_per_sec() / ssp.speed) * packet_size;
-    qemu_chr_fe_ioctl(s->chr, CHR_IOCTL_SERIAL_SET_PARAMS, &ssp);
+    if (s->chr) {
+        qemu_chr_fe_ioctl(s->chr, CHR_IOCTL_SERIAL_SET_PARAMS, &ssp);
+    }
 }
 
 static int uart_can_receive(void *opaque)
@@ -295,6 +299,7 @@ static gboolean cadence_uart_xmit(GIOChannel *chan, GIOCondition cond,
     /* instant drain the fifo when there's no back-end */
     if (!s->chr) {
         s->tx_count = 0;
+        return FALSE;
     }
 
     if (!s->tx_count) {
@@ -375,7 +380,9 @@ static void uart_read_rx_fifo(UartState *s, uint32_t *c)
         *c = s->rx_fifo[rx_rpos];
         s->rx_count--;
 
-        qemu_chr_accept_input(s->chr);
+        if (s->chr) {
+            qemu_chr_accept_input(s->chr);
+        }
     } else {
         *c = 0;
     }
Signature · 1 line
1.9.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 38 lines · On Wed, Jul 16, 2014 at 1:18 AM, <[email protected]> wrote:

From: KONRAD Frederic <[email protected]>

This checks that s->chr is not NULL before using it.

---
 hw/char/cadence_uart.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
hw/char/cadence_uart.c +7 -3
index dbbc167..a5736cb 100644
@@ -175,8 +175,10 @@ static void uart_send_breaks(UartState *s)
 {
     int break_enabled = 1;
 
-    qemu_chr_fe_ioctl(s->chr, CHR_IOCTL_SERIAL_SET_BREAK,
-                               &break_enabled);
+    if (s->chr) {
+        qemu_chr_fe_ioctl(s->chr, CHR_IOCTL_SERIAL_SET_BREAK,
+                                   &break_enabled);
+    }
 }
 
 static void uart_parameters_setup(UartState *s)
@@ -227,7 +229,9 @@ static void uart_parameters_setup(UartState *s)
 
     packet_size += ssp.data_bits + ssp.stop_bits;
     s->char_tx_time = (get_ticks_per_sec() / ssp.speed) * packet_size;
-    qemu_chr_fe_ioctl(s->chr, CHR_IOCTL_SERIAL_SET_PARAMS, &ssp);
+    if (s->chr) {
+        qemu_chr_fe_ioctl(s->chr, CHR_IOCTL_SERIAL_SET_PARAMS, &ssp);
+    }
 }
 
 static int uart_can_receive(void *opaque)

hw/char/cadence_uart.c static gboolean cadence_uart_xmit(GIOChannel *chan, GIOCondition cond, · line 302

Quoted 4 lines
hw/char/cadence_uart.c +1 -0
@@ -295,6 +299,7 @@ static gboolean cadence_uart_xmit(GIOChannel *chan, GIOCondition cond,
     /* instant drain the fifo when there's no back-end */
     if (!s->chr) {
         s->tx_count = 0;
+        return FALSE;

Is this needed? With s->tx_count forced to 0 in the NULL dev case, won't the next if trigger immediately and return?

300 if (!s->tx_count) {
301 return FALSE;
302 }

With this hunk dropped,

And recommended for 2.1.

Regards,
Peter

Quoted 18 lines
hw/char/cadence_uart.c +3 -2
     }
 
     if (!s->tx_count) {
@@ -375,7 +380,9 @@ static void uart_read_rx_fifo(UartState *s, uint32_t *c)
         *c = s->rx_fifo[rx_rpos];
         s->rx_count--;
 
-        qemu_chr_accept_input(s->chr);
+        if (s->chr) {
+            qemu_chr_accept_input(s->chr);
+        }
     } else {
         *c = 0;
     }
--

1.9.0

#2 lore raw
Quoted 37 lines · Peter Crosthwaite
Quoted 36 lines · On Wed, Jul 16, 2014 at 1:18 AM, <[email protected]> wrote:

From: KONRAD Frederic <[email protected]>

This checks that s->chr is not NULL before using it.

---
  hw/char/cadence_uart.c | 15 +++++++++++----
  1 file changed, 11 insertions(+), 4 deletions(-)
hw/char/cadence_uart.c +7 -3
index dbbc167..a5736cb 100644
@@ -175,8 +175,10 @@ static void uart_send_breaks(UartState *s)
  {
      int break_enabled = 1;
 
-    qemu_chr_fe_ioctl(s->chr, CHR_IOCTL_SERIAL_SET_BREAK,
-                               &break_enabled);
+    if (s->chr) {
+        qemu_chr_fe_ioctl(s->chr, CHR_IOCTL_SERIAL_SET_BREAK,
+                                   &break_enabled);
+    }
  }
 
  static void uart_parameters_setup(UartState *s)
@@ -227,7 +229,9 @@ static void uart_parameters_setup(UartState *s)
 
      packet_size += ssp.data_bits + ssp.stop_bits;
      s->char_tx_time = (get_ticks_per_sec() / ssp.speed) * packet_size;
-    qemu_chr_fe_ioctl(s->chr, CHR_IOCTL_SERIAL_SET_PARAMS, &ssp);
+    if (s->chr) {
+        qemu_chr_fe_ioctl(s->chr, CHR_IOCTL_SERIAL_SET_PARAMS, &ssp);
+    }
  }
 
Quoted 8 lines

hw/char/cadence_uart.c static gboolean cadence_uart_xmit(GIOChannel *chan, GIOCondition cond, · line 302

Quoted 6 lines
hw/char/cadence_uart.c +1 -0
  static int uart_can_receive(void *opaque)
@@ -295,6 +299,7 @@ static gboolean cadence_uart_xmit(GIOChannel *chan, GIOCondition cond,
      /* instant drain the fifo when there's no back-end */
      if (!s->chr) {
          s->tx_count = 0;
+        return FALSE;

Is this needed? With s->tx_count forced to 0 in the NULL dev case, won't the next if trigger immediately and return?

True,
I'll make this change and resend.

Thanks,
Fred

Quoted 32 lines

300 if (!s->tx_count) {
301 return FALSE;
302 }

With this hunk dropped,

And recommended for 2.1.

Regards,
Peter

Quoted 18 lines
hw/char/cadence_uart.c +3 -2
      }
 
      if (!s->tx_count) {
@@ -375,7 +380,9 @@ static void uart_read_rx_fifo(UartState *s, uint32_t *c)
          *c = s->rx_fifo[rx_rpos];
          s->rx_count--;
 
-        qemu_chr_accept_input(s->chr);
+        if (s->chr) {
+            qemu_chr_accept_input(s->chr);
+        }
      } else {
          *c = 0;
      }
--

1.9.0