]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tree-wide: coccinelle fixes
authorFrantisek Sumsal <frantisek@sumsal.cz>
Fri, 9 Jul 2021 11:15:01 +0000 (13:15 +0200)
committerLuca Boccassi <luca.boccassi@gmail.com>
Fri, 9 Jul 2021 19:54:22 +0000 (20:54 +0100)
Yet another batch of Coccinelle fixes.

src/basic/efivars.c
src/basic/time-util.c
src/creds/creds.c
src/libsystemd-network/sd-dhcp-client.c
src/nspawn/nspawn-bind-user.c
src/nspawn/nspawn.c
src/portable/portable.c

index 032ae6f9a1ce209583517e84bfbda9464c0f21ca..77d969c6350173502f29f0e8b9b3b5989a5d37bf 100644 (file)
@@ -382,7 +382,7 @@ int systemd_efi_options_efivarfs_if_newer(char **line) {
                 return log_debug_errno(errno, "Failed to stat EFI variable SystemdOptions: %m");
 
         if (stat(EFIVAR_CACHE_PATH(EFI_SYSTEMD_VARIABLE(SystemdOptions)), &b) < 0) {
-                if (errno != -ENOENT)
+                if (errno != ENOENT)
                         log_debug_errno(errno, "Failed to stat "EFIVAR_CACHE_PATH(EFI_SYSTEMD_VARIABLE(SystemdOptions))": %m");
         } else if (compare_stat_mtime(&a, &b) > 0)
                 log_debug("Variable SystemdOptions in evifarfs is newer than in cache.");
index 5d162e8ffe85bf719d2ed103a8e306e94e09d19b..0a4fcdcd135ae77fa1ef830a77175108cb52c5c1 100644 (file)
@@ -1334,10 +1334,10 @@ static int get_timezones_from_tzdata_zi(char ***ret) {
                         continue;
 
                 char *tz;
-                if (*type == 'Z' || *type == 'z')
+                if (IN_SET(*type, 'Z', 'z'))
                         /* Zone lines have timezone in field 1. */
                         tz = f1;
-                else if (*type == 'L' || *type == 'l')
+                else if (IN_SET(*type, 'L', 'l'))
                         /* Link lines have timezone in field 2. */
                         tz = f2;
                 else
index 50de685cd4a43fd8dd7a8e295ab1e65032c573dd..b58faf65899b96984b334aa6408182fee40437fd 100644 (file)
@@ -362,7 +362,7 @@ static int verb_encrypt(int argc, char **argv, void *userdata) {
 
         assert(argc == 3);
 
-        input_path = (isempty(argv[1]) || streq(argv[1], "-")) ? NULL : argv[1];
+        input_path = empty_or_dash(argv[1]) ? NULL : argv[1];
 
         if (input_path)
                 r = read_full_file_full(AT_FDCWD, input_path, UINT64_MAX, CREDENTIAL_SIZE_MAX, READ_FULL_FILE_SECURE|READ_FULL_FILE_FAIL_WHEN_LARGER, NULL, &plaintext, &plaintext_size);
@@ -373,7 +373,7 @@ static int verb_encrypt(int argc, char **argv, void *userdata) {
         if (r < 0)
                 return log_error_errno(r, "Failed to read plaintext: %m");
 
-        output_path = (isempty(argv[2]) || streq(argv[2], "-")) ? NULL : argv[2];
+        output_path = empty_or_dash(argv[2]) ? NULL : argv[2];
 
         if (arg_name_any)
                 name = NULL;
@@ -455,7 +455,7 @@ static int verb_decrypt(int argc, char **argv, void *userdata) {
 
         assert(IN_SET(argc, 2, 3));
 
-        input_path = (isempty(argv[1]) || streq(argv[1], "-")) ? NULL : argv[1];
+        input_path = empty_or_dash(argv[1]) ? NULL : argv[1];
 
         if (input_path)
                 r = read_full_file_full(AT_FDCWD, argv[1], UINT64_MAX, CREDENTIAL_ENCRYPTED_SIZE_MAX, READ_FULL_FILE_UNBASE64|READ_FULL_FILE_FAIL_WHEN_LARGER, NULL, &input, &input_size);
index dc8ff19d1a2448811c6df4cffbada36a62448c1a..3c8c440771c37846b25fc4f9e1fdb93d27d47985 100644 (file)
@@ -238,7 +238,7 @@ int sd_dhcp_client_set_callback(
 int sd_dhcp_client_set_request_broadcast(sd_dhcp_client *client, int broadcast) {
         assert_return(client, -EINVAL);
 
-        client->request_broadcast = !!broadcast;
+        client->request_broadcast = broadcast;
 
         return 0;
 }
index 6852125b9d33dc31e23589cf99414b5df33bb798..3250cd9768fb698e75cecb2d55ef795067f17deb 100644 (file)
@@ -171,10 +171,8 @@ static int find_free_uid(const char *directory, uid_t max_uid, uid_t *current_ui
 
                 /* We want to use the UID also as GID, hence check for it in /etc/group too */
                 r = check_etc_group_collisions(directory, NULL, (gid_t) *current_uid);
-                if (r < 0)
+                if (r <= 0)
                         return r;
-                if (r == 0) /* free! yay! */
-                        return 0;
         }
 }
 
index 04685fecbaf35d0e81fdb7cb412cf59c0bd9d3b5..3cc028b55bca0d232ed4fc95938cda4b009df4ac 100644 (file)
@@ -4091,7 +4091,7 @@ static int make_uid_map_string(
         int r;
 
         assert(n_bind_user_uid == 0 || bind_user_uid);
-        assert(offset == 0 || offset == 2); /* used to switch between UID and GID map */
+        assert(IN_SET(offset, 0, 2)); /* used to switch between UID and GID map */
         assert(ret);
 
         /* The bind_user_uid[] array is a series of 4 uid_t values, for each --bind-user= entry one
index 4cf5fb4f0aa92bd74baa0b9d706aaa028fee1391..5afb008bb8f2737d5dcad8902a213a9a7739606a 100644 (file)
@@ -86,10 +86,8 @@ static PortableMetadata *portable_metadata_new(const char *name, const char *pat
         /* In case of a layered attach, we want to remember which image the unit came from */
         if (path) {
                 m->image_path = strdup(path);
-                if (!m->image_path) {
-                        free(m);
-                        return NULL;
-                }
+                if (!m->image_path)
+                        return mfree(m);
         }
 
         strcpy(m->name, name);