From b5da337d1e9f1e9d3cb2526fde776e8ca4b3a60d Mon Sep 17 00:00:00 2001 From: Matthew Rosato Date: Wed, 2 Feb 2022 09:19:46 -0500 Subject: [PATCH] zdev: check for errors when removing a devtype setting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently, a device type setting being --removed from both the active and persistent configuration via 'chzdev -t' can result in a scenario where the setting is not removed from the active configuration (and an error message is presented) but chzdev still proceeds to remove the setting from the persistent configuration. Update this logic so that devtype_remove_settings behaves the same way as device_remove_settings and only perform the removal when no errors are encountered. Reported-by: Boris Fiuczynski Reviewed-by: Jason J. Herne Reviewed-by: Boris Fiuczynski Reviewed-by: Peter Oberparleiter Signed-off-by: Matthew Rosato Signed-off-by: Jan Höppner --- zdev/src/chzdev.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/zdev/src/chzdev.c b/zdev/src/chzdev.c index 76f7309d..a37b41a8 100644 --- a/zdev/src/chzdev.c +++ b/zdev/src/chzdev.c @@ -2088,12 +2088,18 @@ static exit_code_t devtype_remove_settings(struct devtype *dt, config_t config, found = strlist_new(); notfound = strlist_new(); - if (SCOPE_ACTIVE(config)) - remove_settings(dt->active_settings, names, found, notfound, 1); + if (SCOPE_ACTIVE(config)) { + rc = remove_settings(dt->active_settings, names, found, + notfound, 1); + if (rc) + goto out; + } if (SCOPE_PERSISTENT(config)) { - remove_settings(dt->persistent_settings, names, found, - notfound, 0); + rc = remove_settings(dt->persistent_settings, names, found, + notfound, 0); + if (rc) + goto out; } if (!util_list_is_empty(notfound)) { @@ -2104,6 +2110,7 @@ static exit_code_t devtype_remove_settings(struct devtype *dt, config_t config, rc = EXIT_SETTING_NOT_FOUND; } +out: strlist_free(found); strlist_free(notfound);