Skip to content

Commit d0cc248

Browse files
committed
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) <[email protected]>" [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 <[email protected]>
2 parents 3cbc897 + 0771951 commit d0cc248

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

hw/nvram/fw_cfg.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,10 +1032,9 @@ void *fw_cfg_modify_file(FWCfgState *s, const char *filename,
10321032
return NULL;
10331033
}
10341034

1035-
void fw_cfg_add_from_generator(FWCfgState *s, const char *filename,
1035+
bool fw_cfg_add_from_generator(FWCfgState *s, const char *filename,
10361036
const char *gen_id, Error **errp)
10371037
{
1038-
ERRP_GUARD();
10391038
FWCfgDataGeneratorClass *klass;
10401039
GByteArray *array;
10411040
Object *obj;
@@ -1044,20 +1043,22 @@ void fw_cfg_add_from_generator(FWCfgState *s, const char *filename,
10441043
obj = object_resolve_path_component(object_get_objects_root(), gen_id);
10451044
if (!obj) {
10461045
error_setg(errp, "Cannot find object ID '%s'", gen_id);
1047-
return;
1046+
return false;
10481047
}
10491048
if (!object_dynamic_cast(obj, TYPE_FW_CFG_DATA_GENERATOR_INTERFACE)) {
10501049
error_setg(errp, "Object ID '%s' is not a '%s' subclass",
10511050
gen_id, TYPE_FW_CFG_DATA_GENERATOR_INTERFACE);
1052-
return;
1051+
return false;
10531052
}
10541053
klass = FW_CFG_DATA_GENERATOR_GET_CLASS(obj);
10551054
array = klass->get_data(obj, errp);
1056-
if (*errp) {
1057-
return;
1055+
if (!array) {
1056+
return false;
10581057
}
10591058
size = array->len;
10601059
fw_cfg_add_file(s, filename, g_byte_array_free(array, TRUE), size);
1060+
1061+
return true;
10611062
}
10621063

10631064
static void fw_cfg_machine_reset(void *opaque)

include/hw/nvram/fw_cfg.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ typedef struct FWCfgDataGeneratorClass {
3232
* @obj: the object implementing this interface
3333
* @errp: pointer to a NULL-initialized error object
3434
*
35-
* Returns: reference to a byte array containing the data.
35+
* Returns: reference to a byte array containing the data on success,
36+
* or NULL on error.
37+
*
3638
* The caller should release the reference when no longer
3739
* required.
3840
*/
@@ -302,8 +304,10 @@ void *fw_cfg_modify_file(FWCfgState *s, const char *filename, void *data,
302304
* will be used; also, a new entry will be added to the file directory
303305
* structure residing at key value FW_CFG_FILE_DIR, containing the item name,
304306
* data size, and assigned selector key value.
307+
*
308+
* Returns: %true on success, %false on error.
305309
*/
306-
void fw_cfg_add_from_generator(FWCfgState *s, const char *filename,
310+
bool fw_cfg_add_from_generator(FWCfgState *s, const char *filename,
307311
const char *gen_id, Error **errp);
308312

309313
FWCfgState *fw_cfg_init_io_dma(uint32_t iobase, uint32_t dma_iobase,

softmmu/vl.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2070,11 +2070,7 @@ static int parse_fw_cfg(void *opaque, QemuOpts *opts, Error **errp)
20702070
size = strlen(str); /* NUL terminator NOT included in fw_cfg blob */
20712071
buf = g_memdup(str, size);
20722072
} else if (nonempty_str(gen_id)) {
2073-
Error *local_err = NULL;
2074-
2075-
fw_cfg_add_from_generator(fw_cfg, name, gen_id, errp);
2076-
if (local_err) {
2077-
error_propagate(errp, local_err);
2073+
if (!fw_cfg_add_from_generator(fw_cfg, name, gen_id, errp)) {
20782074
return -1;
20792075
}
20802076
return 0;

0 commit comments

Comments
 (0)