cadence_uart: check serial backend before using it.
PATCH 1/1 cadence_uart: check serial backend before using it.
From: KONRAD Frederic <[email protected]>
Segfault occurs when there are less than two serial backends with zynq platform.
This checks that s->chr is not NULL before using it.
Signed-off-by KONRAD Frederic <[email protected]>
Reviewed-by Peter Crosthwaite <[email protected]>
--- hw/char/cadence_uart.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
hw/char/cadence_uart.c +10 -4
@@ -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)
@@ -375,7 +379,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
Peter Maydell
AppliedQuoted 11 lines · On 16 July 2014 08:42, <[email protected]> wrote:
From: KONRAD Frederic <[email protected]>
Segfault occurs when there are less than two serial backends with zynq platform.
This checks that
s->chris not NULL before using it.Signed-off-by KONRAD Frederic <[email protected]>Reviewed-by Peter Crosthwaite <[email protected]>--- hw/char/cadence_uart.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
Applied to master, thanks.
-- PMM