qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 1/2] tests: fw_cfg: add a function to get the fw


From: Philippe Mathieu-Daudé
Subject: Re: [Qemu-devel] [PATCH 1/2] tests: fw_cfg: add a function to get the fw_cfg file
Date: Sun, 21 Apr 2019 20:48:03 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1

Hi Thomas,

On 4/19/19 9:03 AM, Thomas Huth wrote:
> 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 <address@hidden>
>> ---
>>  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.

Correct.

Apparently Li did address your suggestion in his next iteration of this
patch (same subject, Message-Id: <address@hidden>).

Thanks,

Phil.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]