fw_cfg patches

Fixes the DEADCODE issue reported by Coverity (CID 1430396).
 
 CI jobs result:
 . https://gitlab.com/philmd/qemu/-/pipelines/169086301
 -----BEGIN PGP SIGNATURE-----
 
 iQIzBAABCAAdFiEE+qvnXhKRciHc/Wuy4+MsLN6twN4FAl8XK24ACgkQ4+MsLN6t
 wN5ZTA/+LqaTmOiflQnoRl9OsfF2tShD0/4DQf0QJ2uz+rEHDgQnTXxVCWU7kLVN
 XTYGy6e0VxAXMcJ4AtEB90M8P+QkmRjazdt6dyAZKU/QRaDl1IebLEeOaYk0SnhT
 riVxY699QblS5AgO8z/Q3+i6l3n+74UyvwhWu3SmmpgfTLaZhvuNmr61HwVCr9sA
 6Gp8jJ7jHUKDP5tbkP66AcDx6Crhn70isJ/f194yk1+ffYiEBNHwTLUOojdHfA0P
 E4TQlAey1w3ZYRK4WPPAscevCwr+uQo3Dtz4eXrFHUOy8dOE5fpa7op2fXKPixaT
 zbPnyBXF2YpFC3JQeRPKGQS2gzvAElFzbR/Pg2dSRAPpx+z4oAjQJjCuqtK+usQF
 ddoSLcPDb37TdYa5p8ZK5fPae3Ga9u3/qEIt9QWLWoMBSyoIXpwf4c3B6kz98lZ4
 cW/kmh4flH/W4wZPVItfbd4LMYqYL+3DGil5TxgwzJcVROENa5jlQOyK7e+Y2WFI
 cFkrUtI6wXb4Z50FD2nQONj1AgrF9jcn0a1lNG+PlkibWx0GmYx4QZz9SE4ws76K
 irwlrxT9QW3CYt5o0D1yV7PwL65wBYMETg4n1IavO0KmKbZrsyCHqgZoVsNyZDCb
 +THEQ3m5PbSm9I50HWr70uYE+6/Sr1Wrn3aqQeM8Y3pdpXViMLc=
 =ZmXl
 -----END PGP SIGNATURE-----

Merge remote-tracking branch 'remotes/philmd-gitlab/tags/fw_cfg-20200721' into staging

fw_cfg patches

Fixes the DEADCODE issue reported by Coverity (CID 1430396).

CI jobs result:
. https://gitlab.com/philmd/qemu/-/pipelines/169086301

# gpg: Signature made Tue 21 Jul 2020 18:52:46 BST
# gpg:                using RSA key FAABE75E12917221DCFD6BB2E3E32C2CDEADC0DE
# gpg: Good signature from "Philippe Mathieu-Daudé (F4BUG) <f4bug@amsat.org>" [full]
# Primary key fingerprint: FAAB E75E 1291 7221 DCFD  6BB2 E3E3 2C2C DEAD C0DE

* remotes/philmd-gitlab/tags/fw_cfg-20200721:
  hw/nvram/fw_cfg: Let fw_cfg_add_from_generator() return boolean value
  hw/nvram/fw_cfg: Simplify fw_cfg_add_from_generator() error propagation

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
Peter Maydell 2020-07-22 12:42:25 +01:00
commit d0cc248164
3 changed files with 14 additions and 13 deletions

View File

@ -1032,10 +1032,9 @@ void *fw_cfg_modify_file(FWCfgState *s, const char *filename,
return NULL;
}
void fw_cfg_add_from_generator(FWCfgState *s, const char *filename,
bool fw_cfg_add_from_generator(FWCfgState *s, const char *filename,
const char *gen_id, Error **errp)
{
ERRP_GUARD();
FWCfgDataGeneratorClass *klass;
GByteArray *array;
Object *obj;
@ -1044,20 +1043,22 @@ void fw_cfg_add_from_generator(FWCfgState *s, const char *filename,
obj = object_resolve_path_component(object_get_objects_root(), gen_id);
if (!obj) {
error_setg(errp, "Cannot find object ID '%s'", gen_id);
return;
return false;
}
if (!object_dynamic_cast(obj, TYPE_FW_CFG_DATA_GENERATOR_INTERFACE)) {
error_setg(errp, "Object ID '%s' is not a '%s' subclass",
gen_id, TYPE_FW_CFG_DATA_GENERATOR_INTERFACE);
return;
return false;
}
klass = FW_CFG_DATA_GENERATOR_GET_CLASS(obj);
array = klass->get_data(obj, errp);
if (*errp) {
return;
if (!array) {
return false;
}
size = array->len;
fw_cfg_add_file(s, filename, g_byte_array_free(array, TRUE), size);
return true;
}
static void fw_cfg_machine_reset(void *opaque)

View File

@ -32,7 +32,9 @@ typedef struct FWCfgDataGeneratorClass {
* @obj: the object implementing this interface
* @errp: pointer to a NULL-initialized error object
*
* Returns: reference to a byte array containing the data.
* Returns: reference to a byte array containing the data on success,
* or NULL on error.
*
* The caller should release the reference when no longer
* required.
*/
@ -302,8 +304,10 @@ void *fw_cfg_modify_file(FWCfgState *s, const char *filename, void *data,
* will be used; also, a new entry will be added to the file directory
* structure residing at key value FW_CFG_FILE_DIR, containing the item name,
* data size, and assigned selector key value.
*
* Returns: %true on success, %false on error.
*/
void fw_cfg_add_from_generator(FWCfgState *s, const char *filename,
bool fw_cfg_add_from_generator(FWCfgState *s, const char *filename,
const char *gen_id, Error **errp);
FWCfgState *fw_cfg_init_io_dma(uint32_t iobase, uint32_t dma_iobase,

View File

@ -2070,11 +2070,7 @@ static int parse_fw_cfg(void *opaque, QemuOpts *opts, Error **errp)
size = strlen(str); /* NUL terminator NOT included in fw_cfg blob */
buf = g_memdup(str, size);
} else if (nonempty_str(gen_id)) {
Error *local_err = NULL;
fw_cfg_add_from_generator(fw_cfg, name, gen_id, errp);
if (local_err) {
error_propagate(errp, local_err);
if (!fw_cfg_add_from_generator(fw_cfg, name, gen_id, errp)) {
return -1;
}
return 0;