Message ID | 20250110104619.267564-2-anisinha@redhat.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | tests/qtest/libqos: add DMA support for writing and reading fw_cfg files | expand |
Ani Sinha <anisinha@redhat.com> writes: > fw-cfg file directory iteration code can be used by other functions that may > want to implement fw-cfg file operations. Refactor it into a smaller helper > so that it can be reused. > > No functional change. > > Signed-off-by: Ani Sinha <anisinha@redhat.com> Reviewed-by: Fabiano Rosas <farosas@suse.de>
On 10/1/25 11:46, Ani Sinha wrote: > fw-cfg file directory iteration code can be used by other functions that may > want to implement fw-cfg file operations. Refactor it into a smaller helper > so that it can be reused. > > No functional change. > > Signed-off-by: Ani Sinha <anisinha@redhat.com> > --- > tests/qtest/libqos/fw_cfg.c | 62 ++++++++++++++++++++++++------------- > 1 file changed, 40 insertions(+), 22 deletions(-) > > diff --git a/tests/qtest/libqos/fw_cfg.c b/tests/qtest/libqos/fw_cfg.c > index 89f053ccac..b178d0b1b8 100644 > --- a/tests/qtest/libqos/fw_cfg.c > +++ b/tests/qtest/libqos/fw_cfg.c > @@ -60,6 +60,38 @@ static void mm_fw_cfg_select(QFWCFG *fw_cfg, uint16_t key) > qtest_writew(fw_cfg->qts, fw_cfg->base, key); > } > > +static bool > +find_pdir_entry(QFWCFG *fw_cfg, const char *filename, > + uint16_t *sel, uint32_t *size) Please use QEMU coding style.
On Fri, Jan 10, 2025 at 9:48 PM Philippe Mathieu-Daudé <philmd@linaro.org> wrote: > > On 10/1/25 11:46, Ani Sinha wrote: > > fw-cfg file directory iteration code can be used by other functions that may > > want to implement fw-cfg file operations. Refactor it into a smaller helper > > so that it can be reused. > > > > No functional change. > > > > Signed-off-by: Ani Sinha <anisinha@redhat.com> > > --- > > tests/qtest/libqos/fw_cfg.c | 62 ++++++++++++++++++++++++------------- > > 1 file changed, 40 insertions(+), 22 deletions(-) > > > > diff --git a/tests/qtest/libqos/fw_cfg.c b/tests/qtest/libqos/fw_cfg.c > > index 89f053ccac..b178d0b1b8 100644 > > --- a/tests/qtest/libqos/fw_cfg.c > > +++ b/tests/qtest/libqos/fw_cfg.c > > @@ -60,6 +60,38 @@ static void mm_fw_cfg_select(QFWCFG *fw_cfg, uint16_t key) > > qtest_writew(fw_cfg->qts, fw_cfg->base, key); > > } > > > > +static bool > > +find_pdir_entry(QFWCFG *fw_cfg, const char *filename, > > + uint16_t *sel, uint32_t *size) > > Please use QEMU coding style. btw, checkpatch did not catch this. I suggest we also fix checkpatch $ ./scripts/checkpatch.pl patches-v5/* Checking patches-v5/0001-libqos-fw_cfg-refactor-file-directory-iteraton-to-ma.patch... total: 0 errors, 0 warnings, 78 lines checked patches-v5/0001-libqos-fw_cfg-refactor-file-directory-iteraton-to-ma.patch has no obvious style problems and is ready for submission. Checking patches-v5/0002-tests-qtest-libqos-add-DMA-support-for-writing-and-r.patch... total: 0 errors, 0 warnings, 178 lines checked patches-v5/0002-tests-qtest-libqos-add-DMA-support-for-writing-and-r.patch has no obvious style problems and is ready for submission. Checking patches-v5/0003-tests-qtest-vmcoreinfo-add-a-unit-test-to-exercize-b.patch... total: 0 errors, 0 warnings, 111 lines checked patches-v5/0003-tests-qtest-vmcoreinfo-add-a-unit-test-to-exercize-b.patch has no obvious style problems and is ready for submission.
diff --git a/tests/qtest/libqos/fw_cfg.c b/tests/qtest/libqos/fw_cfg.c index 89f053ccac..b178d0b1b8 100644 --- a/tests/qtest/libqos/fw_cfg.c +++ b/tests/qtest/libqos/fw_cfg.c @@ -60,6 +60,38 @@ static void mm_fw_cfg_select(QFWCFG *fw_cfg, uint16_t key) qtest_writew(fw_cfg->qts, fw_cfg->base, key); } +static bool +find_pdir_entry(QFWCFG *fw_cfg, const char *filename, + uint16_t *sel, uint32_t *size) +{ + g_autofree unsigned char *filesbuf = NULL; + uint32_t count; + size_t dsize; + FWCfgFile *pdir_entry; + uint32_t i; + bool found = false; + + *size = 0; + *sel = 0; + + qfw_cfg_get(fw_cfg, FW_CFG_FILE_DIR, &count, sizeof(count)); + count = be32_to_cpu(count); + dsize = sizeof(uint32_t) + count * sizeof(struct fw_cfg_file); + filesbuf = g_malloc(dsize); + qfw_cfg_get(fw_cfg, FW_CFG_FILE_DIR, filesbuf, dsize); + pdir_entry = (FWCfgFile *)(filesbuf + sizeof(uint32_t)); + for (i = 0; i < count; ++i, ++pdir_entry) { + if (!strcmp(pdir_entry->name, filename)) { + *size = be32_to_cpu(pdir_entry->size); + *sel = be16_to_cpu(pdir_entry->select); + found = true; + break; + } + } + + return found; +} + /* * The caller need check the return value. When the return value is * nonzero, it means that some bytes have been transferred. @@ -75,32 +107,18 @@ static void mm_fw_cfg_select(QFWCFG *fw_cfg, uint16_t key) size_t qfw_cfg_get_file(QFWCFG *fw_cfg, const char *filename, void *data, size_t buflen) { - uint32_t count; - uint32_t i; - unsigned char *filesbuf = NULL; - size_t dsize; - FWCfgFile *pdir_entry; size_t filesize = 0; + uint32_t len; + uint16_t sel; - qfw_cfg_get(fw_cfg, FW_CFG_FILE_DIR, &count, sizeof(count)); - count = be32_to_cpu(count); - dsize = sizeof(uint32_t) + count * sizeof(struct fw_cfg_file); - filesbuf = g_malloc(dsize); - qfw_cfg_get(fw_cfg, FW_CFG_FILE_DIR, filesbuf, dsize); - pdir_entry = (FWCfgFile *)(filesbuf + sizeof(uint32_t)); - for (i = 0; i < count; ++i, ++pdir_entry) { - if (!strcmp(pdir_entry->name, filename)) { - uint32_t len = be32_to_cpu(pdir_entry->size); - uint16_t sel = be16_to_cpu(pdir_entry->select); - filesize = len; - if (len > buflen) { - len = buflen; - } - qfw_cfg_get(fw_cfg, sel, data, len); - break; + if (find_pdir_entry(fw_cfg, filename, &sel, &len)) { + filesize = len; + if (len > buflen) { + len = buflen; } + qfw_cfg_get(fw_cfg, sel, data, len); } - g_free(filesbuf); + return filesize; }
fw-cfg file directory iteration code can be used by other functions that may want to implement fw-cfg file operations. Refactor it into a smaller helper so that it can be reused. No functional change. Signed-off-by: Ani Sinha <anisinha@redhat.com> --- tests/qtest/libqos/fw_cfg.c | 62 ++++++++++++++++++++++++------------- 1 file changed, 40 insertions(+), 22 deletions(-)