[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v2 2/8] virtio: enhance virtio_error messages
From: |
Ladi Prosek |
Subject: |
Re: [Qemu-devel] [PATCH v2 2/8] virtio: enhance virtio_error messages |
Date: |
Thu, 13 Jul 2017 15:58:34 +0200 |
On Thu, Jul 13, 2017 at 3:40 PM, Stefan Hajnoczi <address@hidden> wrote:
> On Thu, Jul 13, 2017 at 01:02:31PM +0200, Ladi Prosek wrote:
>> +static const char *virtio_get_device_id(VirtIODevice *vdev)
>> +{
>> + DeviceState *qdev = DEVICE(vdev);
>> + while (qdev) {
>> + /* Find the proxy object corresponding to the vdev backend */
>> + Object *prop = object_property_get_link(OBJECT(qdev),
>> + VIRTIO_PROP_BACKEND, NULL);
>> + if (prop == OBJECT(vdev)) {
>> + return qdev->id;
>> + }
>> + qdev = qdev->parent_bus->parent;
>> + }
>> + return NULL;
>> +}
>> +
>> void GCC_FMT_ATTR(2, 3) virtio_error(VirtIODevice *vdev, const char *fmt,
>> ...)
>> {
>> va_list ap;
>>
>> + error_report_nolf("%s (id=%s): ", vdev->name,
>> virtio_get_device_id(vdev));
>
> virtio_get_device_id() can return NULL. POSIX does not guarantee that
> the printf(3) family functions handle "%s", NULL safely. glibc prints
> "(null)" but other libc implementations crash (e.g. Solaris).
>
> http://pubs.opengroup.org/onlinepubs/9699919799/functions/fprintf.html
>
> Should the return NULL above have g_assert_not_reached()? That would
> communicate the assumption that we never reach return NULL and it might
> silence static checkers like Coverity but I'm not sure.
virtio_get_device_id is expected to return NULL if the device has no
id assigned and I kind of liked the "(null)" output. I just failed to
realize that not all printf's will handle it. I'll definitely fix
this, thanks!
- [Qemu-devel] [PATCH v2 0/8] virtio: enhance virtio_error messages, Ladi Prosek, 2017/07/13
- [Qemu-devel] [PATCH v2 1/8] qemu-error: introduce error_report_nolf, Ladi Prosek, 2017/07/13
- [Qemu-devel] [PATCH v2 2/8] virtio: enhance virtio_error messages, Ladi Prosek, 2017/07/13
- [Qemu-devel] [PATCH v2 3/8] virtio: introduce virtqueue_error, Ladi Prosek, 2017/07/13
- [Qemu-devel] [PATCH v2 4/8] virtio-9p: use virtqueue_error for errors with queue context, Ladi Prosek, 2017/07/13
- [Qemu-devel] [PATCH v2 5/8] virtio-blk: use virtqueue_error for errors with queue context, Ladi Prosek, 2017/07/13