[1/1] virtio-serial-bus: assert port is non-null in remove_port()

Submitted by Amit Shah on Dec. 18, 2012, 7:43 a.m.

Details

Message ID e511f84e3897014ffe70ebb00124f028f65e098f.1355816625.git.amit.shah@redhat.com
State New
Headers show

Commit Message

Amit Shah Dec. 18, 2012, 7:43 a.m.
remove_port() is called from qdev's unplug callback, and we're certain
the port will be found in our list of ports.  Adding an assert()
documents this.

This was flagged by Coverity, fix suggested by Markus.

CC: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Amit Shah <amit.shah@redhat.com>
---
 hw/virtio-serial-bus.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Markus Armbruster Dec. 18, 2012, 8:44 a.m.
Amit Shah <amit.shah@redhat.com> writes:

> remove_port() is called from qdev's unplug callback, and we're certain
> the port will be found in our list of ports.  Adding an assert()
> documents this.
>
> This was flagged by Coverity, fix suggested by Markus.
>
> CC: Markus Armbruster <armbru@redhat.com>
> Signed-off-by: Amit Shah <amit.shah@redhat.com>
> ---
>  hw/virtio-serial-bus.c | 6 ++++++
>  1 file changed, 6 insertions(+)
>
> diff --git a/hw/virtio-serial-bus.c b/hw/virtio-serial-bus.c
> index 3ea95b8..ce4556f 100644
> --- a/hw/virtio-serial-bus.c
> +++ b/hw/virtio-serial-bus.c
> @@ -852,6 +852,12 @@ static void remove_port(VirtIOSerial *vser, uint32_t port_id)
>      vser->ports_map[i] &= ~(1U << (port_id % 32));
>  
>      port = find_port_by_id(vser, port_id);
> +    /*
> +     * This function is only called from qdev's unplug callback; if we
> +     * get a NULL port here, we're in trouble.
> +     */
> +    assert(port);
> +
>      /* Flush out any unconsumed buffers first */
>      discard_vq_data(port->ovq, &port->vser->vdev);

Leaving it to you got me a nice comment!

Reviewed-by: Markus Armbruster <armbru@redhat.com>

Patch hide | download patch | download mbox

diff --git a/hw/virtio-serial-bus.c b/hw/virtio-serial-bus.c
index 3ea95b8..ce4556f 100644
--- a/hw/virtio-serial-bus.c
+++ b/hw/virtio-serial-bus.c
@@ -852,6 +852,12 @@  static void remove_port(VirtIOSerial *vser, uint32_t port_id)
     vser->ports_map[i] &= ~(1U << (port_id % 32));
 
     port = find_port_by_id(vser, port_id);
+    /*
+     * This function is only called from qdev's unplug callback; if we
+     * get a NULL port here, we're in trouble.
+     */
+    assert(port);
+
     /* Flush out any unconsumed buffers first */
     discard_vq_data(port->ovq, &port->vser->vdev);