* [Qemu-devel] [PATCH for-2.9] virtio: Fix error handling in virtio_bus_device_plugged
@ 2017-03-17 11:33 Fam Zheng
2017-03-17 11:55 ` Cornelia Huck
2017-03-17 12:18 ` Andrew Jones
0 siblings, 2 replies; 5+ messages in thread
From: Fam Zheng @ 2017-03-17 11:33 UTC (permalink / raw)
To: qemu-devel; +Cc: drjones, Michael S. Tsirkin
For one thing we shouldn't continue if an error happened, for the other
two steps failing can cause an abort() in error_setg because we reuse
the same errp blindly.
Add error handling checks to fix both issues.
Signed-off-by: Fam Zheng <famz@redhat.com>
---
hw/virtio/virtio-bus.c | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
diff --git a/hw/virtio/virtio-bus.c b/hw/virtio/virtio-bus.c
index a886011..ef76919 100644
--- a/hw/virtio/virtio-bus.c
+++ b/hw/virtio/virtio-bus.c
@@ -25,6 +25,7 @@
#include "qemu/osdep.h"
#include "hw/hw.h"
#include "qemu/error-report.h"
+#include "qapi/error.h"
#include "hw/qdev.h"
#include "hw/virtio/virtio-bus.h"
#include "hw/virtio/virtio.h"
@@ -48,21 +49,34 @@ void virtio_bus_device_plugged(VirtIODevice *vdev, Error **errp)
VirtioBusClass *klass = VIRTIO_BUS_GET_CLASS(bus);
VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(vdev);
bool has_iommu = virtio_host_has_feature(vdev, VIRTIO_F_IOMMU_PLATFORM);
+ Error *local_err = NULL;
DPRINTF("%s: plug device.\n", qbus->name);
if (klass->pre_plugged != NULL) {
- klass->pre_plugged(qbus->parent, errp);
+ klass->pre_plugged(qbus->parent, &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
+ return;
+ }
}
/* Get the features of the plugged device. */
assert(vdc->get_features != NULL);
vdev->host_features = vdc->get_features(vdev, vdev->host_features,
- errp);
+ &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
+ return;
+ }
if (klass->device_plugged != NULL) {
klass->device_plugged(qbus->parent, errp);
}
+ if (local_err) {
+ error_propagate(errp, local_err);
+ return;
+ }
if (klass->get_dma_as != NULL && has_iommu) {
virtio_add_feature(&vdev->host_features, VIRTIO_F_IOMMU_PLATFORM);
--
2.9.3
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH for-2.9] virtio: Fix error handling in virtio_bus_device_plugged
2017-03-17 11:33 [Qemu-devel] [PATCH for-2.9] virtio: Fix error handling in virtio_bus_device_plugged Fam Zheng
@ 2017-03-17 11:55 ` Cornelia Huck
2017-03-17 12:18 ` Andrew Jones
1 sibling, 0 replies; 5+ messages in thread
From: Cornelia Huck @ 2017-03-17 11:55 UTC (permalink / raw)
To: Fam Zheng; +Cc: qemu-devel, drjones, Michael S. Tsirkin
On Fri, 17 Mar 2017 19:33:53 +0800
Fam Zheng <famz@redhat.com> wrote:
> For one thing we shouldn't continue if an error happened, for the other
> two steps failing can cause an abort() in error_setg because we reuse
> the same errp blindly.
>
> Add error handling checks to fix both issues.
>
> Signed-off-by: Fam Zheng <famz@redhat.com>
> ---
> hw/virtio/virtio-bus.c | 18 ++++++++++++++++--
> 1 file changed, 16 insertions(+), 2 deletions(-)
Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH for-2.9] virtio: Fix error handling in virtio_bus_device_plugged
2017-03-17 11:33 [Qemu-devel] [PATCH for-2.9] virtio: Fix error handling in virtio_bus_device_plugged Fam Zheng
2017-03-17 11:55 ` Cornelia Huck
@ 2017-03-17 12:18 ` Andrew Jones
2017-03-17 12:28 ` Cornelia Huck
2017-03-17 12:29 ` Fam Zheng
1 sibling, 2 replies; 5+ messages in thread
From: Andrew Jones @ 2017-03-17 12:18 UTC (permalink / raw)
To: Fam Zheng; +Cc: qemu-devel, Michael S. Tsirkin
On Fri, Mar 17, 2017 at 07:33:53PM +0800, Fam Zheng wrote:
> For one thing we shouldn't continue if an error happened, for the other
> two steps failing can cause an abort() in error_setg because we reuse
> the same errp blindly.
>
> Add error handling checks to fix both issues.
>
> Signed-off-by: Fam Zheng <famz@redhat.com>
> ---
> hw/virtio/virtio-bus.c | 18 ++++++++++++++++--
> 1 file changed, 16 insertions(+), 2 deletions(-)
>
> diff --git a/hw/virtio/virtio-bus.c b/hw/virtio/virtio-bus.c
> index a886011..ef76919 100644
> --- a/hw/virtio/virtio-bus.c
> +++ b/hw/virtio/virtio-bus.c
> @@ -25,6 +25,7 @@
> #include "qemu/osdep.h"
> #include "hw/hw.h"
> #include "qemu/error-report.h"
> +#include "qapi/error.h"
> #include "hw/qdev.h"
> #include "hw/virtio/virtio-bus.h"
> #include "hw/virtio/virtio.h"
> @@ -48,21 +49,34 @@ void virtio_bus_device_plugged(VirtIODevice *vdev, Error **errp)
> VirtioBusClass *klass = VIRTIO_BUS_GET_CLASS(bus);
> VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(vdev);
> bool has_iommu = virtio_host_has_feature(vdev, VIRTIO_F_IOMMU_PLATFORM);
> + Error *local_err = NULL;
>
> DPRINTF("%s: plug device.\n", qbus->name);
>
> if (klass->pre_plugged != NULL) {
> - klass->pre_plugged(qbus->parent, errp);
> + klass->pre_plugged(qbus->parent, &local_err);
> + if (local_err) {
> + error_propagate(errp, local_err);
> + return;
> + }
> }
>
> /* Get the features of the plugged device. */
> assert(vdc->get_features != NULL);
> vdev->host_features = vdc->get_features(vdev, vdev->host_features,
> - errp);
> + &local_err);
> + if (local_err) {
> + error_propagate(errp, local_err);
> + return;
> + }
>
> if (klass->device_plugged != NULL) {
> klass->device_plugged(qbus->parent, errp);
Did you intend to change this errp to &local_err, as well? If not,
then the body of the below hunk is unreachable, as local_err can
never be non-null there.
Thanks,
drew
> }
> + if (local_err) {
> + error_propagate(errp, local_err);
> + return;
> + }
>
> if (klass->get_dma_as != NULL && has_iommu) {
> virtio_add_feature(&vdev->host_features, VIRTIO_F_IOMMU_PLATFORM);
> --
> 2.9.3
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH for-2.9] virtio: Fix error handling in virtio_bus_device_plugged
2017-03-17 12:18 ` Andrew Jones
@ 2017-03-17 12:28 ` Cornelia Huck
2017-03-17 12:29 ` Fam Zheng
1 sibling, 0 replies; 5+ messages in thread
From: Cornelia Huck @ 2017-03-17 12:28 UTC (permalink / raw)
To: Andrew Jones; +Cc: Fam Zheng, qemu-devel, Michael S. Tsirkin
On Fri, 17 Mar 2017 13:18:16 +0100
Andrew Jones <drjones@redhat.com> wrote:
> On Fri, Mar 17, 2017 at 07:33:53PM +0800, Fam Zheng wrote:
> > For one thing we shouldn't continue if an error happened, for the other
> > two steps failing can cause an abort() in error_setg because we reuse
> > the same errp blindly.
> >
> > Add error handling checks to fix both issues.
> >
> > Signed-off-by: Fam Zheng <famz@redhat.com>
> > ---
> > hw/virtio/virtio-bus.c | 18 ++++++++++++++++--
> > 1 file changed, 16 insertions(+), 2 deletions(-)
> >
> > if (klass->device_plugged != NULL) {
> > klass->device_plugged(qbus->parent, errp);
>
> Did you intend to change this errp to &local_err, as well? If not,
> then the body of the below hunk is unreachable, as local_err can
> never be non-null there.
Oh, I managed to overlook this.
So my r-b applies if this is changed to use local_err :)
>
> Thanks,
> drew
>
> > }
> > + if (local_err) {
> > + error_propagate(errp, local_err);
> > + return;
> > + }
> >
> > if (klass->get_dma_as != NULL && has_iommu) {
> > virtio_add_feature(&vdev->host_features, VIRTIO_F_IOMMU_PLATFORM);
> > --
> > 2.9.3
> >
> >
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH for-2.9] virtio: Fix error handling in virtio_bus_device_plugged
2017-03-17 12:18 ` Andrew Jones
2017-03-17 12:28 ` Cornelia Huck
@ 2017-03-17 12:29 ` Fam Zheng
1 sibling, 0 replies; 5+ messages in thread
From: Fam Zheng @ 2017-03-17 12:29 UTC (permalink / raw)
To: Andrew Jones; +Cc: qemu-devel, Michael S. Tsirkin
On Fri, 03/17 13:18, Andrew Jones wrote:
> On Fri, Mar 17, 2017 at 07:33:53PM +0800, Fam Zheng wrote:
> > For one thing we shouldn't continue if an error happened, for the other
> > two steps failing can cause an abort() in error_setg because we reuse
> > the same errp blindly.
> >
> > Add error handling checks to fix both issues.
> >
> > Signed-off-by: Fam Zheng <famz@redhat.com>
> > ---
> > hw/virtio/virtio-bus.c | 18 ++++++++++++++++--
> > 1 file changed, 16 insertions(+), 2 deletions(-)
> >
> > diff --git a/hw/virtio/virtio-bus.c b/hw/virtio/virtio-bus.c
> > index a886011..ef76919 100644
> > --- a/hw/virtio/virtio-bus.c
> > +++ b/hw/virtio/virtio-bus.c
> > @@ -25,6 +25,7 @@
> > #include "qemu/osdep.h"
> > #include "hw/hw.h"
> > #include "qemu/error-report.h"
> > +#include "qapi/error.h"
> > #include "hw/qdev.h"
> > #include "hw/virtio/virtio-bus.h"
> > #include "hw/virtio/virtio.h"
> > @@ -48,21 +49,34 @@ void virtio_bus_device_plugged(VirtIODevice *vdev, Error **errp)
> > VirtioBusClass *klass = VIRTIO_BUS_GET_CLASS(bus);
> > VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(vdev);
> > bool has_iommu = virtio_host_has_feature(vdev, VIRTIO_F_IOMMU_PLATFORM);
> > + Error *local_err = NULL;
> >
> > DPRINTF("%s: plug device.\n", qbus->name);
> >
> > if (klass->pre_plugged != NULL) {
> > - klass->pre_plugged(qbus->parent, errp);
> > + klass->pre_plugged(qbus->parent, &local_err);
> > + if (local_err) {
> > + error_propagate(errp, local_err);
> > + return;
> > + }
> > }
> >
> > /* Get the features of the plugged device. */
> > assert(vdc->get_features != NULL);
> > vdev->host_features = vdc->get_features(vdev, vdev->host_features,
> > - errp);
> > + &local_err);
> > + if (local_err) {
> > + error_propagate(errp, local_err);
> > + return;
> > + }
> >
> > if (klass->device_plugged != NULL) {
> > klass->device_plugged(qbus->parent, errp);
>
> Did you intend to change this errp to &local_err, as well? If not,
> then the body of the below hunk is unreachable, as local_err can
> never be non-null there.
Yes, this is an overlook.
Fam
>
> Thanks,
> drew
>
> > }
> > + if (local_err) {
> > + error_propagate(errp, local_err);
> > + return;
> > + }
> >
> > if (klass->get_dma_as != NULL && has_iommu) {
> > virtio_add_feature(&vdev->host_features, VIRTIO_F_IOMMU_PLATFORM);
> > --
> > 2.9.3
> >
> >
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2017-03-17 12:29 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-03-17 11:33 [Qemu-devel] [PATCH for-2.9] virtio: Fix error handling in virtio_bus_device_plugged Fam Zheng
2017-03-17 11:55 ` Cornelia Huck
2017-03-17 12:18 ` Andrew Jones
2017-03-17 12:28 ` Cornelia Huck
2017-03-17 12:29 ` Fam Zheng
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).