On 23 July 2012 13:34, Peter Maydell <[email protected]> wrote:
> On 23 July 2012 12:33, Laszlo Ersek <[email protected]> wrote:
>>
>> Signed-off-by: Laszlo Ersek <[email protected]>
>
> I think it would be much nicer to just rewrite qdev_get_fw_dev_path
> so we weren't trying to fill the path into a fixed string buffer
> at all. Here is an entirely untested implementation:
>
> char *qdev_get_fw_dev_path(DeviceState *dev)
> {
> char *path;
> char **strarray;
> int depth = 0;
> DeviceState *d = dev;
> for (d = dev; d && d->parent_bus; d = d->parent_bus->parent) {
> depth++;
> }
> depth++;
> strarray = g_new(char*, depth);
> for (d = dev; d && d->parent_bus; d = d->parent_bus->parent) {
> depth--;
> strarray[depth] = bus_get_fw_dev_path(dev->parent_bus, dev);
"d" not "dev" here and in the line below, obviously. I said it was
untested :-)
> if (!strarray[depth]) {
> strarray[depth] = g_strdup(object_get_typename(OBJECT(dev)));
> }
> }
> strarray[0] = g_strdup("");
> path = g_strjoinv("/", strarray);
> g_strfreev(strarray);
> return path;
> }
-- PMM