Skip to content

Commit 42f0680

Browse files
Sam Eidermanjnsnow
Sam Eiderman
authored andcommitted
bootdevice: Refactor get_boot_devices_list
Move device name construction to a separate function. We will reuse this function in the following commit to pass logical CHS parameters through fw_cfg much like we currently pass bootindex. Reviewed-by: Karl Heubaum <[email protected]> Reviewed-by: Arbel Moshe <[email protected]> Reviewed-by: Philippe Mathieu-Daudé <[email protected]> Signed-off-by: Sam Eiderman <[email protected]> Signed-off-by: Sam Eiderman <[email protected]> Tested-by: Philippe Mathieu-Daudé <[email protected]> Signed-off-by: John Snow <[email protected]>
1 parent 71f571a commit 42f0680

File tree

1 file changed

+34
-27
lines changed

1 file changed

+34
-27
lines changed

bootdevice.c

+34-27
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,39 @@ DeviceState *get_boot_device(uint32_t position)
202202
return res;
203203
}
204204

205+
static char *get_boot_device_path(DeviceState *dev, bool ignore_suffixes,
206+
const char *suffix)
207+
{
208+
char *devpath = NULL, *s = NULL, *d, *bootpath;
209+
210+
if (dev) {
211+
devpath = qdev_get_fw_dev_path(dev);
212+
assert(devpath);
213+
}
214+
215+
if (!ignore_suffixes) {
216+
if (dev) {
217+
d = qdev_get_own_fw_dev_path_from_handler(dev->parent_bus, dev);
218+
if (d) {
219+
assert(!suffix);
220+
s = d;
221+
} else {
222+
s = g_strdup(suffix);
223+
}
224+
} else {
225+
s = g_strdup(suffix);
226+
}
227+
}
228+
229+
bootpath = g_strdup_printf("%s%s",
230+
devpath ? devpath : "",
231+
s ? s : "");
232+
g_free(devpath);
233+
g_free(s);
234+
235+
return bootpath;
236+
}
237+
205238
/*
206239
* This function returns null terminated string that consist of new line
207240
* separated device paths.
@@ -218,36 +251,10 @@ char *get_boot_devices_list(size_t *size)
218251
bool ignore_suffixes = mc->ignore_boot_device_suffixes;
219252

220253
QTAILQ_FOREACH(i, &fw_boot_order, link) {
221-
char *devpath = NULL, *suffix = NULL;
222254
char *bootpath;
223-
char *d;
224255
size_t len;
225256

226-
if (i->dev) {
227-
devpath = qdev_get_fw_dev_path(i->dev);
228-
assert(devpath);
229-
}
230-
231-
if (!ignore_suffixes) {
232-
if (i->dev) {
233-
d = qdev_get_own_fw_dev_path_from_handler(i->dev->parent_bus,
234-
i->dev);
235-
if (d) {
236-
assert(!i->suffix);
237-
suffix = d;
238-
} else {
239-
suffix = g_strdup(i->suffix);
240-
}
241-
} else {
242-
suffix = g_strdup(i->suffix);
243-
}
244-
}
245-
246-
bootpath = g_strdup_printf("%s%s",
247-
devpath ? devpath : "",
248-
suffix ? suffix : "");
249-
g_free(devpath);
250-
g_free(suffix);
257+
bootpath = get_boot_device_path(i->dev, ignore_suffixes, i->suffix);
251258

252259
if (total) {
253260
list[total-1] = '\n';

0 commit comments

Comments
 (0)