tree-wide: use set_ensure_put()

Patch contains a coccinelle script, but it only works in some cases. Many
parts were converted by hand.

Note: I did not fix errors in return value handing. This will be done separate
to keep the patch comprehensible. No functional change is intended in this
patch.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2020-06-22 16:32:37 +02:00
parent 0f9ccd9552
commit de7fef4b6e
37 changed files with 92 additions and 330 deletions
+1 -5
View File
@@ -613,11 +613,7 @@ int bus_message_print_all_properties(
return r;
if (found_properties) {
r = set_ensure_allocated(found_properties, &string_hash_ops);
if (r < 0)
return log_oom();
r = set_put(*found_properties, name);
r = set_ensure_put(found_properties, &string_hash_ops, name);
if (r < 0 && r != -EEXIST)
return log_oom();
}
+5 -10
View File
@@ -1742,17 +1742,13 @@ int seccomp_restrict_archs(Set *archs) {
return 0;
}
int parse_syscall_archs(char **l, Set **archs) {
_cleanup_set_free_ Set *_archs = NULL;
int parse_syscall_archs(char **l, Set **ret_archs) {
_cleanup_set_free_ Set *archs = NULL;
char **s;
int r;
assert(l);
assert(archs);
r = set_ensure_allocated(&_archs, NULL);
if (r < 0)
return r;
assert(ret_archs);
STRV_FOREACH(s, l) {
uint32_t a;
@@ -1761,13 +1757,12 @@ int parse_syscall_archs(char **l, Set **archs) {
if (r < 0)
return -EINVAL;
r = set_put(_archs, UINT32_TO_PTR(a + 1));
r = set_ensure_put(&archs, NULL, UINT32_TO_PTR(a + 1));
if (r < 0)
return -ENOMEM;
}
*archs = TAKE_PTR(_archs);
*ret_archs = TAKE_PTR(archs);
return 0;
}
+1 -1
View File
@@ -105,6 +105,6 @@ extern const uint32_t seccomp_local_archs[];
DEFINE_TRIVIAL_CLEANUP_FUNC(scmp_filter_ctx, seccomp_release);
int parse_syscall_archs(char **l, Set **archs);
int parse_syscall_archs(char **l, Set **ret_archs);
uint32_t scmp_act_kill_process(void);
+1 -5
View File
@@ -359,11 +359,7 @@ static int userdb_connect(
if (r < 0)
return log_debug_errno(r, "Failed to invoke varlink method: %m");
r = set_ensure_allocated(&iterator->links, &link_hash_ops);
if (r < 0)
return log_debug_errno(r, "Failed to allocate set: %m");
r = set_put(iterator->links, vl);
r = set_ensure_put(&iterator->links, &link_hash_ops, vl);
if (r < 0)
return log_debug_errno(r, "Failed to add varlink connection to set: %m");