On 10/28/21 17:54, Daniel P. Berrangé wrote:
> This turns the pattern
>
> if (err) {
> hmp_handle_error(mon, err);
> return;
> }
>
> into
>
> if (hmp_handle_error(mon, err);
> return;
> }
>
> Signed-off-by: Daniel P. Berrangé <[email protected]>
> ---
> hw/core/machine-hmp-cmds.c | 3 +--
> include/monitor/hmp.h | 2 +-
> monitor/hmp-cmds.c | 28 +++++++++++-----------------
> 3 files changed, 13 insertions(+), 20 deletions(-)
>
> diff --git a/hw/core/machine-hmp-cmds.c b/hw/core/machine-hmp-cmds.c
> index 76b22b00d6..c356783ab9 100644
> --- a/hw/core/machine-hmp-cmds.c
> +++ b/hw/core/machine-hmp-cmds.c
> @@ -53,8 +53,7 @@ void hmp_hotpluggable_cpus(Monitor *mon, const QDict *qdict)
> HotpluggableCPUList *saved = l;
> CpuInstanceProperties *c;
>
> - if (err != NULL) {
> - hmp_handle_error(mon, err);
> + if (hmp_handle_error(mon, err)) {
> return;
> }
>
> diff --git a/include/monitor/hmp.h b/include/monitor/hmp.h
> index 6bc27639e0..a2cb002a3a 100644
> --- a/include/monitor/hmp.h
> +++ b/include/monitor/hmp.h
> @@ -16,7 +16,7 @@
>
> #include "qemu/readline.h"
>
> -void hmp_handle_error(Monitor *mon, Error *err);
> +bool hmp_handle_error(Monitor *mon, Error *err);
>
> void hmp_info_name(Monitor *mon, const QDict *qdict);
> void hmp_info_version(Monitor *mon, const QDict *qdict);
> diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c
> index bcaa41350e..9031cea881 100644
> --- a/monitor/hmp-cmds.c
> +++ b/monitor/hmp-cmds.c
> @@ -62,11 +62,13 @@
> #include <spice/enums.h>
> #endif
>
> -void hmp_handle_error(Monitor *mon, Error *err)
> +bool hmp_handle_error(Monitor *mon, Error *err)
> {
> if (err) {
> error_reportf_err(err, "Error: ");
> + return true;
> }
> + return false;
> }
The usual pattern is to return false on error. Anyhow,
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>