Merge pull request #12420 from mrc0mmand/coccinelle-tweaks
Coccinelle improvements
This commit is contained in:
commit
0892f3f999
|
@ -1,8 +1,12 @@
|
|||
@@
|
||||
constant s;
|
||||
@@
|
||||
(
|
||||
#define STRLEN
|
||||
&
|
||||
- sizeof(s)-1
|
||||
+ STRLEN(s)
|
||||
)
|
||||
@@
|
||||
constant s;
|
||||
@@
|
|
@ -1,8 +1,16 @@
|
|||
@@
|
||||
@@
|
||||
(
|
||||
#define DEBUG_LOGGING
|
||||
&
|
||||
- _unlikely_(log_get_max_level() >= LOG_DEBUG)
|
||||
+ DEBUG_LOGGING
|
||||
)
|
||||
@@
|
||||
@@
|
||||
(
|
||||
#define DEBUG_LOGGING
|
||||
&
|
||||
- log_get_max_level() >= LOG_DEBUG
|
||||
+ DEBUG_LOGGING
|
||||
)
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
@@
|
||||
/* We want to stick with dup() in test-fd-util.c */
|
||||
position p : script:python() { p[0].file != "src/test/test-fd-util.c" };
|
||||
expression fd;
|
||||
@@
|
||||
- dup(fd)
|
||||
- dup@p(fd)
|
||||
+ fcntl(fd, F_DUPFD, 3)
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
@@
|
||||
/* Avoid running this transformation on the empty_to_null function itself */
|
||||
position p : script:python() { p[0].current_element != "empty_to_null" };
|
||||
expression s;
|
||||
@@
|
||||
- isempty(s) ? NULL : s
|
||||
|
||||
- isempty@p(s) ? NULL : s
|
||||
+ empty_to_null(s)
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
@@
|
||||
/* Disable this transformation for the securebits-util.h, as it makes
|
||||
* the expression there confusing. */
|
||||
position p : script:python() { p[0].file != "src/shared/securebits-util.h" };
|
||||
expression x, y;
|
||||
@@
|
||||
- ((x) & (y)) == (y)
|
||||
(
|
||||
- ((x@p) & (y)) == (y)
|
||||
+ FLAGS_SET(x, y)
|
||||
@@
|
||||
expression x, y;
|
||||
@@
|
||||
- (x & (y)) == (y)
|
||||
|
|
||||
- (x@p & (y)) == (y)
|
||||
+ FLAGS_SET(x, y)
|
||||
@@
|
||||
expression x, y;
|
||||
@@
|
||||
- ((x) & y) == y
|
||||
|
|
||||
- ((x@p) & y) == y
|
||||
+ FLAGS_SET(x, y)
|
||||
)
|
||||
|
|
|
@ -1,54 +1,37 @@
|
|||
@@
|
||||
expression e;
|
||||
constant n0, n1, n2, n3, n4, n5, n6, n7, n8, n9;
|
||||
/* Exclude JsonVariant * from the transformation, as it can't work with the
|
||||
* current version of the IN_SET macro */
|
||||
typedef JsonVariant;
|
||||
type T != JsonVariant*;
|
||||
constant T n0, n1, n2, n3, n4, n5, n6, n7, n8, n9;
|
||||
@@
|
||||
|
||||
(
|
||||
- e == n0 || e == n1 || e == n2 || e == n3 || e == n4 || e == n5 || e == n6 || e == n7 || e == n8 || e == n9
|
||||
+ IN_SET(e, n0, n1, n2, n3, n4, n5, n6, n7, n8, n9)
|
||||
@@
|
||||
expression e;
|
||||
constant n0, n1, n2, n3, n4, n5, n6, n7, n8;
|
||||
@@
|
||||
|
|
||||
- e == n0 || e == n1 || e == n2 || e == n3 || e == n4 || e == n5 || e == n6 || e == n7 || e == n8
|
||||
+ IN_SET(e, n0, n1, n2, n3, n4, n5, n6, n7, n8)
|
||||
@@
|
||||
expression e;
|
||||
constant n0, n1, n2, n3, n4, n5, n6, n7;
|
||||
@@
|
||||
|
|
||||
- e == n0 || e == n1 || e == n2 || e == n3 || e == n4 || e == n5 || e == n6 || e == n7
|
||||
+ IN_SET(e, n0, n1, n2, n3, n4, n5, n6, n7)
|
||||
@@
|
||||
expression e;
|
||||
constant n0, n1, n2, n3, n4, n5, n6;
|
||||
@@
|
||||
|
|
||||
- e == n0 || e == n1 || e == n2 || e == n3 || e == n4 || e == n5 || e == n6
|
||||
+ IN_SET(e, n0, n1, n2, n3, n4, n5, n6)
|
||||
@@
|
||||
expression e;
|
||||
constant n0, n1, n2, n3, n4, n5;
|
||||
@@
|
||||
|
|
||||
- e == n0 || e == n1 || e == n2 || e == n3 || e == n4 || e == n5
|
||||
+ IN_SET(e, n0, n1, n2, n3, n4, n5)
|
||||
@@
|
||||
expression e;
|
||||
constant n0, n1, n2, n3, n4;
|
||||
@@
|
||||
|
|
||||
- e == n0 || e == n1 || e == n2 || e == n3 || e == n4
|
||||
+ IN_SET(e, n0, n1, n2, n3, n4)
|
||||
@@
|
||||
expression e;
|
||||
constant n0, n1, n2, n3;
|
||||
@@
|
||||
|
|
||||
- e == n0 || e == n1 || e == n2 || e == n3
|
||||
+ IN_SET(e, n0, n1, n2, n3)
|
||||
@@
|
||||
expression e;
|
||||
constant n0, n1, n2;
|
||||
@@
|
||||
|
|
||||
- e == n0 || e == n1 || e == n2
|
||||
+ IN_SET(e, n0, n1, n2)
|
||||
@@
|
||||
expression e;
|
||||
constant n0, n1;
|
||||
@@
|
||||
|
|
||||
- e == n0 || e == n1
|
||||
+ IN_SET(e, n0, n1)
|
||||
)
|
||||
|
|
|
@ -1,60 +1,42 @@
|
|||
@@
|
||||
/* Disable this transformation for the test-string-util.c */
|
||||
position p : script:python() { p[0].file != "src/test/test-string-util.c" };
|
||||
expression s;
|
||||
@@
|
||||
- strv_length(s) == 0
|
||||
(
|
||||
- strv_length@p(s) == 0
|
||||
+ strv_isempty(s)
|
||||
@@
|
||||
expression s;
|
||||
@@
|
||||
- strv_length(s) <= 0
|
||||
|
|
||||
- strv_length@p(s) <= 0
|
||||
+ strv_isempty(s)
|
||||
@@
|
||||
expression s;
|
||||
@@
|
||||
- strv_length(s) > 0
|
||||
|
|
||||
- strv_length@p(s) > 0
|
||||
+ !strv_isempty(s)
|
||||
@@
|
||||
expression s;
|
||||
@@
|
||||
- strv_length(s) != 0
|
||||
|
|
||||
- strv_length@p(s) != 0
|
||||
+ !strv_isempty(s)
|
||||
@@
|
||||
expression s;
|
||||
@@
|
||||
- strlen(s) == 0
|
||||
|
|
||||
- strlen@p(s) == 0
|
||||
+ isempty(s)
|
||||
@@
|
||||
expression s;
|
||||
@@
|
||||
- strlen(s) <= 0
|
||||
|
|
||||
- strlen@p(s) <= 0
|
||||
+ isempty(s)
|
||||
@@
|
||||
expression s;
|
||||
@@
|
||||
- strlen(s) > 0
|
||||
|
|
||||
- strlen@p(s) > 0
|
||||
+ !isempty(s)
|
||||
@@
|
||||
expression s;
|
||||
@@
|
||||
- strlen(s) != 0
|
||||
|
|
||||
- strlen@p(s) != 0
|
||||
+ !isempty(s)
|
||||
@@
|
||||
expression s;
|
||||
@@
|
||||
- strlen_ptr(s) == 0
|
||||
|
|
||||
- strlen_ptr@p(s) == 0
|
||||
+ isempty(s)
|
||||
@@
|
||||
expression s;
|
||||
@@
|
||||
- strlen_ptr(s) <= 0
|
||||
|
|
||||
- strlen_ptr@p(s) <= 0
|
||||
+ isempty(s)
|
||||
@@
|
||||
expression s;
|
||||
@@
|
||||
- strlen_ptr(s) > 0
|
||||
|
|
||||
- strlen_ptr@p(s) > 0
|
||||
+ !isempty(s)
|
||||
@@
|
||||
expression s;
|
||||
@@
|
||||
- strlen_ptr(s) != 0
|
||||
|
|
||||
- strlen_ptr@p(s) != 0
|
||||
+ !isempty(s)
|
||||
)
|
||||
|
|
|
@ -21,10 +21,18 @@ expression s;
|
|||
@@
|
||||
expression a, b;
|
||||
@@
|
||||
(
|
||||
#define memzero
|
||||
&
|
||||
- memset(a, 0, b)
|
||||
+ memzero(a, b)
|
||||
)
|
||||
@@
|
||||
expression a, b;
|
||||
@@
|
||||
(
|
||||
#define memzero
|
||||
&
|
||||
- bzero(a, b)
|
||||
+ memzero(a, b)
|
||||
)
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
@@
|
||||
expression p;
|
||||
/* Avoid running this transformation on the mfree function itself */
|
||||
position p : script:python() { p[0].current_element != "mfree" };
|
||||
expression e;
|
||||
@@
|
||||
- free(p);
|
||||
- free@p(e);
|
||||
- return NULL;
|
||||
+ return mfree(p);
|
||||
+ return mfree(e);
|
||||
|
|
|
@ -1,54 +1,34 @@
|
|||
@@
|
||||
expression e;
|
||||
constant n0, n1, n2, n3, n4, n5, n6, n7, n8, n9;
|
||||
typedef JsonVariant;
|
||||
type T != JsonVariant*;
|
||||
constant T n0, n1, n2, n3, n4, n5, n6, n7, n8, n9;
|
||||
@@
|
||||
(
|
||||
- e != n0 && e != n1 && e != n2 && e != n3 && e != n4 && e != n5 && e != n6 && e != n7 && e != n8 && e != n9
|
||||
+ !IN_SET(e, n0, n1, n2, n3, n4, n5, n6, n7, n8, n9)
|
||||
@@
|
||||
expression e;
|
||||
constant n0, n1, n2, n3, n4, n5, n6, n7, n8;
|
||||
@@
|
||||
|
|
||||
- e != n0 && e != n1 && e != n2 && e != n3 && e != n4 && e != n5 && e != n6 && e != n7 && e != n8
|
||||
+ !IN_SET(e, n0, n1, n2, n3, n4, n5, n6, n7, n8)
|
||||
@@
|
||||
expression e;
|
||||
constant n0, n1, n2, n3, n4, n5, n6, n7;
|
||||
@@
|
||||
|
|
||||
- e != n0 && e != n1 && e != n2 && e != n3 && e != n4 && e != n5 && e != n6 && e != n7
|
||||
+ !IN_SET(e, n0, n1, n2, n3, n4, n5, n6, n7)
|
||||
@@
|
||||
expression e;
|
||||
constant n0, n1, n2, n3, n4, n5, n6;
|
||||
@@
|
||||
|
|
||||
- e != n0 && e != n1 && e != n2 && e != n3 && e != n4 && e != n5 && e != n6
|
||||
+ !IN_SET(e, n0, n1, n2, n3, n4, n5, n6)
|
||||
@@
|
||||
expression e;
|
||||
constant n0, n1, n2, n3, n4, n5;
|
||||
@@
|
||||
|
|
||||
- e != n0 && e != n1 && e != n2 && e != n3 && e != n4 && e != n5
|
||||
+ !IN_SET(e, n0, n1, n2, n3, n4, n5)
|
||||
@@
|
||||
expression e;
|
||||
constant n0, n1, n2, n3, n4;
|
||||
@@
|
||||
|
|
||||
- e != n0 && e != n1 && e != n2 && e != n3 && e != n4
|
||||
+ !IN_SET(e, n0, n1, n2, n3, n4)
|
||||
@@
|
||||
expression e;
|
||||
constant n0, n1, n2, n3;
|
||||
@@
|
||||
|
|
||||
- e != n0 && e != n1 && e != n2 && e != n3
|
||||
+ !IN_SET(e, n0, n1, n2, n3)
|
||||
@@
|
||||
expression e;
|
||||
constant n0, n1, n2;
|
||||
@@
|
||||
|
|
||||
- e != n0 && e != n1 && e != n2
|
||||
+ !IN_SET(e, n0, n1, n2)
|
||||
@@
|
||||
expression e;
|
||||
constant n0, n1;
|
||||
@@
|
||||
|
|
||||
- e != n0 && e != n1
|
||||
+ !IN_SET(e, n0, n1)
|
||||
)
|
||||
|
|
|
@ -1,9 +1,25 @@
|
|||
#!/bin/bash -e
|
||||
|
||||
# Exclude following paths from the Coccinelle transformations
|
||||
EXCLUDED_PATHS=(
|
||||
"src/boot/efi/*"
|
||||
"src/shared/linux/*"
|
||||
"src/basic/linux/*"
|
||||
# Symlinked to test-bus-vtable-cc.cc, which causes issues with the IN_SET macro
|
||||
"src/libsystemd/sd-bus/test-bus-vtable.c"
|
||||
)
|
||||
|
||||
top="$(git rev-parse --show-toplevel)"
|
||||
files="$(git ls-files ':/*.[ch]')"
|
||||
iso_defs="$top/coccinelle/systemd-definitions.iso"
|
||||
args=
|
||||
|
||||
# Create an array from files tracked by git...
|
||||
mapfile -t files < <(git ls-files ':/*.[ch]')
|
||||
# ...and filter everything that matches patterns from EXCLUDED_PATHS
|
||||
for excl in "${EXCLUDED_PATHS[@]}"; do
|
||||
files=(${files[@]//$excl})
|
||||
done
|
||||
|
||||
case "$1" in
|
||||
-i)
|
||||
args="$args --in-place"
|
||||
|
@ -21,7 +37,7 @@ for SCRIPT in ${@-$top/coccinelle/*.cocci} ; do
|
|||
TMPFILE=`mktemp`
|
||||
echo "+ spatch --sp-file $SCRIPT $args ..."
|
||||
parallel --halt now,fail=1 --keep-order --noswap --max-args=20 \
|
||||
spatch --sp-file $SCRIPT $args ::: $files \
|
||||
spatch --iso-file $iso_defs --sp-file $SCRIPT $args ::: "${files[@]}" \
|
||||
2>"$TMPFILE" || cat "$TMPFILE"
|
||||
echo -e "--x-- Processed $SCRIPT --x--\n"
|
||||
done
|
||||
|
|
|
@ -1,48 +1,60 @@
|
|||
@@
|
||||
/* Avoid running this transformation on the strempty function itself */
|
||||
position p : script:python() { p[0].current_element != "strempty" };
|
||||
expression s;
|
||||
@@
|
||||
- s ?: ""
|
||||
(
|
||||
- s@p ?: ""
|
||||
+ strempty(s)
|
||||
@@
|
||||
expression s;
|
||||
@@
|
||||
- s ? s : ""
|
||||
|
|
||||
- s@p ? s : ""
|
||||
+ strempty(s)
|
||||
)
|
||||
|
||||
@@
|
||||
position p : script:python() { p[0].current_element != "strempty" };
|
||||
expression s;
|
||||
@@
|
||||
- if (!s)
|
||||
- if (!s@p)
|
||||
- s = "";
|
||||
+ s = strempty(s);
|
||||
|
||||
@@
|
||||
position p : script:python() { p[0].current_element != "strnull" };
|
||||
expression s;
|
||||
@@
|
||||
- s ?: "(null)"
|
||||
(
|
||||
- s@p ?: "(null)"
|
||||
+ strnull(s)
|
||||
@@
|
||||
expression s;
|
||||
@@
|
||||
- s ? s : "(null)"
|
||||
|
|
||||
- s@p ? s : "(null)"
|
||||
+ strnull(s)
|
||||
)
|
||||
|
||||
@@
|
||||
position p : script:python() { p[0].current_element != "strnull" };
|
||||
expression s;
|
||||
@@
|
||||
- if (!s)
|
||||
- if (!s@p)
|
||||
- s = "(null)";
|
||||
+ s = strnull(s);
|
||||
|
||||
@@
|
||||
position p : script:python() { p[0].current_element != "strna" };
|
||||
expression s;
|
||||
@@
|
||||
- s ?: "n/a"
|
||||
(
|
||||
- s@p ?: "n/a"
|
||||
+ strna(s)
|
||||
@@
|
||||
expression s;
|
||||
@@
|
||||
- s ? s : "n/a"
|
||||
|
|
||||
- s@p ? s : "n/a"
|
||||
+ strna(s)
|
||||
)
|
||||
|
||||
@@
|
||||
position p : script:python() { p[0].current_element != "strna" };
|
||||
expression s;
|
||||
@@
|
||||
- if (!s)
|
||||
- if (!s@p)
|
||||
- s = "n/a";
|
||||
+ s = strna(s);
|
||||
|
|
|
@ -2,9 +2,15 @@
|
|||
expression e;
|
||||
expression list args;
|
||||
@@
|
||||
(
|
||||
/* Ignore one specific case in src/shared/bootspec.c where we want to stick
|
||||
* with the log_debug() + return pattern */
|
||||
log_debug("Found no default boot entry :(");
|
||||
|
|
||||
- log_debug(args);
|
||||
- return -e;
|
||||
+ return log_debug_errno(SYNTHETIC_ERRNO(e), args);
|
||||
)
|
||||
@@
|
||||
expression e;
|
||||
expression list args;
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
/* Statement isomorphisms - replace explicit checks against NULL with a
|
||||
* shorter variant, which relies on C's downgrade-to-bool feature.
|
||||
* The expression metavariables should be declared as pointers, however,
|
||||
* that doesn't work well with complex expressions like:
|
||||
* if (UNIT(p)->default_dependencies != NULL)
|
||||
*/
|
||||
|
||||
Statement
|
||||
@@
|
||||
expression X;
|
||||
statement S;
|
||||
@@
|
||||
if (X == NULL) S => if (!X) S
|
||||
|
||||
Statement
|
||||
@@
|
||||
expression X;
|
||||
statement S;
|
||||
@@
|
||||
if (X != NULL) S => if (X) S
|
|
@ -6,8 +6,15 @@ expression q;
|
|||
- q = -1;
|
||||
- return p;
|
||||
+ return TAKE_FD(q);
|
||||
|
||||
/* The ideal solution would use 'local idexpression' to avoid matching errno,
|
||||
* which is a global variable. However, 'idexpression' nor 'identifier'
|
||||
* would match, for example, "x->fd", which is considered 'expression' in
|
||||
* the SmPL grammar
|
||||
*/
|
||||
@@
|
||||
expression p, q;
|
||||
expression p != errno;
|
||||
expression q;
|
||||
@@
|
||||
- p = q;
|
||||
- q = -1;
|
||||
|
|
|
@ -59,7 +59,7 @@ int main(int argc, char **argv) {
|
|||
vtable,
|
||||
&object));
|
||||
|
||||
while (true) {
|
||||
for (;;) {
|
||||
check(sd_bus_wait(bus, UINT64_MAX));
|
||||
check(sd_bus_process(bus, NULL));
|
||||
}
|
||||
|
|
|
@ -303,8 +303,12 @@ static int bus_socket_set_transient_property(
|
|||
if (streq(name, "SocketProtocol"))
|
||||
return bus_set_transient_socket_protocol(u, name, &s->socket_protocol, message, flags, error);
|
||||
|
||||
if ((ci = socket_exec_command_from_string(name)) >= 0)
|
||||
return bus_set_transient_exec_command(u, name, &s->exec_command[ci], message, flags, error);
|
||||
ci = socket_exec_command_from_string(name);
|
||||
if (ci >= 0)
|
||||
return bus_set_transient_exec_command(u, name,
|
||||
&s->exec_command[ci],
|
||||
message, flags, error);
|
||||
|
||||
|
||||
if (streq(name, "Symlinks")) {
|
||||
_cleanup_strv_free_ char **l = NULL;
|
||||
|
|
|
@ -1036,10 +1036,7 @@ static int send_iovec(const struct iovec iovec[], size_t n_iovec, int input_fd)
|
|||
* (truncated) copy of what we want to send, and the second one
|
||||
* contains the trailing dots. */
|
||||
copy[0] = iovec[i];
|
||||
copy[1] = (struct iovec) {
|
||||
.iov_base = (char[]) { '.', '.', '.' },
|
||||
.iov_len = 3,
|
||||
};
|
||||
copy[1] = IOVEC_MAKE(((char[]){'.', '.', '.'}), 3);
|
||||
|
||||
mh.msg_iov = copy;
|
||||
mh.msg_iovlen = 2;
|
||||
|
|
|
@ -250,7 +250,7 @@ static void transfer_send_logs(Transfer *t, bool flush) {
|
|||
n = strndup(t->log_message, e - t->log_message);
|
||||
|
||||
/* Skip over NUL and newlines */
|
||||
while (e < t->log_message + t->log_message_size && (*e == 0 || *e == '\n'))
|
||||
while (e < t->log_message + t->log_message_size && IN_SET(*e, 0, '\n'))
|
||||
e++;
|
||||
|
||||
memmove(t->log_message, e, t->log_message + sizeof(t->log_message) - e);
|
||||
|
|
|
@ -181,7 +181,7 @@ static int get_source_for_fd(RemoteServer *s,
|
|||
return log_warning_errno(r, "Failed to get writer for source %s: %m",
|
||||
name);
|
||||
|
||||
if (s->sources[fd] == NULL) {
|
||||
if (!s->sources[fd]) {
|
||||
s->sources[fd] = source_new(fd, false, name, writer);
|
||||
if (!s->sources[fd]) {
|
||||
writer_unref(writer);
|
||||
|
|
|
@ -612,7 +612,7 @@ int serialize_dhcp_option(FILE *f, const char *key, const void *data, size_t siz
|
|||
assert(data);
|
||||
|
||||
hex_buf = hexmem(data, size);
|
||||
if (hex_buf == NULL)
|
||||
if (!hex_buf)
|
||||
return -ENOMEM;
|
||||
|
||||
fprintf(f, "%s=%s\n", key, hex_buf);
|
||||
|
|
|
@ -26,7 +26,7 @@ static int message_append_basic(sd_bus_message *m, char type, const void *p, con
|
|||
|
||||
static void *adjust_pointer(const void *p, void *old_base, size_t sz, void *new_base) {
|
||||
|
||||
if (p == NULL)
|
||||
if (!p)
|
||||
return NULL;
|
||||
|
||||
if (old_base == new_base)
|
||||
|
|
|
@ -693,8 +693,7 @@ bool manager_all_buttons_ignored(Manager *m) {
|
|||
return false;
|
||||
if (m->handle_lid_switch != HANDLE_IGNORE)
|
||||
return false;
|
||||
if (m->handle_lid_switch_ep != _HANDLE_ACTION_INVALID &&
|
||||
m->handle_lid_switch_ep != HANDLE_IGNORE)
|
||||
if (!IN_SET(m->handle_lid_switch_ep, _HANDLE_ACTION_INVALID, HANDLE_IGNORE))
|
||||
return false;
|
||||
if (m->handle_lid_switch_docked != HANDLE_IGNORE)
|
||||
return false;
|
||||
|
|
|
@ -754,7 +754,7 @@ void user_update_last_session_timer(User *u) {
|
|||
|
||||
assert(!u->timer_event_source);
|
||||
|
||||
if (u->manager->user_stop_delay == 0 || u->manager->user_stop_delay == USEC_INFINITY)
|
||||
if (IN_SET(u->manager->user_stop_delay, 0, USEC_INFINITY))
|
||||
return;
|
||||
|
||||
if (sd_event_get_state(u->manager->event) == SD_EVENT_FINISHED) {
|
||||
|
|
|
@ -229,7 +229,7 @@ static int dhcp6_pd_prefix_distribute(Link *dhcp6_link, Iterator *i,
|
|||
strnull(assigned_buf),
|
||||
strnull(buf), pd_prefix_len);
|
||||
|
||||
if (assigned_link == NULL)
|
||||
if (!assigned_link)
|
||||
continue;
|
||||
|
||||
} else
|
||||
|
|
|
@ -356,7 +356,7 @@ static int radv_set_dns(Link *link, Link *uplink) {
|
|||
if (link->network->router_dns) {
|
||||
dns = newdup(struct in6_addr, link->network->router_dns,
|
||||
link->network->n_router_dns);
|
||||
if (dns == NULL)
|
||||
if (!dns)
|
||||
return -ENOMEM;
|
||||
|
||||
n_dns = link->network->n_router_dns;
|
||||
|
@ -372,7 +372,7 @@ static int radv_set_dns(Link *link, Link *uplink) {
|
|||
goto set_dns;
|
||||
|
||||
if (uplink) {
|
||||
if (uplink->network == NULL) {
|
||||
if (!uplink->network) {
|
||||
log_link_debug(uplink, "Cannot fetch DNS servers as uplink interface is not managed by us");
|
||||
return 0;
|
||||
}
|
||||
|
@ -411,7 +411,7 @@ static int radv_set_domains(Link *link, Link *uplink) {
|
|||
goto set_domains;
|
||||
|
||||
if (uplink) {
|
||||
if (uplink->network == NULL) {
|
||||
if (!uplink->network) {
|
||||
log_link_debug(uplink, "Cannot fetch DNS search domains as uplink interface is not managed by us");
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ int dns_label_unescape(const char **name, char *dest, size_t sz, DNSLabelFlags f
|
|||
d = dest;
|
||||
|
||||
for (;;) {
|
||||
if (*n == 0 || *n == '.') {
|
||||
if (IN_SET(*n, 0, '.')) {
|
||||
if (FLAGS_SET(flags, DNS_LABEL_LDH) && last_char == '-')
|
||||
/* Trailing dash */
|
||||
return -EINVAL;
|
||||
|
|
|
@ -514,7 +514,7 @@ int efi_get_boot_option(
|
|||
if (path)
|
||||
*path = TAKE_PTR(p);
|
||||
if (active)
|
||||
*active = !!(header->attr & LOAD_OPTION_ACTIVE);
|
||||
*active = header->attr & LOAD_OPTION_ACTIVE;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -94,7 +94,7 @@ static int get_line(JournalImporter *imp, char **line, size_t *size) {
|
|||
|
||||
c = memchr(imp->buf + start, '\n',
|
||||
imp->filled - start);
|
||||
if (c != NULL)
|
||||
if (c)
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -395,7 +395,7 @@ static int image_make(
|
|||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (size != 0 && size != UINT64_MAX)
|
||||
if (!IN_SET(size, 0, UINT64_MAX))
|
||||
(*ret)->usage = (*ret)->usage_exclusive = (*ret)->limit = (*ret)->limit_exclusive = size;
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -158,7 +158,7 @@ static int enumerate_print_list(struct udev_enumerate *enumerate) {
|
|||
|
||||
device = udev_device_new_from_syspath(udev_enumerate_get_udev(enumerate),
|
||||
udev_list_entry_get_name(list_entry));
|
||||
if (device != NULL) {
|
||||
if (device) {
|
||||
log_info("device: '%s' (%s)",
|
||||
udev_device_get_syspath(device),
|
||||
udev_device_get_subsystem(device));
|
||||
|
@ -249,7 +249,7 @@ static int test_enumerate(struct udev *udev, const char *subsystem) {
|
|||
|
||||
log_info("enumerate '%s'", subsystem == NULL ? "<all>" : subsystem);
|
||||
udev_enumerate = udev_enumerate_new(udev);
|
||||
if (udev_enumerate == NULL)
|
||||
if (!udev_enumerate)
|
||||
return -1;
|
||||
udev_enumerate_add_match_subsystem(udev_enumerate, subsystem);
|
||||
udev_enumerate_scan_devices(udev_enumerate);
|
||||
|
@ -258,7 +258,7 @@ static int test_enumerate(struct udev *udev, const char *subsystem) {
|
|||
|
||||
log_info("enumerate 'net' + duplicated scan + null + zero");
|
||||
udev_enumerate = udev_enumerate_new(udev);
|
||||
if (udev_enumerate == NULL)
|
||||
if (!udev_enumerate)
|
||||
return -1;
|
||||
udev_enumerate_add_match_subsystem(udev_enumerate, "net");
|
||||
udev_enumerate_scan_devices(udev_enumerate);
|
||||
|
@ -278,7 +278,7 @@ static int test_enumerate(struct udev *udev, const char *subsystem) {
|
|||
|
||||
log_info("enumerate 'block'");
|
||||
udev_enumerate = udev_enumerate_new(udev);
|
||||
if (udev_enumerate == NULL)
|
||||
if (!udev_enumerate)
|
||||
return -1;
|
||||
udev_enumerate_add_match_subsystem(udev_enumerate,"block");
|
||||
r = udev_enumerate_add_match_is_initialized(udev_enumerate);
|
||||
|
@ -292,7 +292,7 @@ static int test_enumerate(struct udev *udev, const char *subsystem) {
|
|||
|
||||
log_info("enumerate 'not block'");
|
||||
udev_enumerate = udev_enumerate_new(udev);
|
||||
if (udev_enumerate == NULL)
|
||||
if (!udev_enumerate)
|
||||
return -1;
|
||||
udev_enumerate_add_nomatch_subsystem(udev_enumerate, "block");
|
||||
udev_enumerate_scan_devices(udev_enumerate);
|
||||
|
@ -301,7 +301,7 @@ static int test_enumerate(struct udev *udev, const char *subsystem) {
|
|||
|
||||
log_info("enumerate 'pci, mem, vc'");
|
||||
udev_enumerate = udev_enumerate_new(udev);
|
||||
if (udev_enumerate == NULL)
|
||||
if (!udev_enumerate)
|
||||
return -1;
|
||||
udev_enumerate_add_match_subsystem(udev_enumerate, "pci");
|
||||
udev_enumerate_add_match_subsystem(udev_enumerate, "mem");
|
||||
|
@ -312,7 +312,7 @@ static int test_enumerate(struct udev *udev, const char *subsystem) {
|
|||
|
||||
log_info("enumerate 'subsystem'");
|
||||
udev_enumerate = udev_enumerate_new(udev);
|
||||
if (udev_enumerate == NULL)
|
||||
if (!udev_enumerate)
|
||||
return -1;
|
||||
udev_enumerate_scan_subsystems(udev_enumerate);
|
||||
enumerate_print_list(udev_enumerate);
|
||||
|
@ -320,7 +320,7 @@ static int test_enumerate(struct udev *udev, const char *subsystem) {
|
|||
|
||||
log_info("enumerate 'property IF_FS_*=filesystem'");
|
||||
udev_enumerate = udev_enumerate_new(udev);
|
||||
if (udev_enumerate == NULL)
|
||||
if (!udev_enumerate)
|
||||
return -1;
|
||||
udev_enumerate_add_match_property(udev_enumerate, "ID_FS*", "filesystem");
|
||||
udev_enumerate_scan_devices(udev_enumerate);
|
||||
|
|
|
@ -88,7 +88,7 @@ static int print_gaih_addrtuples(const struct gaih_addrtuple *tuples) {
|
|||
if (it->scopeid == 0)
|
||||
goto numerical_index;
|
||||
|
||||
if (if_indextoname(it->scopeid, ifname) == NULL) {
|
||||
if (!if_indextoname(it->scopeid, ifname)) {
|
||||
log_warning_errno(errno, "if_indextoname(%d) failed: %m", it->scopeid);
|
||||
numerical_index:
|
||||
xsprintf(ifname, "%i", it->scopeid);
|
||||
|
|
|
@ -1024,7 +1024,7 @@ static int manager_network_event_handler(sd_event_source *s, int fd, uint32_t re
|
|||
sd_network_monitor_flush(m->network_monitor);
|
||||
|
||||
/* When manager_network_read_link_servers() failed, we assume that the servers are changed. */
|
||||
changed = !!manager_network_read_link_servers(m);
|
||||
changed = manager_network_read_link_servers(m);
|
||||
|
||||
/* check if the machine is online */
|
||||
online = network_is_online();
|
||||
|
|
|
@ -2397,7 +2397,7 @@ static int specifier_expansion_from_arg(Item *i) {
|
|||
|
||||
assert(i);
|
||||
|
||||
if (i->argument == NULL)
|
||||
if (!i->argument)
|
||||
return 0;
|
||||
|
||||
switch (i->type) {
|
||||
|
|
|
@ -381,7 +381,7 @@ static int disk_identify(int fd,
|
|||
}
|
||||
|
||||
out:
|
||||
if (out_is_packet_device != NULL)
|
||||
if (out_is_packet_device)
|
||||
*out_is_packet_device = is_packet_device;
|
||||
return ret;
|
||||
}
|
||||
|
@ -432,7 +432,7 @@ int main(int argc, char *argv[]) {
|
|||
}
|
||||
|
||||
node = argv[optind];
|
||||
if (node == NULL) {
|
||||
if (!node) {
|
||||
log_error("no node specified");
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -95,7 +95,7 @@ static bool is_mounted(const char *device) {
|
|||
return false;
|
||||
|
||||
fp = fopen("/proc/self/mountinfo", "re");
|
||||
if (fp == NULL)
|
||||
if (!fp)
|
||||
return false;
|
||||
while (fscanf(fp, "%*s %*s %i:%i %*[^\n]", &maj, &min) == 2) {
|
||||
if (makedev(maj, min) == statbuf.st_rdev) {
|
||||
|
@ -203,8 +203,7 @@ static int cd_capability_compat(int fd) {
|
|||
|
||||
capability = ioctl(fd, CDROM_GET_CAPABILITY, NULL);
|
||||
if (capability < 0) {
|
||||
log_debug("CDROM_GET_CAPABILITY failed");
|
||||
return -1;
|
||||
return log_debug_errno(errno, "CDROM_GET_CAPABILITY failed");
|
||||
}
|
||||
|
||||
if (capability & CDC_CD_R)
|
||||
|
@ -226,8 +225,7 @@ static int cd_capability_compat(int fd) {
|
|||
|
||||
static int cd_media_compat(int fd) {
|
||||
if (ioctl(fd, CDROM_DRIVE_STATUS, CDSL_CURRENT) != CDS_DISC_OK) {
|
||||
log_debug("CDROM_DRIVE_STATUS != CDS_DISC_OK");
|
||||
return -1;
|
||||
return log_debug_errno(errno, "CDROM_DRIVE_STATUS != CDS_DISC_OK");
|
||||
}
|
||||
cd_media = 1;
|
||||
return 0;
|
||||
|
@ -249,8 +247,7 @@ static int cd_inquiry(int fd) {
|
|||
}
|
||||
|
||||
if ((inq[0] & 0x1F) != 5) {
|
||||
log_debug("not an MMC unit");
|
||||
return -1;
|
||||
return log_debug_errno(SYNTHETIC_ERRNO(EINVAL), "not an MMC unit");
|
||||
}
|
||||
|
||||
log_debug("INQUIRY: [%.8s][%.16s][%.4s]", inq + 8, inq + 16, inq + 32);
|
||||
|
@ -474,8 +471,8 @@ static int cd_profiles_old_mmc(int fd) {
|
|||
cd_media_track_count_data = 1;
|
||||
return 0;
|
||||
} else {
|
||||
log_debug("no current profile, assuming no media");
|
||||
return -1;
|
||||
return log_debug_errno(SYNTHETIC_ERRNO(ENOMEDIUM),
|
||||
"no current profile, assuming no media");
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -660,8 +657,8 @@ static int cd_media_info(int fd) {
|
|||
|
||||
len = format[3];
|
||||
if (len & 7 || len < 16) {
|
||||
log_debug("invalid format capacities length");
|
||||
return -1;
|
||||
return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||
"invalid format capacities length");
|
||||
}
|
||||
|
||||
switch(format[8] & 3) {
|
||||
|
@ -680,8 +677,8 @@ static int cd_media_info(int fd) {
|
|||
|
||||
case 3:
|
||||
cd_media = 0; //return no media
|
||||
log_debug("format capacities returned no media");
|
||||
return -1;
|
||||
return log_debug_errno(SYNTHETIC_ERRNO(ENOMEDIUM),
|
||||
"format capacities returned no media");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1026,7 +1023,7 @@ work:
|
|||
if (cd_media_hddvd_rw)
|
||||
printf("ID_CDROM_MEDIA_HDDVD_RW=1\n");
|
||||
|
||||
if (cd_media_state != NULL)
|
||||
if (cd_media_state)
|
||||
printf("ID_CDROM_MEDIA_STATE=%s\n", cd_media_state);
|
||||
if (cd_media_session_next > 0)
|
||||
printf("ID_CDROM_MEDIA_SESSION_NEXT=%u\n", cd_media_session_next);
|
||||
|
|
|
@ -157,7 +157,7 @@ static int get_file_options(const char *vendor, const char *model,
|
|||
int retval = 0;
|
||||
|
||||
f = fopen(config_file, "re");
|
||||
if (f == NULL) {
|
||||
if (!f) {
|
||||
if (errno == ENOENT)
|
||||
return 1;
|
||||
else {
|
||||
|
@ -181,7 +181,7 @@ static int get_file_options(const char *vendor, const char *model,
|
|||
vendor_in = model_in = options_in = NULL;
|
||||
|
||||
buf = fgets(buffer, MAX_BUFFER_LEN, f);
|
||||
if (buf == NULL)
|
||||
if (!buf)
|
||||
break;
|
||||
lineno++;
|
||||
if (buf[strlen(buffer) - 1] != '\n') {
|
||||
|
@ -239,7 +239,7 @@ static int get_file_options(const char *vendor, const char *model,
|
|||
break;
|
||||
}
|
||||
if (vendor == NULL) {
|
||||
if (vendor_in == NULL)
|
||||
if (!vendor_in)
|
||||
break;
|
||||
} else if (vendor_in &&
|
||||
startswith(vendor, vendor_in) &&
|
||||
|
@ -347,16 +347,18 @@ static int set_options(int argc, char **argv,
|
|||
else if (streq(optarg, "pre-spc3-83"))
|
||||
default_page_code = PAGE_83_PRE_SPC3;
|
||||
else {
|
||||
log_error("Unknown page code '%s'", optarg);
|
||||
return -1;
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||
"Unknown page code '%s'",
|
||||
optarg);
|
||||
}
|
||||
break;
|
||||
|
||||
case 's':
|
||||
sg_version = atoi(optarg);
|
||||
if (sg_version < 3 || sg_version > 4) {
|
||||
log_error("Unknown SG version '%s'", optarg);
|
||||
return -1;
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||
"Unknown SG version '%s'",
|
||||
optarg);
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
|
@ -169,8 +169,9 @@ static int scsi_dump_sense(struct scsi_id_device *dev_scsi,
|
|||
*/
|
||||
|
||||
if (sb_len < 1) {
|
||||
log_debug("%s: sense buffer empty", dev_scsi->kernel);
|
||||
return -1;
|
||||
return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||
"%s: sense buffer empty",
|
||||
dev_scsi->kernel);
|
||||
}
|
||||
|
||||
sense_class = (sense_buffer[0] >> 4) & 0x07;
|
||||
|
@ -182,9 +183,10 @@ static int scsi_dump_sense(struct scsi_id_device *dev_scsi,
|
|||
*/
|
||||
s = sense_buffer[7] + 8;
|
||||
if (sb_len < s) {
|
||||
log_debug("%s: sense buffer too small %d bytes, %d bytes too short",
|
||||
dev_scsi->kernel, sb_len, s - sb_len);
|
||||
return -1;
|
||||
return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||
"%s: sense buffer too small %d bytes, %d bytes too short",
|
||||
dev_scsi->kernel, sb_len,
|
||||
s - sb_len);
|
||||
}
|
||||
if (IN_SET(code, 0x0, 0x1)) {
|
||||
sense_key = sense_buffer[2] & 0xf;
|
||||
|
@ -192,9 +194,9 @@ static int scsi_dump_sense(struct scsi_id_device *dev_scsi,
|
|||
/*
|
||||
* Possible?
|
||||
*/
|
||||
log_debug("%s: sense result too" " small %d bytes",
|
||||
dev_scsi->kernel, s);
|
||||
return -1;
|
||||
return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||
"%s: sense result too small %d bytes",
|
||||
dev_scsi->kernel, s);
|
||||
}
|
||||
asc = sense_buffer[12];
|
||||
ascq = sense_buffer[13];
|
||||
|
@ -203,17 +205,18 @@ static int scsi_dump_sense(struct scsi_id_device *dev_scsi,
|
|||
asc = sense_buffer[2];
|
||||
ascq = sense_buffer[3];
|
||||
} else {
|
||||
log_debug("%s: invalid sense code 0x%x",
|
||||
dev_scsi->kernel, code);
|
||||
return -1;
|
||||
return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||
"%s: invalid sense code 0x%x",
|
||||
dev_scsi->kernel, code);
|
||||
}
|
||||
log_debug("%s: sense key 0x%x ASC 0x%x ASCQ 0x%x",
|
||||
dev_scsi->kernel, sense_key, asc, ascq);
|
||||
} else {
|
||||
if (sb_len < 4) {
|
||||
log_debug("%s: sense buffer too small %d bytes, %d bytes too short",
|
||||
dev_scsi->kernel, sb_len, 4 - sb_len);
|
||||
return -1;
|
||||
return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||
"%s: sense buffer too small %d bytes, %d bytes too short",
|
||||
dev_scsi->kernel, sb_len,
|
||||
4 - sb_len);
|
||||
}
|
||||
|
||||
if (sense_buffer[0] < 15)
|
||||
|
@ -235,8 +238,9 @@ static int scsi_dump(struct scsi_id_device *dev_scsi, struct sg_io_hdr *io) {
|
|||
/*
|
||||
* Impossible, should not be called.
|
||||
*/
|
||||
log_debug("%s: called with no error", __FUNCTION__);
|
||||
return -1;
|
||||
return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||
"%s: called with no error",
|
||||
__FUNCTION__);
|
||||
}
|
||||
|
||||
log_debug("%s: sg_io failed status 0x%x 0x%x 0x%x 0x%x",
|
||||
|
@ -253,8 +257,9 @@ static int scsi_dump_v4(struct scsi_id_device *dev_scsi, struct sg_io_v4 *io) {
|
|||
/*
|
||||
* Impossible, should not be called.
|
||||
*/
|
||||
log_debug("%s: called with no error", __FUNCTION__);
|
||||
return -1;
|
||||
return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||
"%s: called with no error",
|
||||
__FUNCTION__);
|
||||
}
|
||||
|
||||
log_debug("%s: sg_io failed status 0x%x 0x%x 0x%x",
|
||||
|
@ -279,8 +284,8 @@ static int scsi_inquiry(struct scsi_id_device *dev_scsi, int fd,
|
|||
int retval;
|
||||
|
||||
if (buflen > SCSI_INQ_BUFF_LEN) {
|
||||
log_debug("buflen %d too long", buflen);
|
||||
return -1;
|
||||
return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||
"buflen %d too long", buflen);
|
||||
}
|
||||
|
||||
resend:
|
||||
|
@ -412,9 +417,10 @@ static int prepend_vendor_model(struct scsi_id_device *dev_scsi, char *serial) {
|
|||
* above, ind will never be too large.
|
||||
*/
|
||||
if (ind != (VENDOR_LENGTH + MODEL_LENGTH)) {
|
||||
log_debug("%s: expected length %d, got length %d",
|
||||
dev_scsi->kernel, (VENDOR_LENGTH + MODEL_LENGTH), ind);
|
||||
return -1;
|
||||
return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||
"%s: expected length %d, got length %d",
|
||||
dev_scsi->kernel,
|
||||
(VENDOR_LENGTH + MODEL_LENGTH), ind);
|
||||
}
|
||||
return ind;
|
||||
}
|
||||
|
@ -524,7 +530,7 @@ static int check_fill_0x83_id(struct scsi_id_device *dev_scsi,
|
|||
|
||||
if (id_search->id_type == SCSI_ID_NAA && wwn != NULL) {
|
||||
strncpy(wwn, &serial[s], 16);
|
||||
if (wwn_vendor_extension != NULL)
|
||||
if (wwn_vendor_extension)
|
||||
strncpy(wwn_vendor_extension, &serial[s + 16], 16);
|
||||
}
|
||||
|
||||
|
@ -729,7 +735,7 @@ static int do_scsi_page80_inquiry(struct scsi_id_device *dev_scsi, int fd,
|
|||
* specific type where we prepend '0' + vendor + model.
|
||||
*/
|
||||
len = buf[3];
|
||||
if (serial != NULL) {
|
||||
if (serial) {
|
||||
serial[0] = 'S';
|
||||
ser_ind = prepend_vendor_model(dev_scsi, &serial[1]);
|
||||
if (ser_ind < 0)
|
||||
|
@ -738,7 +744,7 @@ static int do_scsi_page80_inquiry(struct scsi_id_device *dev_scsi, int fd,
|
|||
for (i = 4; i < len + 4; i++, ser_ind++)
|
||||
serial[ser_ind] = buf[i];
|
||||
}
|
||||
if (serial_short != NULL) {
|
||||
if (serial_short) {
|
||||
memcpy(serial_short, &buf[4], len);
|
||||
serial_short[len] = '\0';
|
||||
}
|
||||
|
|
|
@ -196,7 +196,7 @@ static int dev_if_packed_info(sd_device *dev, char *ifs_str, size_t len) {
|
|||
desc->bInterfaceProtocol) != 7)
|
||||
continue;
|
||||
|
||||
if (strstr(ifs_str, if_str) != NULL)
|
||||
if (strstr(ifs_str, if_str))
|
||||
continue;
|
||||
|
||||
memcpy(&ifs_str[strpos], if_str, 8),
|
||||
|
|
|
@ -56,7 +56,7 @@ int main(int argc, char *argv[]) {
|
|||
}
|
||||
|
||||
device = argv[optind];
|
||||
if (device == NULL)
|
||||
if (!device)
|
||||
return 2;
|
||||
|
||||
fd = open(device, O_RDONLY);
|
||||
|
|
Loading…
Reference in New Issue