1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-12-22 13:33:56 +03:00

tree-wide: code improvements suggested by Coccinelle

This commit is contained in:
Frantisek Sumsal 2019-04-29 18:22:22 +02:00
parent 4a4eaade60
commit ed0cb34682
11 changed files with 57 additions and 52 deletions

View File

@ -59,7 +59,7 @@ int main(int argc, char **argv) {
vtable, vtable,
&object)); &object));
while (true) { for (;;) {
check(sd_bus_wait(bus, UINT64_MAX)); check(sd_bus_wait(bus, UINT64_MAX));
check(sd_bus_process(bus, NULL)); check(sd_bus_process(bus, NULL));
} }

View File

@ -303,8 +303,12 @@ static int bus_socket_set_transient_property(
if (streq(name, "SocketProtocol")) if (streq(name, "SocketProtocol"))
return bus_set_transient_socket_protocol(u, name, &s->socket_protocol, message, flags, error); return bus_set_transient_socket_protocol(u, name, &s->socket_protocol, message, flags, error);
if ((ci = socket_exec_command_from_string(name)) >= 0) ci = socket_exec_command_from_string(name);
return bus_set_transient_exec_command(u, name, &s->exec_command[ci], message, flags, error); if (ci >= 0)
return bus_set_transient_exec_command(u, name,
&s->exec_command[ci],
message, flags, error);
if (streq(name, "Symlinks")) { if (streq(name, "Symlinks")) {
_cleanup_strv_free_ char **l = NULL; _cleanup_strv_free_ char **l = NULL;

View File

@ -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 * (truncated) copy of what we want to send, and the second one
* contains the trailing dots. */ * contains the trailing dots. */
copy[0] = iovec[i]; copy[0] = iovec[i];
copy[1] = (struct iovec) { copy[1] = IOVEC_MAKE(((char[]){'.', '.', '.'}), 3);
.iov_base = (char[]) { '.', '.', '.' },
.iov_len = 3,
};
mh.msg_iov = copy; mh.msg_iov = copy;
mh.msg_iovlen = 2; mh.msg_iovlen = 2;

View File

@ -250,7 +250,7 @@ static void transfer_send_logs(Transfer *t, bool flush) {
n = strndup(t->log_message, e - t->log_message); n = strndup(t->log_message, e - t->log_message);
/* Skip over NUL and newlines */ /* 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++; e++;
memmove(t->log_message, e, t->log_message + sizeof(t->log_message) - e); memmove(t->log_message, e, t->log_message + sizeof(t->log_message) - e);

View File

@ -693,8 +693,7 @@ bool manager_all_buttons_ignored(Manager *m) {
return false; return false;
if (m->handle_lid_switch != HANDLE_IGNORE) if (m->handle_lid_switch != HANDLE_IGNORE)
return false; return false;
if (m->handle_lid_switch_ep != _HANDLE_ACTION_INVALID && if (!IN_SET(m->handle_lid_switch_ep, _HANDLE_ACTION_INVALID, HANDLE_IGNORE))
m->handle_lid_switch_ep != HANDLE_IGNORE)
return false; return false;
if (m->handle_lid_switch_docked != HANDLE_IGNORE) if (m->handle_lid_switch_docked != HANDLE_IGNORE)
return false; return false;

View File

@ -754,7 +754,7 @@ void user_update_last_session_timer(User *u) {
assert(!u->timer_event_source); 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; return;
if (sd_event_get_state(u->manager->event) == SD_EVENT_FINISHED) { if (sd_event_get_state(u->manager->event) == SD_EVENT_FINISHED) {

View File

@ -37,7 +37,7 @@ int dns_label_unescape(const char **name, char *dest, size_t sz, DNSLabelFlags f
d = dest; d = dest;
for (;;) { for (;;) {
if (*n == 0 || *n == '.') { if (IN_SET(*n, 0, '.')) {
if (FLAGS_SET(flags, DNS_LABEL_LDH) && last_char == '-') if (FLAGS_SET(flags, DNS_LABEL_LDH) && last_char == '-')
/* Trailing dash */ /* Trailing dash */
return -EINVAL; return -EINVAL;

View File

@ -395,7 +395,7 @@ static int image_make(
if (r < 0) if (r < 0)
return r; 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; (*ret)->usage = (*ret)->usage_exclusive = (*ret)->limit = (*ret)->limit_exclusive = size;
return 0; return 0;

View File

@ -203,8 +203,7 @@ static int cd_capability_compat(int fd) {
capability = ioctl(fd, CDROM_GET_CAPABILITY, NULL); capability = ioctl(fd, CDROM_GET_CAPABILITY, NULL);
if (capability < 0) { if (capability < 0) {
log_debug("CDROM_GET_CAPABILITY failed"); return log_debug_errno(errno, "CDROM_GET_CAPABILITY failed");
return -1;
} }
if (capability & CDC_CD_R) if (capability & CDC_CD_R)
@ -226,8 +225,7 @@ static int cd_capability_compat(int fd) {
static int cd_media_compat(int fd) { static int cd_media_compat(int fd) {
if (ioctl(fd, CDROM_DRIVE_STATUS, CDSL_CURRENT) != CDS_DISC_OK) { if (ioctl(fd, CDROM_DRIVE_STATUS, CDSL_CURRENT) != CDS_DISC_OK) {
log_debug("CDROM_DRIVE_STATUS != CDS_DISC_OK"); return log_debug_errno(errno, "CDROM_DRIVE_STATUS != CDS_DISC_OK");
return -1;
} }
cd_media = 1; cd_media = 1;
return 0; return 0;
@ -249,8 +247,7 @@ static int cd_inquiry(int fd) {
} }
if ((inq[0] & 0x1F) != 5) { if ((inq[0] & 0x1F) != 5) {
log_debug("not an MMC unit"); return log_debug_errno(SYNTHETIC_ERRNO(EINVAL), "not an MMC unit");
return -1;
} }
log_debug("INQUIRY: [%.8s][%.16s][%.4s]", inq + 8, inq + 16, inq + 32); 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; cd_media_track_count_data = 1;
return 0; return 0;
} else { } else {
log_debug("no current profile, assuming no media"); return log_debug_errno(SYNTHETIC_ERRNO(ENOMEDIUM),
return -1; "no current profile, assuming no media");
} }
}; };
@ -660,8 +657,8 @@ static int cd_media_info(int fd) {
len = format[3]; len = format[3];
if (len & 7 || len < 16) { if (len & 7 || len < 16) {
log_debug("invalid format capacities length"); return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
return -1; "invalid format capacities length");
} }
switch(format[8] & 3) { switch(format[8] & 3) {
@ -680,8 +677,8 @@ static int cd_media_info(int fd) {
case 3: case 3:
cd_media = 0; //return no media cd_media = 0; //return no media
log_debug("format capacities returned no media"); return log_debug_errno(SYNTHETIC_ERRNO(ENOMEDIUM),
return -1; "format capacities returned no media");
} }
} }

View File

@ -347,16 +347,18 @@ static int set_options(int argc, char **argv,
else if (streq(optarg, "pre-spc3-83")) else if (streq(optarg, "pre-spc3-83"))
default_page_code = PAGE_83_PRE_SPC3; default_page_code = PAGE_83_PRE_SPC3;
else { else {
log_error("Unknown page code '%s'", optarg); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -1; "Unknown page code '%s'",
optarg);
} }
break; break;
case 's': case 's':
sg_version = atoi(optarg); sg_version = atoi(optarg);
if (sg_version < 3 || sg_version > 4) { if (sg_version < 3 || sg_version > 4) {
log_error("Unknown SG version '%s'", optarg); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -1; "Unknown SG version '%s'",
optarg);
} }
break; break;

View File

@ -169,8 +169,9 @@ static int scsi_dump_sense(struct scsi_id_device *dev_scsi,
*/ */
if (sb_len < 1) { if (sb_len < 1) {
log_debug("%s: sense buffer empty", dev_scsi->kernel); return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
return -1; "%s: sense buffer empty",
dev_scsi->kernel);
} }
sense_class = (sense_buffer[0] >> 4) & 0x07; 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; s = sense_buffer[7] + 8;
if (sb_len < s) { if (sb_len < s) {
log_debug("%s: sense buffer too small %d bytes, %d bytes too short", return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
dev_scsi->kernel, sb_len, s - sb_len); "%s: sense buffer too small %d bytes, %d bytes too short",
return -1; dev_scsi->kernel, sb_len,
s - sb_len);
} }
if (IN_SET(code, 0x0, 0x1)) { if (IN_SET(code, 0x0, 0x1)) {
sense_key = sense_buffer[2] & 0xf; sense_key = sense_buffer[2] & 0xf;
@ -192,9 +194,9 @@ static int scsi_dump_sense(struct scsi_id_device *dev_scsi,
/* /*
* Possible? * Possible?
*/ */
log_debug("%s: sense result too" " small %d bytes", return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
dev_scsi->kernel, s); "%s: sense result too small %d bytes",
return -1; dev_scsi->kernel, s);
} }
asc = sense_buffer[12]; asc = sense_buffer[12];
ascq = sense_buffer[13]; ascq = sense_buffer[13];
@ -203,17 +205,18 @@ static int scsi_dump_sense(struct scsi_id_device *dev_scsi,
asc = sense_buffer[2]; asc = sense_buffer[2];
ascq = sense_buffer[3]; ascq = sense_buffer[3];
} else { } else {
log_debug("%s: invalid sense code 0x%x", return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
dev_scsi->kernel, code); "%s: invalid sense code 0x%x",
return -1; dev_scsi->kernel, code);
} }
log_debug("%s: sense key 0x%x ASC 0x%x ASCQ 0x%x", log_debug("%s: sense key 0x%x ASC 0x%x ASCQ 0x%x",
dev_scsi->kernel, sense_key, asc, ascq); dev_scsi->kernel, sense_key, asc, ascq);
} else { } else {
if (sb_len < 4) { if (sb_len < 4) {
log_debug("%s: sense buffer too small %d bytes, %d bytes too short", return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
dev_scsi->kernel, sb_len, 4 - sb_len); "%s: sense buffer too small %d bytes, %d bytes too short",
return -1; dev_scsi->kernel, sb_len,
4 - sb_len);
} }
if (sense_buffer[0] < 15) 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. * Impossible, should not be called.
*/ */
log_debug("%s: called with no error", __FUNCTION__); return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
return -1; "%s: called with no error",
__FUNCTION__);
} }
log_debug("%s: sg_io failed status 0x%x 0x%x 0x%x 0x%x", 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. * Impossible, should not be called.
*/ */
log_debug("%s: called with no error", __FUNCTION__); return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
return -1; "%s: called with no error",
__FUNCTION__);
} }
log_debug("%s: sg_io failed status 0x%x 0x%x 0x%x", 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; int retval;
if (buflen > SCSI_INQ_BUFF_LEN) { if (buflen > SCSI_INQ_BUFF_LEN) {
log_debug("buflen %d too long", buflen); return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
return -1; "buflen %d too long", buflen);
} }
resend: 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. * above, ind will never be too large.
*/ */
if (ind != (VENDOR_LENGTH + MODEL_LENGTH)) { if (ind != (VENDOR_LENGTH + MODEL_LENGTH)) {
log_debug("%s: expected length %d, got length %d", return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
dev_scsi->kernel, (VENDOR_LENGTH + MODEL_LENGTH), ind); "%s: expected length %d, got length %d",
return -1; dev_scsi->kernel,
(VENDOR_LENGTH + MODEL_LENGTH), ind);
} }
return ind; return ind;
} }