Commit a5cf8262 authored by Jim Meyering's avatar Jim Meyering Committed by Anthony Liguori
Browse files

scsi, pci, qdev, isa-bus, sysbus: don't let *_get_fw_dev_path return NULL



Use g_strdup rather than strdup, because the sole caller
(qdev_get_fw_dev_path_helper) assumes it gets non-NULL, and dereferences
it.  Besides, in that caller, the allocated buffer is already freed with
g_free, so it's better to allocate with a matching g_strdup.

In one case, (scsi-bus.c) it was trivial, so I replaced an snprintf+
g_strdup combination with an equivalent g_strdup_printf use.

Signed-off-by: default avatarJim Meyering <meyering@redhat.com>
Signed-off-by: default avatarAnthony Liguori <aliguori@us.ibm.com>
parent a14c7492
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -60,7 +60,7 @@ static char *idebus_get_fw_dev_path(DeviceState *dev)
    snprintf(path, sizeof(path), "%s@%d", qdev_fw_name(dev),
             ((IDEBus*)dev->parent_bus)->bus_id);

    return strdup(path);
    return g_strdup(path);
}

static int ide_qdev_init(DeviceState *qdev)
+1 −1
Original line number Diff line number Diff line
@@ -236,7 +236,7 @@ static char *isabus_get_fw_dev_path(DeviceState *dev)
        snprintf(path + off, sizeof(path) - off, "@%04x", d->ioport_id);
    }

    return strdup(path);
    return g_strdup(path);
}

MemoryRegion *isa_address_space(ISADevice *dev)
+1 −1
Original line number Diff line number Diff line
@@ -1962,7 +1962,7 @@ static char *pcibus_get_fw_dev_path(DeviceState *dev)
                   PCI_SLOT(d->devfn));
    if (PCI_FUNC(d->devfn))
        snprintf(path + off, sizeof(path) + off, ",%x", PCI_FUNC(d->devfn));
    return strdup(path);
    return g_strdup(path);
}

static char *pcibus_get_dev_path(DeviceState *dev)
+1 −1
Original line number Diff line number Diff line
@@ -520,7 +520,7 @@ char* qdev_get_fw_dev_path(DeviceState *dev)

    path[l-1] = '\0';

    return strdup(path);
    return g_strdup(path);
}

char *qdev_get_dev_path(DeviceState *dev)
+2 −6
Original line number Diff line number Diff line
@@ -1723,12 +1723,8 @@ static char *scsibus_get_dev_path(DeviceState *dev)
static char *scsibus_get_fw_dev_path(DeviceState *dev)
{
    SCSIDevice *d = SCSI_DEVICE(dev);
    char path[100];

    snprintf(path, sizeof(path), "channel@%x/%s@%x,%x", d->channel,
    return g_strdup_printf("channel@%x/%s@%x,%x", d->channel,
                           qdev_fw_name(dev), d->id, d->lun);

    return strdup(path);
}

SCSIDevice *scsi_device_find(SCSIBus *bus, int channel, int id, int lun)
Loading