From: Thomas Huth <thuth@redhat.com>
To: Li Qiang <liq3ea@163.com>,
lvivier@redhat.com, pbonzini@redhat.com, philmd@redhat.com,
lersek@redhat.com, kraxel@redhat.com
Cc: qemu-devel@nongnu.org, liq3ea@gmail.com
Subject: Re: [Qemu-devel] [PATCH 1/2] tests: fw_cfg: add a function to get the fw_cfg file
Date: Fri, 19 Apr 2019 09:03:58 +0200 [thread overview]
Message-ID: <27424fa0-0fed-c292-2321-069d725fd57d@redhat.com> (raw)
In-Reply-To: <20190319023030.947-2-liq3ea@163.com>
On 19/03/2019 03.30, Li Qiang wrote:
> This is useful to write qtest about fw_cfg file entry.
>
> Signed-off-by: Li Qiang <liq3ea@163.com>
> ---
> tests/libqos/fw_cfg.c | 45 +++++++++++++++++++++++++++++++++++++++++++
> tests/libqos/fw_cfg.h | 2 ++
> 2 files changed, 47 insertions(+)
>
> diff --git a/tests/libqos/fw_cfg.c b/tests/libqos/fw_cfg.c
> index d0889d1e22..2df33df859 100644
> --- a/tests/libqos/fw_cfg.c
> +++ b/tests/libqos/fw_cfg.c
> @@ -16,12 +16,57 @@
> #include "libqos/fw_cfg.h"
> #include "libqtest.h"
> #include "qemu/bswap.h"
> +#include "hw/nvram/fw_cfg.h"
>
> void qfw_cfg_select(QFWCFG *fw_cfg, uint16_t key)
> {
> fw_cfg->select(fw_cfg, key);
> }
>
> +/*
> + * The caller need check the return value. When the return value is
> + * nonzero, it means that some bytes have been transferred.
> + *
> + * If the fw_cfg file in question is smaller than the allocated & passed-in
> + * buffer, then the buffer has been populated only in part.
> + *
> + * If the fw_cfg file in question is larger than the passed-in
> + * buffer, then the return value explains how much room would have been
> + * necessary in total. And, while the caller's buffer has been fully
> + * populated, it has received only a starting slice of the fw_cfg file.
> + */
> +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;
> +
> + 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_malloc0(dsize);
> + qfw_cfg_get(fw_cfg, FW_CFG_FILE_DIR, filesbuf, dsize);
If I get the code right, qfw_cfg_get() fills the whole buffer here...
in that case, g_malloc() should be sufficient, so you don't need
g_malloc0() here.
Thomas
WARNING: multiple messages have this Message-ID (diff)
From: Thomas Huth <thuth@redhat.com>
To: Li Qiang <liq3ea@163.com>,
lvivier@redhat.com, pbonzini@redhat.com, philmd@redhat.com,
lersek@redhat.com, kraxel@redhat.com
Cc: liq3ea@gmail.com, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 1/2] tests: fw_cfg: add a function to get the fw_cfg file
Date: Fri, 19 Apr 2019 09:03:58 +0200 [thread overview]
Message-ID: <27424fa0-0fed-c292-2321-069d725fd57d@redhat.com> (raw)
Message-ID: <20190419070358.LwYP2e6qp7nZQk8QRg5OJRuAXagE3PXBboWAlidmMxY@z> (raw)
In-Reply-To: <20190319023030.947-2-liq3ea@163.com>
On 19/03/2019 03.30, Li Qiang wrote:
> This is useful to write qtest about fw_cfg file entry.
>
> Signed-off-by: Li Qiang <liq3ea@163.com>
> ---
> tests/libqos/fw_cfg.c | 45 +++++++++++++++++++++++++++++++++++++++++++
> tests/libqos/fw_cfg.h | 2 ++
> 2 files changed, 47 insertions(+)
>
> diff --git a/tests/libqos/fw_cfg.c b/tests/libqos/fw_cfg.c
> index d0889d1e22..2df33df859 100644
> --- a/tests/libqos/fw_cfg.c
> +++ b/tests/libqos/fw_cfg.c
> @@ -16,12 +16,57 @@
> #include "libqos/fw_cfg.h"
> #include "libqtest.h"
> #include "qemu/bswap.h"
> +#include "hw/nvram/fw_cfg.h"
>
> void qfw_cfg_select(QFWCFG *fw_cfg, uint16_t key)
> {
> fw_cfg->select(fw_cfg, key);
> }
>
> +/*
> + * The caller need check the return value. When the return value is
> + * nonzero, it means that some bytes have been transferred.
> + *
> + * If the fw_cfg file in question is smaller than the allocated & passed-in
> + * buffer, then the buffer has been populated only in part.
> + *
> + * If the fw_cfg file in question is larger than the passed-in
> + * buffer, then the return value explains how much room would have been
> + * necessary in total. And, while the caller's buffer has been fully
> + * populated, it has received only a starting slice of the fw_cfg file.
> + */
> +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;
> +
> + 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_malloc0(dsize);
> + qfw_cfg_get(fw_cfg, FW_CFG_FILE_DIR, filesbuf, dsize);
If I get the code right, qfw_cfg_get() fills the whole buffer here...
in that case, g_malloc() should be sufficient, so you don't need
g_malloc0() here.
Thomas
next prev parent reply other threads:[~2019-04-19 7:04 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20190319023030.947-1-liq3ea@163.com>
[not found] ` <4359b7c8.12ac0.169c3e7ba5d.Coremail.liq3ea@163.com>
2019-04-05 15:47 ` [Qemu-devel] [PATCH 0/2] tests: fw_cfg: add reboot-timeout test case Philippe Mathieu-Daudé
2019-04-05 15:47 ` Philippe Mathieu-Daudé
[not found] ` <20190319023030.947-3-liq3ea@163.com>
2019-04-18 21:01 ` [Qemu-devel] [PATCH 2/2] tests: fw_cfg: add reboot_timeout " Philippe Mathieu-Daudé
2019-04-18 21:01 ` Philippe Mathieu-Daudé
2019-04-19 2:23 ` Li Qiang
2019-04-19 2:23 ` Li Qiang
2019-04-20 10:07 ` Li Qiang
2019-04-20 10:07 ` Li Qiang
[not found] ` <20190319023030.947-2-liq3ea@163.com>
2019-04-19 7:03 ` Thomas Huth [this message]
2019-04-19 7:03 ` [Qemu-devel] [PATCH 1/2] tests: fw_cfg: add a function to get the fw_cfg file Thomas Huth
2019-04-21 18:48 ` Philippe Mathieu-Daudé
2019-04-21 18:48 ` Philippe Mathieu-Daudé
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=27424fa0-0fed-c292-2321-069d725fd57d@redhat.com \
--to=thuth@redhat.com \
--cc=kraxel@redhat.com \
--cc=lersek@redhat.com \
--cc=liq3ea@163.com \
--cc=liq3ea@gmail.com \
--cc=lvivier@redhat.com \
--cc=pbonzini@redhat.com \
--cc=philmd@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).