Skip to content

Commit a3ad583

Browse files
committed
hw/nvram/fw_cfg: Simplify fw_cfg_add_from_generator() error propagation
Document FWCfgDataGeneratorClass::get_data() return NULL on error, and non-NULL on success. This allow us to simplify fw_cfg_add_from_generator(). Since we don't need a local variable to propagate the error, we can remove the ERRP_GUARD() macro. Suggested-by: Markus Armbruster <[email protected]> Signed-off-by: Philippe Mathieu-Daudé <[email protected]> Reviewed-by: Markus Armbruster <[email protected]> Message-Id: <[email protected]>
1 parent 90218a9 commit a3ad583

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

hw/nvram/fw_cfg.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,7 +1035,6 @@ void *fw_cfg_modify_file(FWCfgState *s, const char *filename,
10351035
void 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;
@@ -1053,7 +1052,7 @@ void fw_cfg_add_from_generator(FWCfgState *s, const char *filename,
10531052
}
10541053
klass = FW_CFG_DATA_GENERATOR_GET_CLASS(obj);
10551054
array = klass->get_data(obj, errp);
1056-
if (*errp) {
1055+
if (!array) {
10571056
return;
10581057
}
10591058
size = array->len;

include/hw/nvram/fw_cfg.h

Lines changed: 3 additions & 1 deletion
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
*/

0 commit comments

Comments
 (0)