From: Zhao Liu <zhao1.liu@intel.com>
To: "Michael S. Tsirkin" <mst@redhat.com>
Cc: "Eugenio P�rez" <eperezma@redhat.com>,
qemu-devel@nongnu.org, "Jason Wang" <jasowang@redhat.com>,
"Zhao Liu" <zhao1.liu@intel.com>
Subject: Re: [PATCH v2] hw/virtio/vdpa-dev: Check returned value instead of dereferencing @errp
Date: Sat, 31 Aug 2024 19:18:07 +0800 [thread overview]
Message-ID: <ZtL77yZU/+WThF5A@intel.com> (raw)
In-Reply-To: <20240820065310-mutt-send-email-mst@kernel.org>
Hi Michael,
On Tue, Aug 20, 2024 at 06:55:29AM -0400, Michael S. Tsirkin wrote:
[snip]
> > diff --git a/hw/virtio/vdpa-dev.c b/hw/virtio/vdpa-dev.c
> > index 64b96b226c39..8a1e16fce3de 100644
> > --- a/hw/virtio/vdpa-dev.c
> > +++ b/hw/virtio/vdpa-dev.c
> > @@ -63,19 +63,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;
> > }
>
> vdev_id is unsigned, no idea how is this supposed to work.
>
> >
> > 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;
> > }
> >
> max_queue_size is unsigned, too.
>
> > @@ -89,7 +89,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;
> > }
> >
>
> num_queues is unsigned, too.
Oops, yes. The correct way is to check whether vhost_vdpa_device_get_u32
returns "(uint32_t)-1".
I can add a new macro like this:
#define VDPA_DEVICE_U32_VALUE_NONE ((uint32_t)-1)
Is this okay with you?
Thanks,
Zhao
> > @@ -127,7 +127,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
>
prev parent reply other threads:[~2024-08-31 11:03 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-16 16:26 [PATCH v2] hw/virtio/vdpa-dev: Check returned value instead of dereferencing @errp Zhao Liu
2024-08-20 10:55 ` Michael S. Tsirkin
2024-08-31 11:18 ` Zhao Liu [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZtL77yZU/+WThF5A@intel.com \
--to=zhao1.liu@intel.com \
--cc=eperezma@redhat.com \
--cc=jasowang@redhat.com \
--cc=mst@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).