Merge pull request #30639 from mrc0mmand/more-cocci-shenanigans

Another batch of Coccinelle tweaks
This commit is contained in:
Yu Watanabe
2023-12-27 20:33:46 +09:00
committed by GitHub
12 changed files with 109 additions and 267 deletions
+1 -1
View File
@@ -221,7 +221,7 @@ int get_locales(char ***ret) {
locales = set_free(locales);
r = getenv_bool("SYSTEMD_LIST_NON_UTF8_LOCALES");
if (r == -ENXIO || r == 0) {
if (IN_SET(r, -ENXIO, 0)) {
char **a, **b;
/* Filter out non-UTF-8 locales, because it's 2019, by default */
+1 -1
View File
@@ -1018,7 +1018,7 @@ static int remove_loader_variables(void) {
EFI_LOADER_VARIABLE(LoaderEntryDefault),
EFI_LOADER_VARIABLE(LoaderEntryLastBooted),
EFI_LOADER_VARIABLE(LoaderEntryOneShot),
EFI_LOADER_VARIABLE(LoaderSystemToken)){
EFI_LOADER_VARIABLE(LoaderSystemToken)) {
int q;
+1 -1
View File
@@ -348,7 +348,7 @@ static int parse_package_metadata(const char *name, JsonVariant *id_json, Elf *e
/* Package metadata is in PT_NOTE headers. */
program_header = sym_gelf_getphdr(elf, i, &mem);
if (!program_header || (program_header->p_type != PT_NOTE && program_header->p_type != PT_INTERP))
if (!program_header || !IN_SET(program_header->p_type, PT_NOTE, PT_INTERP))
continue;
if (program_header->p_type == PT_INTERP) {
+4 -4
View File
@@ -665,7 +665,7 @@ int pkcs11_token_find_private_key(
optional_attributes[1].ulValueLen = sizeof(derive_value);
rv = m->C_GetAttributeValue(session, candidate, optional_attributes, ELEMENTSOF(optional_attributes));
if (rv != CKR_OK && rv != CKR_ATTRIBUTE_TYPE_INVALID)
if (!IN_SET(rv, CKR_OK, CKR_ATTRIBUTE_TYPE_INVALID))
return log_error_errno(SYNTHETIC_ERRNO(EIO),
"Failed to get attributes of a selected private key: %s", sym_p11_kit_strerror(rv));
@@ -737,7 +737,7 @@ int pkcs11_token_find_related_object(
CK_RV rv;
rv = m->C_GetAttributeValue(session, prototype, attributes, ELEMENTSOF(attributes));
if (rv != CKR_OK && rv != CKR_ATTRIBUTE_TYPE_INVALID)
if (!IN_SET(rv, CKR_OK, CKR_ATTRIBUTE_TYPE_INVALID))
return log_debug_errno(SYNTHETIC_ERRNO(EIO), "Failed to retrieve length of attributes: %s", sym_p11_kit_strerror(rv));
if (attributes[0].ulValueLen != CK_UNAVAILABLE_INFORMATION) {
@@ -812,7 +812,7 @@ static int ecc_convert_to_compressed(
int r;
rv = m->C_GetAttributeValue(session, object, &ec_params_attr, 1);
if (rv != CKR_OK && rv != CKR_ATTRIBUTE_TYPE_INVALID)
if (!IN_SET(rv, CKR_OK, CKR_ATTRIBUTE_TYPE_INVALID))
return log_error_errno(SYNTHETIC_ERRNO(EIO),
"Failed to retrieve length of CKA_EC_PARAMS: %s", sym_p11_kit_strerror(rv));
@@ -834,7 +834,7 @@ static int ecc_convert_to_compressed(
ec_params_attr.ulValueLen = 0;
rv = m->C_GetAttributeValue(session, public_key, &ec_params_attr, 1);
if (rv != CKR_OK && rv != CKR_ATTRIBUTE_TYPE_INVALID)
if (!IN_SET(rv, CKR_OK, CKR_ATTRIBUTE_TYPE_INVALID))
return log_error_errno(SYNTHETIC_ERRNO(EIO),
"Failed to retrieve length of CKA_EC_PARAMS: %s", sym_p11_kit_strerror(rv));
+1 -1
View File
@@ -7569,7 +7569,7 @@ int tpm2_util_pbkdf2_hmac_sha256(const void *pass,
size_t saltlen,
uint8_t ret_key[static SHA256_DIGEST_SIZE]) {
uint8_t _cleanup_(erase_and_freep) *buffer = NULL;
_cleanup_(erase_and_freep) uint8_t *buffer = NULL;
uint8_t u[SHA256_DIGEST_SIZE];
/* To keep this simple, since derived KeyLen (dkLen in docs)
+5 -5
View File
@@ -328,23 +328,23 @@ TEST(mount_option_supported) {
r = mount_option_supported("tmpfs", "size", "64M");
log_info("tmpfs supports size=64M: %s (%i)", r < 0 ? "don't know" : yes_no(r), r);
assert_se(r > 0 || r == -EAGAIN || (r < 0 && ERRNO_IS_PRIVILEGE(r)));
assert_se(r > 0 || r == -EAGAIN || ERRNO_IS_NEG_PRIVILEGE(r));
r = mount_option_supported("ext4", "discard", NULL);
log_info("ext4 supports discard: %s (%i)", r < 0 ? "don't know" : yes_no(r), r);
assert_se(r > 0 || r == -EAGAIN || (r < 0 && ERRNO_IS_PRIVILEGE(r)));
assert_se(r > 0 || r == -EAGAIN || ERRNO_IS_NEG_PRIVILEGE(r));
r = mount_option_supported("tmpfs", "idontexist", "64M");
log_info("tmpfs supports idontexist: %s (%i)", r < 0 ? "don't know" : yes_no(r), r);
assert_se(r == 0 || r == -EAGAIN || (r < 0 && ERRNO_IS_PRIVILEGE(r)));
assert_se(IN_SET(r, 0, -EAGAIN) || ERRNO_IS_NEG_PRIVILEGE(r));
r = mount_option_supported("tmpfs", "ialsodontexist", NULL);
log_info("tmpfs supports ialsodontexist: %s (%i)", r < 0 ? "don't know" : yes_no(r), r);
assert_se(r == 0 || r == -EAGAIN || (r < 0 && ERRNO_IS_PRIVILEGE(r)));
assert_se(IN_SET(r, 0, -EAGAIN) || ERRNO_IS_NEG_PRIVILEGE(r));
r = mount_option_supported("proc", "hidepid", "1");
log_info("proc supports hidepid=1: %s (%i)", r < 0 ? "don't know" : yes_no(r), r);
assert_se(r >= 0 || r == -EAGAIN || (r < 0 && ERRNO_IS_PRIVILEGE(r)));
assert_se(r >= 0 || r == -EAGAIN || ERRNO_IS_NEG_PRIVILEGE(r));
}
TEST(fstype_can_discard) {
+1 -1
View File
@@ -141,7 +141,7 @@ TEST(set_ensure_allocated) {
assert_se(set_ensure_allocated(&m, &string_hash_ops) == 1);
assert_se(set_ensure_allocated(&m, &string_hash_ops) == 0);
assert_se(set_ensure_allocated(&m, NULL) == 0);
assert_se(set_size(m) == 0);
assert_se(set_isempty(m));
}
TEST(set_copy) {
+3 -3
View File
@@ -1089,9 +1089,9 @@ TEST(map_clock_usec) {
assert_se(nowr < USEC_INFINITY - USEC_PER_DAY*7); /* overflow check */
x = nowr + USEC_PER_DAY*7; /* 1 week from now */
y = map_clock_usec(x, CLOCK_REALTIME, CLOCK_MONOTONIC);
assert_se(y > 0 && y < USEC_INFINITY);
assert_se(timestamp_is_set(y));
z = map_clock_usec(y, CLOCK_MONOTONIC, CLOCK_REALTIME);
assert_se(z > 0 && z < USEC_INFINITY);
assert_se(timestamp_is_set(z));
assert_se((z > x ? z - x : x - z) < USEC_PER_HOUR);
assert_se(nowr > USEC_PER_DAY * 7); /* underflow check */
@@ -1100,7 +1100,7 @@ TEST(map_clock_usec) {
if (y != 0) { /* might underflow if machine is not up long enough for the monotonic clock to be beyond 1w */
assert_se(y < USEC_INFINITY);
z = map_clock_usec(y, CLOCK_MONOTONIC, CLOCK_REALTIME);
assert_se(z > 0 && z < USEC_INFINITY);
assert_se(timestamp_is_set(z));
assert_se((z > x ? z - x : x - z) < USEC_PER_HOUR);
}
}
+2 -2
View File
@@ -45,7 +45,7 @@ TEST(getxattr_at_malloc) {
fd = open("/", O_RDONLY|O_DIRECTORY|O_CLOEXEC|O_NOCTTY);
assert_se(fd >= 0);
r = getxattr_at_malloc(fd, "usr", "user.idontexist", 0, &value);
assert_se(r < 0 && ERRNO_IS_XATTR_ABSENT(r));
assert_se(ERRNO_IS_NEG_XATTR_ABSENT(r));
safe_close(fd);
fd = open(x, O_PATH|O_CLOEXEC);
@@ -99,7 +99,7 @@ TEST(xsetxattr) {
/* by full path */
r = xsetxattr(AT_FDCWD, x, "user.foo", "fullpath", SIZE_MAX, 0);
if (r < 0 && ERRNO_IS_NOT_SUPPORTED(r))
if (ERRNO_IS_NEG_NOT_SUPPORTED(r))
return (void) log_tests_skipped_errno(r, "no xattrs supported on /var/tmp");
assert_se(r >= 0);
verify_xattr(dfd, "fullpath");