hw/nubus/nubus-virtio-mmio: Fix missing ERRP_GUARD() in nubus_virtio_mmio_realize()
PATCH 1/1 hw/nubus/nubus-virtio-mmio: Fix missing ERRP_GUARD() in nubus_virtio_mmio_realize()
As the comment in qapi/error, dereferencing @errp requires ERRP_GUARD():
* = Why, when and how to use ERRP_GUARD() =
*
* Without ERRP_GUARD(), use of the @errp parameter is restricted:
* - It must not be dereferenced, because it may be null.
...
* ERRP_GUARD() lifts these restrictions.
*
* To use ERRP_GUARD(), add it right at the beginning of the function.
* @errp can then be used without worrying about the argument being
* NULL or &error_fatal.
*
* Using it when it's not needed is safe, but please avoid cluttering
* the source with useless code.
But in nubus_virtio_mmio_realize(), @errp is dereferenced without ERRP_GUARD().
Although nubus_virtio_mmio_realize() - as a DeviceClass.realize() method - doesn't get the NULL @errp parameter, it hasn't triggered the bug that dereferencing the NULL @errp. It's still necessary to follow the requirement of @errp, so add missing ERRP_GUARD() in nubus_virtio_mmio_realize().
--- hw/nubus/nubus-virtio-mmio.c | 1 + 1 file changed, 1 insertion(+)
hw/nubus/nubus-virtio-mmio.c +1 -0
@@ -23,6 +23,7 @@ static void nubus_virtio_mmio_set_input_irq(void *opaque, int n, int level)static void nubus_virtio_mmio_realize (DeviceState *dev,Error **errp) { +ERRP_GUARD ();NubusVirtioMMIODeviceClass *nvmdc =NUBUS_VIRTIO_MMIO_GET_CLASS (dev);NubusVirtioMMIO *s =NUBUS_VIRTIO_MMIO (dev);NubusDevice *nd =NUBUS_DEVICE (dev);
Signature · 1 line
2.34.1
PATCH 1/1 hw/virtio/vdpa-dev: Check returned value instead of dereferencing @errp
As the comment in qapi/error, dereferencing @errp requires ERRP_GUARD():
* = Why, when and how to use ERRP_GUARD() =
*
* Without ERRP_GUARD(), use of the @errp parameter is restricted:
* - It must not be dereferenced, because it may be null.
...
* ERRP_GUARD() lifts these restrictions.
*
* To use ERRP_GUARD(), add it right at the beginning of the function.
* @errp can then be used without worrying about the argument being
* NULL or &error_fatal.
*
* Using it when it's not needed is safe, but please avoid cluttering
* the source with useless code.
Though vhost_vdpa_device_realize() is called at DeviceClass.realize() context and won't get NULL @errp, it's still better to follow the requirement to add the ERRP_GUARD().
But qemu_open() and vhost_vdpa_device_get_u32()'s return values can distinguish between successful and unsuccessful calls, so check the return values directly without dereferencing @errp, which eliminates the need of ERRP_GUARD().
--- hw/virtio/vdpa-dev.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
hw/virtio/vdpa-dev.c +6 -5
@@ -50,6 +50,7 @@ vhost_vdpa_device_get_u32(int fd, unsigned long int cmd, Error **errp)static void vhost_vdpa_device_realize (DeviceState *dev,Error **errp) { +ERRP_GUARD ();VirtIODevice *vdev =VIRTIO_DEVICE (dev);VhostVdpaDevice *v =VHOST_VDPA_DEVICE (vdev);struct vhost_vdpa_iova_range iova_range;
@@ -63,19 +64,19 @@ static void vhost_vdpa_device_realize(DeviceState *dev, Error **errp) } v->vhostfd =qemu_open (v->vhostdev,O_RDWR , errp); -if (*errp) { +if (v->vhostfd <0 ) {return ; } v->vdev_id =vhost_vdpa_device_get_u32 (v->vhostfd,VHOST_VDPA_GET_DEVICE_ID , errp); -if (*errp) { +if (v->vdev_id <0 ) { goto out; } max_queue_size =vhost_vdpa_device_get_u32 (v->vhostfd,VHOST_VDPA_GET_VRING_NUM , errp); -if (*errp) { +if (max_queue_size <0 ) { goto out; }
@@ -89,7 +90,7 @@ static void vhost_vdpa_device_realize(DeviceState *dev, Error **errp) v->num_queues =vhost_vdpa_device_get_u32 (v->vhostfd,VHOST_VDPA_GET_VQS_COUNT , errp); -if (*errp) { +if (v->num_queues <0 ) { goto out; }
@@ -127,7 +128,7 @@ static void vhost_vdpa_device_realize(DeviceState *dev, Error **errp) v->config_size =vhost_vdpa_device_get_u32 (v->vhostfd,VHOST_VDPA_GET_CONFIG_SIZE , errp); -if (*errp) { +if (v->config_size <0 ) { goto vhost_cleanup; }
Signature · 1 line
2.34.1
Re: [PATCH] hw/virtio/vdpa-dev: Check returned value instead of dereferencing @errp
Quoted 40 lines · Zhao Liu
As the comment in qapi/error, dereferencing @errp requires
ERRP_GUARD():* = Why, when and how to use
ERRP_GUARD()=
*
* WithoutERRP_GUARD(), use of the @errp parameter is restricted:
* - It must not be dereferenced, because it may be null.
...
*ERRP_GUARD()lifts these restrictions.
*
* To useERRP_GUARD(), add it right at the beginning of the function.
* @errp can then be used without worrying about the argument being
* NULL or&error_fatal.
*
* Using it when it's not needed is safe, but please avoid cluttering
* the source with useless code.Though
vhost_vdpa_device_realize()is called atDeviceClass.realize()context and won't get NULL @errp, it's still better to follow the requirement to add theERRP_GUARD().But
qemu_open()and vhost_vdpa_device_get_u32()'s return values can distinguish between successful and unsuccessful calls, so check the return values directly without dereferencing @errp, which eliminates the need ofERRP_GUARD().Cc "Michael S. Tsirkin" <[email protected]>Cc "Eugenio Pérez" <[email protected]>Cc Jason Wang <[email protected]>Signed-off-by Zhao Liu <[email protected]>--- hw/virtio/vdpa-dev.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)hw/virtio/vdpa-dev.c +0
-0
hw/virtio/vdpa-dev.c vhost_vdpa_device_get_u32(int fd, unsigned long int cmd, Error **errp) · line 53
Quoted 4 lines
hw/virtio/vdpa-dev.c +1
-0@@ -50,6 +50,7 @@ vhost_vdpa_device_get_u32(int fd, unsigned long int cmd, Error **errp)static void vhost_vdpa_device_realize (DeviceState *dev,Error **errp) { +ERRP_GUARD ();
Good catch, thank you! But removing the err dereferencing eliminates the need for ERRP_GUARD(), doesn't it?
Thanks!
Quoted 47 lines
hw/virtio/vdpa-dev.c +5
-6VirtIODevice *vdev =VIRTIO_DEVICE (dev);VhostVdpaDevice *v =VHOST_VDPA_DEVICE (vdev);struct vhost_vdpa_iova_range iova_range;@@ -63,19 +64,19 @@ static void vhost_vdpa_device_realize(DeviceState *dev, Error **errp) } v->vhostfd =qemu_open (v->vhostdev,O_RDWR , errp); -if (*errp) { +if (v->vhostfd <0 ) {return ; } v->vdev_id =vhost_vdpa_device_get_u32 (v->vhostfd,VHOST_VDPA_GET_DEVICE_ID , errp); -if (*errp) { +if (v->vdev_id <0 ) { goto out; } max_queue_size =vhost_vdpa_device_get_u32 (v->vhostfd,VHOST_VDPA_GET_VRING_NUM , errp); -if (*errp) { +if (max_queue_size <0 ) { goto out; }@@ -89,7 +90,7 @@ static void vhost_vdpa_device_realize(DeviceState *dev, Error **errp) v->num_queues =vhost_vdpa_device_get_u32 (v->vhostfd,VHOST_VDPA_GET_VQS_COUNT , errp); -if (*errp) { +if (v->num_queues <0 ) { goto out; }@@ -127,7 +128,7 @@ static void vhost_vdpa_device_realize(DeviceState *dev, Error **errp) v->config_size =vhost_vdpa_device_get_u32 (v->vhostfd,VHOST_VDPA_GET_CONFIG_SIZE , errp); -if (*errp) { +if (v->config_size <0 ) { goto vhost_cleanup; } --2.34.1
Re: [PATCH] hw/virtio/vdpa-dev: Check returned value instead of dereferencing @errp
Quoted 47 lines · Eugenio Perez Martin
Date: Mon, 15 Jul 2024 23:01:08 +0200
From: Eugenio Perez Martin <[email protected]>
Subject: Re: [PATCH] hw/virtio/vdpa-dev: Check returned value instead of
dereferencing @errpQuoted 41 lines · Zhao Liu
As the comment in qapi/error, dereferencing @errp requires
ERRP_GUARD():* = Why, when and how to use
ERRP_GUARD()=
*
* WithoutERRP_GUARD(), use of the @errp parameter is restricted:
* - It must not be dereferenced, because it may be null.
...
*ERRP_GUARD()lifts these restrictions.
*
* To useERRP_GUARD(), add it right at the beginning of the function.
* @errp can then be used without worrying about the argument being
* NULL or&error_fatal.
*
* Using it when it's not needed is safe, but please avoid cluttering
* the source with useless code.Though
vhost_vdpa_device_realize()is called atDeviceClass.realize()context and won't get NULL @errp, it's still better to follow the requirement to add theERRP_GUARD().But
qemu_open()and vhost_vdpa_device_get_u32()'s return values can distinguish between successful and unsuccessful calls, so check the return values directly without dereferencing @errp, which eliminates the need ofERRP_GUARD().Cc "Michael S. Tsirkin" <[email protected]>Cc "Eugenio Pérez" <[email protected]>Cc Jason Wang <[email protected]>Signed-off-by Zhao Liu <[email protected]>--- hw/virtio/vdpa-dev.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)hw/virtio/vdpa-dev.c +0
-0@@ -50,6 +50,7 @@ vhost_vdpa_device_get_u32(int fd, unsigned long int cmd, Error **errp)
Quoted 7 lines
hw/virtio/vdpa-dev.c vhost_vdpa_device_get_u32(int fd, unsigned long int cmd, Error **errp) · line 53
Quoted 3 lines
hw/virtio/vdpa-dev.c +1
-0static void vhost_vdpa_device_realize (DeviceState *dev,Error **errp) { +ERRP_GUARD ();Good catch, thank you! But removing the err dereferencing eliminates the need for
ERRP_GUARD(), doesn't it?
Thanks Eugenio! You're right and I forgot to delete it. I'll post a new version.
Eugenio Perez Martin
Acked-byRe: [PATCH] hw/virtio/vdpa-dev: Check returned value instead of dereferencing @errp
Quoted 57 lines · Zhao Liu
Quoted 47 lines · Eugenio Perez Martin
Date: Mon, 15 Jul 2024 23:01:08 +0200
From: Eugenio Perez Martin <[email protected]>
Subject: Re: [PATCH] hw/virtio/vdpa-dev: Check returned value instead of
dereferencing @errpQuoted 41 lines · Zhao Liu
As the comment in qapi/error, dereferencing @errp requires
ERRP_GUARD():* = Why, when and how to use
ERRP_GUARD()=
*
* WithoutERRP_GUARD(), use of the @errp parameter is restricted:
* - It must not be dereferenced, because it may be null.
...
*ERRP_GUARD()lifts these restrictions.
*
* To useERRP_GUARD(), add it right at the beginning of the function.
* @errp can then be used without worrying about the argument being
* NULL or&error_fatal.
*
* Using it when it's not needed is safe, but please avoid cluttering
* the source with useless code.Though
vhost_vdpa_device_realize()is called atDeviceClass.realize()context and won't get NULL @errp, it's still better to follow the requirement to add theERRP_GUARD().But
qemu_open()and vhost_vdpa_device_get_u32()'s return values can distinguish between successful and unsuccessful calls, so check the return values directly without dereferencing @errp, which eliminates the need ofERRP_GUARD().Cc "Michael S. Tsirkin" <[email protected]>Cc "Eugenio Pérez" <[email protected]>Cc Jason Wang <[email protected]>Signed-off-by Zhao Liu <[email protected]>--- hw/virtio/vdpa-dev.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)hw/virtio/vdpa-dev.c +0
-0@@ -50,6 +50,7 @@ vhost_vdpa_device_get_u32(int fd, unsigned long int cmd, Error **errp)Quoted 7 lines
hw/virtio/vdpa-dev.c vhost_vdpa_device_get_u32(int fd, unsigned long int cmd, Error **errp) · line 53
Quoted 3 lines
hw/virtio/vdpa-dev.c +1
-0static void vhost_vdpa_device_realize (DeviceState *dev,Error **errp) { +ERRP_GUARD ();Good catch, thank you! But removing the err dereferencing eliminates the need for
ERRP_GUARD(), doesn't it?
Quoted 4 lines
Thanks Eugenio! You're right and I forgot to delete it. I'll post a new version.
Good! With that removed,
Thanks!
PATCH 1/1 qga/commands-posix: Make ga_wait_child() return boolean
In reply to Zhao LiuAs the comment in qapi/error, dereferencing @errp requires ERRP_GUARD():
* = Why, when and how to use ERRP_GUARD() =
*
* Without ERRP_GUARD(), use of the @errp parameter is restricted:
* - It must not be dereferenced, because it may be null.
...
* ERRP_GUARD() lifts these restrictions.
*
* To use ERRP_GUARD(), add it right at the beginning of the function.
* @errp can then be used without worrying about the argument being
* NULL or &error_fatal.
*
* Using it when it's not needed is safe, but please avoid cluttering
* the source with useless code.
Though currently ga_run_command() only gets &local_err instead of NULL @errp, it's still better to follow the requirement to add the ERRP_GUARD().
But as error.h suggested, the best practice for callee is to return something to indicate success / failure.
So make ga_wait_child() return boolean and check the returned boolean in ga_run_command() instead of dereferencing @errp, which eliminates the need of ERRP_GUARD().
--- qga/commands-posix.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
qga/commands-posix.c +4 -4
@@ -59,7 +59,7 @@#endif #endif -static void ga_wait_child (pid_t pid,int *status,Error **errp) +static bool ga_wait_child (pid_t pid,int *status,Error **errp) {pid_t rpid;
@@ -70,10 +70,11 @@ static void ga_wait_child(pid_t pid, int *status, Error **errp)if (rpid ==-1 ) {error_setg_errno (errp, errno,"failed to wait for child (pid: %d)" , pid); -return ; +return false; }g_assert (rpid == pid); +return true; }static ssize_t ga_pipe_read_str (int fd[2 ],char **str)
@@ -178,8 +179,7 @@ static int ga_run_command(const char *argv[], const char *in_str, goto out; } -ga_wait_child (pid, &status, errp); -if (*errp) { +if (!ga_wait_child (pid, &status, errp)) { goto out; }
Signature · 1 line
2.34.1
Re: [PATCH] qga/commands-posix: Make ga_wait_child() return boolean
Quoted 21 lines · Zhao Liu
As the comment in qapi/error, dereferencing @errp requires
ERRP_GUARD():* = Why, when and how to use
ERRP_GUARD()=
*
* WithoutERRP_GUARD(), use of the @errp parameter is restricted:
* - It must not be dereferenced, because it may be null.
...
*ERRP_GUARD()lifts these restrictions.
*
* To useERRP_GUARD(), add it right at the beginning of the function.
* @errp can then be used without worrying about the argument being
* NULL or&error_fatal.
*
* Using it when it's not needed is safe, but please avoid cluttering
* the source with useless code.Though currently
ga_run_command()only gets&local_errinstead of NULL @errp, it's still better to follow the requirement to add theERRP_GUARD().
Quoted 6 lines
But as
error.hsuggested, the best practice for callee is to return something to indicate success / failure.So make
ga_wait_child()return boolean and check the returned boolean inga_run_command()instead of dereferencing @errp, which eliminates the need ofERRP_GUARD().
I'd avoid mentioning ERRP_GUARD and just describe:
Make ga_wait_child() return boolean and check the returned boolean in ga_run_command() instead of dereferencing @errp.
For the code change:
Quoted 43 lines
Cc Michael Roth <[email protected]>Cc Konstantin Kostiuk <[email protected]>Signed-off-by Zhao Liu <[email protected]>--- qga/commands-posix.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)qga/commands-posix.c +4
-4@@ -59,7 +59,7 @@#endif #endif -static void ga_wait_child (pid_t pid,int *status,Error **errp) +static bool ga_wait_child (pid_t pid,int *status,Error **errp) {pid_t rpid;@@ -70,10 +70,11 @@ static void ga_wait_child(pid_t pid, int *status, Error **errp)if (rpid ==-1 ) {error_setg_errno (errp, errno,"failed to wait for child (pid: %d)" , pid); -return ; +return false; }g_assert (rpid == pid); +return true; }static ssize_t ga_pipe_read_str (int fd[2 ],char **str)@@ -178,8 +179,7 @@ static int ga_run_command(const char *argv[], const char *in_str, goto out; } -ga_wait_child (pid, &status, errp); -if (*errp) { +if (!ga_wait_child (pid, &status, errp)) { goto out; }
Re: [PATCH] qga/commands-posix: Make ga_wait_child() return boolean
Quoted 33 lines · Philippe Mathieu-Daudé
Date: Mon, 15 Jul 2024 11:59:29 +0200
From: Philippe Mathieu-Daudé <[email protected]>
Subject: Re: [PATCH] qga/commands-posix: Makega_wait_child()return booleanQuoted 21 lines · Zhao Liu
As the comment in qapi/error, dereferencing @errp requires
ERRP_GUARD():* = Why, when and how to use
ERRP_GUARD()=
*
* WithoutERRP_GUARD(), use of the @errp parameter is restricted:
* - It must not be dereferenced, because it may be null.
...
*ERRP_GUARD()lifts these restrictions.
*
* To useERRP_GUARD(), add it right at the beginning of the function.
* @errp can then be used without worrying about the argument being
* NULL or&error_fatal.
*
* Using it when it's not needed is safe, but please avoid cluttering
* the source with useless code.Though currently
ga_run_command()only gets&local_errinstead of NULL @errp, it's still better to follow the requirement to add theERRP_GUARD().Quoted 6 lines
But as
error.hsuggested, the best practice for callee is to return something to indicate success / failure.So make
ga_wait_child()return boolean and check the returned boolean inga_run_command()instead of dereferencing @errp, which eliminates the need ofERRP_GUARD().
Quoted 8 lines
I'd avoid mentioning
ERRP_GUARDand just describe:Make
ga_wait_child()return boolean and check the returned boolean inga_run_command()instead of dereferencing @errp.For the code change:
Reviewed-by Philippe Mathieu-Daudé <[email protected]>
Many thanks for your words and review!
Will use your words in the next version.
Hi Philippe,
If possible, can this one catch a ride with your PULL too?
Many thanks!
Zhao
Quoted 54 lines · Zhao Liu
Date: Mon, 15 Jul 2024 17:59:37 +0800
From: Zhao Liu <[email protected]>
Subject: [PATCH] hw/nubus/nubus-virtio-mmio: Fix missingERRP_GUARD()in
nubus_virtio_mmio_realize()
X-Mailer: git-send-email 2.34.1As the comment in qapi/error, dereferencing @errp requires
ERRP_GUARD():* = Why, when and how to use
ERRP_GUARD()=
*
* WithoutERRP_GUARD(), use of the @errp parameter is restricted:
* - It must not be dereferenced, because it may be null.
...
*ERRP_GUARD()lifts these restrictions.
*
* To useERRP_GUARD(), add it right at the beginning of the function.
* @errp can then be used without worrying about the argument being
* NULL or&error_fatal.
*
* Using it when it's not needed is safe, but please avoid cluttering
* the source with useless code.But in
nubus_virtio_mmio_realize(), @errp is dereferenced withoutERRP_GUARD().Although
nubus_virtio_mmio_realize()- as aDeviceClass.realize()method - doesn't get the NULL @errp parameter, it hasn't triggered the bug that dereferencing the NULL @errp. It's still necessary to follow the requirement of @errp, so add missingERRP_GUARD()innubus_virtio_mmio_realize().Cc Laurent Vivier <[email protected]>Cc Philippe Mathieu-Daudé <[email protected]>Signed-off-by Zhao Liu <[email protected]>--- hw/nubus/nubus-virtio-mmio.c | 1 + 1 file changed, 1 insertion(+)hw/nubus/nubus-virtio-mmio.c +1
-0@@ -23,6 +23,7 @@ static void nubus_virtio_mmio_set_input_irq(void *opaque, int n, int level)static void nubus_virtio_mmio_realize (DeviceState *dev,Error **errp) { +ERRP_GUARD ();NubusVirtioMMIODeviceClass *nvmdc =NUBUS_VIRTIO_MMIO_GET_CLASS (dev);NubusVirtioMMIO *s =NUBUS_VIRTIO_MMIO (dev);NubusDevice *nd =NUBUS_DEVICE (dev);Signature · 1 line
2.34.1
+Markus/Eric for review
Quoted 62 lines · Zhao Liu
Hi Philippe,
If possible, can this one catch a ride with your PULL too?
Many thanks!
ZhaoQuoted 54 lines · Zhao Liu
Date: Mon, 15 Jul 2024 17:59:37 +0800
From: Zhao Liu <[email protected]>
Subject: [PATCH] hw/nubus/nubus-virtio-mmio: Fix missingERRP_GUARD()in
nubus_virtio_mmio_realize()
X-Mailer: git-send-email 2.34.1As the comment in qapi/error, dereferencing @errp requires
ERRP_GUARD():* = Why, when and how to use
ERRP_GUARD()=
*
* WithoutERRP_GUARD(), use of the @errp parameter is restricted:
* - It must not be dereferenced, because it may be null.
...
*ERRP_GUARD()lifts these restrictions.
*
* To useERRP_GUARD(), add it right at the beginning of the function.
* @errp can then be used without worrying about the argument being
* NULL or&error_fatal.
*
* Using it when it's not needed is safe, but please avoid cluttering
* the source with useless code.But in
nubus_virtio_mmio_realize(), @errp is dereferenced withoutERRP_GUARD().Although
nubus_virtio_mmio_realize()- as aDeviceClass.realize()method - doesn't get the NULL @errp parameter, it hasn't triggered the bug that dereferencing the NULL @errp. It's still necessary to follow the requirement of @errp, so add missingERRP_GUARD()innubus_virtio_mmio_realize().Cc Laurent Vivier <[email protected]>Cc Philippe Mathieu-Daudé <[email protected]>Signed-off-by Zhao Liu <[email protected]>--- hw/nubus/nubus-virtio-mmio.c | 1 + 1 file changed, 1 insertion(+)hw/nubus/nubus-virtio-mmio.c +1
-0@@ -23,6 +23,7 @@ static void nubus_virtio_mmio_set_input_irq(void *opaque, int n, int level)static void nubus_virtio_mmio_realize (DeviceState *dev,Error **errp) { +ERRP_GUARD ();NubusVirtioMMIODeviceClass *nvmdc =NUBUS_VIRTIO_MMIO_GET_CLASS (dev);NubusVirtioMMIO *s =NUBUS_VIRTIO_MMIO (dev);NubusDevice *nd =NUBUS_DEVICE (dev);Signature · 1 line
2.34.1
Quoted 1 line · Zhao Liu
As the comment in qapi/error, dereferencing @errp requires
Suggest "According to the comment in qapi/error.h".
Quoted 16 lines
ERRP_GUARD():* = Why, when and how to use
ERRP_GUARD()=
*
* WithoutERRP_GUARD(), use of the @errp parameter is restricted:
* - It must not be dereferenced, because it may be null.
...
*ERRP_GUARD()lifts these restrictions.
*
* To useERRP_GUARD(), add it right at the beginning of the function.
* @errp can then be used without worrying about the argument being
* NULL or&error_fatal.
*
* Using it when it's not needed is safe, but please avoid cluttering
* the source with useless code.
Quoted 2 lines
But in
nubus_virtio_mmio_realize(), @errp is dereferenced withoutERRP_GUARD().
Suggest to scratch "But".
Quoted 5 lines
Although
nubus_virtio_mmio_realize()- as aDeviceClass.realize()method - doesn't get the NULL @errp parameter, it hasn't triggered the bug that dereferencing the NULL @errp. It's still necessary to follow the requirement of @errp, so add missingERRP_GUARD()innubus_virtio_mmio_realize().
Suggest
Although nubus_virtio_mmio_realize() - as a DeviceClass.realize() method - is never passed a null @errp argument, it should follow the rules on @errp usage. Add the ERRP_GUARD() there.
Quoted 12 lines
Cc Laurent Vivier <[email protected]>Cc Philippe Mathieu-Daudé <[email protected]>Signed-off-by Zhao Liu <[email protected]>--- hw/nubus/nubus-virtio-mmio.c | 1 + 1 file changed, 1 insertion(+)hw/nubus/nubus-virtio-mmio.c +0
-0
hw/nubus/nubus-virtio-mmio.c static void nubus_virtio_mmio_set_input_irq(void *opaque, int n, int level) · line 29
Quoted 7 lines
hw/nubus/nubus-virtio-mmio.c +1
-0@@ -23,6 +23,7 @@ static void nubus_virtio_mmio_set_input_irq(void *opaque, int n, int level)static void nubus_virtio_mmio_realize (DeviceState *dev,Error **errp) { +ERRP_GUARD ();NubusVirtioMMIODeviceClass *nvmdc =NUBUS_VIRTIO_MMIO_GET_CLASS (dev);NubusVirtioMMIO *s =NUBUS_VIRTIO_MMIO (dev);NubusDevice *nd =NUBUS_DEVICE (dev);
SysBusDevice *sbd;
int i, offset;
nvmdc->parent_realize(dev, errp);Here's the dereference:
if (*errp) {
return;
}Thanks!
Hi Markus,
Quoted 10 lines · Markus Armbruster
Date: Tue, 23 Jul 2024 12:21:17 +0200
From: Markus Armbruster <[email protected]>
Subject: Re: [PATCH] hw/nubus/nubus-virtio-mmio: Fix missingERRP_GUARD()
innubus_virtio_mmio_realize()Quoted 1 line · Zhao Liu
As the comment in qapi/error, dereferencing @errp requires
Suggest "According to the comment in
qapi/error.h".
Thanks! Good words.
Quoted 16 lines
Quoted 16 lines
ERRP_GUARD():* = Why, when and how to use
ERRP_GUARD()=
*
* WithoutERRP_GUARD(), use of the @errp parameter is restricted:
* - It must not be dereferenced, because it may be null.
...
*ERRP_GUARD()lifts these restrictions.
*
* To useERRP_GUARD(), add it right at the beginning of the function.
* @errp can then be used without worrying about the argument being
* NULL or&error_fatal.
*
* Using it when it's not needed is safe, but please avoid cluttering
* the source with useless code.
Quoted 4 lines
Quoted 2 lines
But in
nubus_virtio_mmio_realize(), @errp is dereferenced withoutERRP_GUARD().Suggest to scratch "But".
No problem, will do.
Quoted 11 lines
Quoted 5 lines
Although
nubus_virtio_mmio_realize()- as aDeviceClass.realize()method - doesn't get the NULL @errp parameter, it hasn't triggered the bug that dereferencing the NULL @errp. It's still necessary to follow the requirement of @errp, so add missingERRP_GUARD()innubus_virtio_mmio_realize().Suggest
Although
nubus_virtio_mmio_realize()- as aDeviceClass.realize()method - is never passed a null @errp argument, it should follow the rules on @errp usage. Add theERRP_GUARD()there.
Thanks for the text! It sounds much more authentic!
Quoted 24 lines
Quoted 12 lines
Cc Laurent Vivier <[email protected]>Cc Philippe Mathieu-Daudé <[email protected]>Signed-off-by Zhao Liu <[email protected]>--- hw/nubus/nubus-virtio-mmio.c | 1 + 1 file changed, 1 insertion(+)hw/nubus/nubus-virtio-mmio.c +0
-0hw/nubus/nubus-virtio-mmio.c static void nubus_virtio_mmio_set_input_irq(void *opaque, int n, int level) · line 29
Quoted 7 lines
hw/nubus/nubus-virtio-mmio.c +1
-0@@ -23,6 +23,7 @@ static void nubus_virtio_mmio_set_input_irq(void *opaque, int n, int level)static void nubus_virtio_mmio_realize (DeviceState *dev,Error **errp) { +ERRP_GUARD ();NubusVirtioMMIODeviceClass *nvmdc =NUBUS_VIRTIO_MMIO_GET_CLASS (dev);NubusVirtioMMIO *s =NUBUS_VIRTIO_MMIO (dev);NubusDevice *nd =NUBUS_DEVICE (dev);SysBusDevice *sbd; int i, offset; nvmdc->parent_realize(dev, errp);
Quoted 8 lines
Here's the dereference:
if (*errp) { return; }Reviewed-by Markus Armbruster <[email protected]>
Thanks! Will refresh a v2 soon.
Regards,
Zhao