clang-tidy: do not use else after return
Found with readability-else-after-return Signed-off-by: Rosen Penev <rosenp@gmail.com>pull/250/head
parent
5a93509655
commit
17a5fe6022
|
|
@ -359,8 +359,7 @@ int get_date(struct timeval *tv, char *date) {
|
||||||
before parsing the real year value (hack) */
|
before parsing the real year value (hack) */
|
||||||
if (!strptime(date, "%B %d %I:%M:%S.%Y %p %Y", &tms))
|
if (!strptime(date, "%B %d %I:%M:%S.%Y %p %Y", &tms))
|
||||||
return 1;
|
return 1;
|
||||||
else
|
sscanf(date, "%*s %*d %*d:%*d:%*d.%3u ", &msecs);
|
||||||
sscanf(date, "%*s %*d %*d:%*d:%*d.%3u ", &msecs);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -377,11 +376,10 @@ int get_date(struct timeval *tv, char *date) {
|
||||||
before parsing the real year value (hack) */
|
before parsing the real year value (hack) */
|
||||||
if (!strptime(date, "%B %d %H:%M:%S.%Y %Y", &tms))
|
if (!strptime(date, "%B %d %H:%M:%S.%Y %Y", &tms))
|
||||||
return 1;
|
return 1;
|
||||||
else
|
sscanf(date, "%*s %*d %*d:%*d:%*d.%3u ", &msecs);
|
||||||
sscanf(date, "%*s %*d %*d:%*d:%*d.%3u ", &msecs);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//printf("h %d m %d s %d ms %03d d %d m %d y %d\n",
|
//printf("h %d m %d s %d ms %03d d %d m %d y %d\n",
|
||||||
//tms.tm_hour, tms.tm_min, tms.tm_sec, msecs,
|
//tms.tm_hour, tms.tm_min, tms.tm_sec, msecs,
|
||||||
//tms.tm_mday, tms.tm_mon+1, tms.tm_year+1900);
|
//tms.tm_mday, tms.tm_mon+1, tms.tm_year+1900);
|
||||||
|
|
|
||||||
42
canfdtest.c
42
canfdtest.c
|
|
@ -181,20 +181,18 @@ static int send_frame(struct can_frame *frame)
|
||||||
|
|
||||||
while ((ret = send(sockfd, frame, sizeof(*frame), 0))
|
while ((ret = send(sockfd, frame, sizeof(*frame), 0))
|
||||||
!= sizeof(*frame)) {
|
!= sizeof(*frame)) {
|
||||||
if (ret < 0) {
|
if (ret >= 0) {
|
||||||
if (errno != ENOBUFS) {
|
|
||||||
perror("send failed");
|
|
||||||
return -1;
|
|
||||||
} else {
|
|
||||||
if (verbose) {
|
|
||||||
printf("N");
|
|
||||||
fflush(stdout);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
fprintf(stderr, "send returned %d", ret);
|
fprintf(stderr, "send returned %d", ret);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
if (errno != ENOBUFS) {
|
||||||
|
perror("send failed");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (verbose) {
|
||||||
|
printf("N");
|
||||||
|
fflush(stdout);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -332,19 +330,19 @@ static int can_echo_gen(void)
|
||||||
if (recv_tx_pos == inflight_count)
|
if (recv_tx_pos == inflight_count)
|
||||||
recv_tx_pos = 0;
|
recv_tx_pos = 0;
|
||||||
continue;
|
continue;
|
||||||
} else {
|
|
||||||
if (!recv_tx[recv_rx_pos]) {
|
|
||||||
printf("RX before TX!\n");
|
|
||||||
print_frame(&rx_frame, 0);
|
|
||||||
running = 0;
|
|
||||||
}
|
|
||||||
/* compare with expected */
|
|
||||||
compare_frame(&tx_frames[recv_rx_pos], &rx_frame, 1);
|
|
||||||
recv_rx_pos++;
|
|
||||||
if (recv_rx_pos == inflight_count)
|
|
||||||
recv_rx_pos = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!recv_tx[recv_rx_pos]) {
|
||||||
|
printf("RX before TX!\n");
|
||||||
|
print_frame(&rx_frame, 0);
|
||||||
|
running = 0;
|
||||||
|
}
|
||||||
|
/* compare with expected */
|
||||||
|
compare_frame(&tx_frames[recv_rx_pos], &rx_frame, 1);
|
||||||
|
recv_rx_pos++;
|
||||||
|
if (recv_rx_pos == inflight_count)
|
||||||
|
recv_rx_pos = 0;
|
||||||
|
|
||||||
loops++;
|
loops++;
|
||||||
if (test_loops && loops >= test_loops)
|
if (test_loops && loops >= test_loops)
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
4
cangen.c
4
cangen.c
|
|
@ -468,8 +468,8 @@ resend:
|
||||||
if (poll(&fds, 1, polltimeout) < 0) {
|
if (poll(&fds, 1, polltimeout) < 0) {
|
||||||
perror("poll");
|
perror("poll");
|
||||||
return 1;
|
return 1;
|
||||||
} else
|
}
|
||||||
goto resend;
|
goto resend;
|
||||||
} else
|
} else
|
||||||
enobufs_count++;
|
enobufs_count++;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -300,15 +300,14 @@ int main(int argc, char **argv)
|
||||||
//printf("accepted\n");
|
//printf("accepted\n");
|
||||||
if (!fork())
|
if (!fork())
|
||||||
break;
|
break;
|
||||||
else
|
close(accsocket);
|
||||||
close(accsocket);
|
|
||||||
}
|
}
|
||||||
else if (errno != EINTR) {
|
else if (errno != EINTR) {
|
||||||
perror("accept");
|
perror("accept");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i=0; i<currmax; i++) {
|
for (i=0; i<currmax; i++) {
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
|
|
||||||
98
isotpdump.c
98
isotpdump.c
|
|
@ -335,65 +335,66 @@ int main(int argc, char **argv)
|
||||||
if (nbytes < 0) {
|
if (nbytes < 0) {
|
||||||
perror("read");
|
perror("read");
|
||||||
return 1;
|
return 1;
|
||||||
} else if (nbytes != CAN_MTU && nbytes != CANFD_MTU) {
|
}
|
||||||
|
if (nbytes != CAN_MTU && nbytes != CANFD_MTU) {
|
||||||
fprintf(stderr, "read: incomplete CAN frame %zu %d\n", sizeof(frame), nbytes);
|
fprintf(stderr, "read: incomplete CAN frame %zu %d\n", sizeof(frame), nbytes);
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
}
|
||||||
|
if (frame.can_id == src && ext && !extany &&
|
||||||
|
extaddr != frame.data[0])
|
||||||
|
continue;
|
||||||
|
|
||||||
if (frame.can_id == src && ext && !extany && extaddr != frame.data[0])
|
if (frame.can_id == dst && rx_ext && !rx_extany &&
|
||||||
continue;
|
rx_extaddr != frame.data[0])
|
||||||
|
continue;
|
||||||
|
|
||||||
if (frame.can_id == dst && rx_ext && !rx_extany && rx_extaddr != frame.data[0])
|
if (color)
|
||||||
continue;
|
printf("%s", (frame.can_id == src) ? FGRED : FGBLUE);
|
||||||
|
|
||||||
if (color)
|
if (timestamp) {
|
||||||
printf("%s", (frame.can_id == src)? FGRED:FGBLUE);
|
ioctl(s, SIOCGSTAMP, &tv);
|
||||||
|
|
||||||
if (timestamp) {
|
switch (timestamp) {
|
||||||
ioctl(s, SIOCGSTAMP, &tv);
|
case 'a': /* absolute with timestamp */
|
||||||
|
printf("(%lu.%06lu) ", tv.tv_sec, tv.tv_usec);
|
||||||
|
|
||||||
switch (timestamp) {
|
|
||||||
|
|
||||||
case 'a': /* absolute with timestamp */
|
|
||||||
printf("(%lu.%06lu) ", tv.tv_sec, tv.tv_usec);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'A': /* absolute with date */
|
|
||||||
{
|
|
||||||
struct tm tm;
|
|
||||||
char timestring[25];
|
|
||||||
|
|
||||||
tm = *localtime(&tv.tv_sec);
|
|
||||||
strftime(timestring, 24, "%Y-%m-%d %H:%M:%S", &tm);
|
|
||||||
printf("(%s.%06lu) ", timestring, tv.tv_usec);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'd': /* delta */
|
case 'A': /* absolute with date */
|
||||||
case 'z': /* starting with zero */
|
{
|
||||||
{
|
struct tm tm;
|
||||||
struct timeval diff;
|
char timestring[25];
|
||||||
|
|
||||||
if (last_tv.tv_sec == 0) /* first init */
|
tm = *localtime(&tv.tv_sec);
|
||||||
last_tv = tv;
|
strftime(timestring, 24, "%Y-%m-%d %H:%M:%S",
|
||||||
diff.tv_sec = tv.tv_sec - last_tv.tv_sec;
|
&tm);
|
||||||
diff.tv_usec = tv.tv_usec - last_tv.tv_usec;
|
printf("(%s.%06lu) ", timestring, tv.tv_usec);
|
||||||
if (diff.tv_usec < 0)
|
} break;
|
||||||
diff.tv_sec--, diff.tv_usec += 1000000;
|
|
||||||
if (diff.tv_sec < 0)
|
|
||||||
diff.tv_sec = diff.tv_usec = 0;
|
|
||||||
printf("(%lu.%06lu) ", diff.tv_sec, diff.tv_usec);
|
|
||||||
|
|
||||||
if (timestamp == 'd')
|
case 'd': /* delta */
|
||||||
last_tv = tv; /* update for delta calculation */
|
case 'z': /* starting with zero */
|
||||||
}
|
{
|
||||||
|
struct timeval diff;
|
||||||
|
|
||||||
|
if (last_tv.tv_sec == 0) /* first init */
|
||||||
|
last_tv = tv;
|
||||||
|
diff.tv_sec = tv.tv_sec - last_tv.tv_sec;
|
||||||
|
diff.tv_usec = tv.tv_usec - last_tv.tv_usec;
|
||||||
|
if (diff.tv_usec < 0)
|
||||||
|
diff.tv_sec--, diff.tv_usec += 1000000;
|
||||||
|
if (diff.tv_sec < 0)
|
||||||
|
diff.tv_sec = diff.tv_usec = 0;
|
||||||
|
printf("(%lu.%06lu) ", diff.tv_sec,
|
||||||
|
diff.tv_usec);
|
||||||
|
|
||||||
|
if (timestamp == 'd')
|
||||||
|
last_tv =
|
||||||
|
tv; /* update for delta calculation */
|
||||||
|
} break;
|
||||||
|
|
||||||
|
default: /* no timestamp output */
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default: /* no timestamp output */
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (frame.can_id & CAN_EFF_FLAG)
|
if (frame.can_id & CAN_EFF_FLAG)
|
||||||
printf(" %s %8X", argv[optind], frame.can_id & CAN_EFF_MASK);
|
printf(" %s %8X", argv[optind], frame.can_id & CAN_EFF_MASK);
|
||||||
|
|
@ -410,7 +411,7 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
datidx = 0;
|
datidx = 0;
|
||||||
n_pci = frame.data[ext];
|
n_pci = frame.data[ext];
|
||||||
|
|
||||||
switch (n_pci & 0xF0) {
|
switch (n_pci & 0xF0) {
|
||||||
case 0x00:
|
case 0x00:
|
||||||
is_ff = 1;
|
is_ff = 1;
|
||||||
|
|
@ -501,7 +502,6 @@ int main(int argc, char **argv)
|
||||||
printf("%s", ATTRESET);
|
printf("%s", ATTRESET);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
close(s);
|
close(s);
|
||||||
|
|
|
||||||
25
isotpperf.c
25
isotpperf.c
|
|
@ -223,19 +223,21 @@ int main(int argc, char **argv)
|
||||||
ret = nbytes;
|
ret = nbytes;
|
||||||
running = 0;
|
running = 0;
|
||||||
continue;
|
continue;
|
||||||
} else if (nbytes != CAN_MTU && nbytes != CANFD_MTU) {
|
}
|
||||||
|
if (nbytes != CAN_MTU && nbytes != CANFD_MTU) {
|
||||||
fprintf(stderr, "read: incomplete CAN frame %zu %d\n", sizeof(frame), nbytes);
|
fprintf(stderr, "read: incomplete CAN frame %zu %d\n", sizeof(frame), nbytes);
|
||||||
ret = nbytes;
|
ret = nbytes;
|
||||||
running = 0;
|
running = 0;
|
||||||
continue;
|
continue;
|
||||||
} else {
|
}
|
||||||
if (rcvlen) {
|
|
||||||
/* make sure to process only the detected PDU CAN frame type */
|
if (rcvlen) {
|
||||||
if (canfd_on && (nbytes != CANFD_MTU))
|
/* make sure to process only the detected PDU CAN frame type */
|
||||||
continue;
|
if (canfd_on && (nbytes != CANFD_MTU))
|
||||||
if (!canfd_on && (nbytes != CAN_MTU))
|
continue;
|
||||||
continue;
|
if (!canfd_on && (nbytes != CAN_MTU))
|
||||||
}
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
/* check extended address if provided */
|
/* check extended address if provided */
|
||||||
if (ext && extaddr != frame.data[0])
|
if (ext && extaddr != frame.data[0])
|
||||||
|
|
@ -255,7 +257,7 @@ int main(int argc, char **argv)
|
||||||
} else
|
} else
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* data content starts and index datidx */
|
/* data content starts and index datidx */
|
||||||
datidx = 0;
|
datidx = 0;
|
||||||
|
|
||||||
|
|
@ -355,7 +357,7 @@ int main(int argc, char **argv)
|
||||||
if (rcvlen) {
|
if (rcvlen) {
|
||||||
if (rcvlen > fflen)
|
if (rcvlen > fflen)
|
||||||
rcvlen = fflen;
|
rcvlen = fflen;
|
||||||
|
|
||||||
percent = (rcvlen * 100 / fflen);
|
percent = (rcvlen * 100 / fflen);
|
||||||
printf("\r %3lu%% ", percent);
|
printf("\r %3lu%% ", percent);
|
||||||
|
|
||||||
|
|
@ -408,7 +410,6 @@ int main(int argc, char **argv)
|
||||||
fflen = rcvlen = 0;
|
fflen = rcvlen = 0;
|
||||||
}
|
}
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
close(s);
|
close(s);
|
||||||
|
|
|
||||||
|
|
@ -383,10 +383,9 @@ static inline int addr_status_mine(int sa)
|
||||||
{
|
{
|
||||||
if (sa == s.current_sa)
|
if (sa == s.current_sa)
|
||||||
return '*';
|
return '*';
|
||||||
else if (addr[sa].flags & F_USE)
|
if (addr[sa].flags & F_USE)
|
||||||
return '+';
|
return '+';
|
||||||
else
|
return '-';
|
||||||
return '-';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dump_status(void)
|
static void dump_status(void)
|
||||||
|
|
|
||||||
13
j1939cat.c
13
j1939cat.c
|
|
@ -212,8 +212,7 @@ static int j1939cat_extract_serr(struct j1939cat_priv *priv)
|
||||||
|
|
||||||
if (serr->ee_info == SCM_TSTAMP_SCHED)
|
if (serr->ee_info == SCM_TSTAMP_SCHED)
|
||||||
return -EINTR;
|
return -EINTR;
|
||||||
else
|
return 0;
|
||||||
return 0;
|
|
||||||
case SO_EE_ORIGIN_LOCAL:
|
case SO_EE_ORIGIN_LOCAL:
|
||||||
/*
|
/*
|
||||||
* The serr->ee_origin == SO_EE_ORIGIN_LOCAL is
|
* The serr->ee_origin == SO_EE_ORIGIN_LOCAL is
|
||||||
|
|
@ -319,11 +318,10 @@ static int j1939cat_send_loop(struct j1939cat_priv *priv, int out_fd, char *buf,
|
||||||
ret = poll(&fds, 1, priv->polltimeout);
|
ret = poll(&fds, 1, priv->polltimeout);
|
||||||
if (ret == -EINTR)
|
if (ret == -EINTR)
|
||||||
continue;
|
continue;
|
||||||
else if (ret < 0)
|
if (ret < 0)
|
||||||
return -errno;
|
return -errno;
|
||||||
else if (!ret)
|
if (!ret)
|
||||||
return -ETIME;
|
return -ETIME;
|
||||||
|
|
||||||
if (!(fds.revents & events)) {
|
if (!(fds.revents & events)) {
|
||||||
warn("%s: something else is wrong", __func__);
|
warn("%s: something else is wrong", __func__);
|
||||||
return -EIO;
|
return -EIO;
|
||||||
|
|
@ -333,11 +331,10 @@ static int j1939cat_send_loop(struct j1939cat_priv *priv, int out_fd, char *buf,
|
||||||
ret = j1939cat_recv_err(priv);
|
ret = j1939cat_recv_err(priv);
|
||||||
if (ret == -EINTR)
|
if (ret == -EINTR)
|
||||||
continue;
|
continue;
|
||||||
else if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
else if ((priv->repeat - 1) == stats->tskey)
|
if ((priv->repeat - 1) == stats->tskey)
|
||||||
tx_done = true;
|
tx_done = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fds.revents & POLLOUT) {
|
if (fds.revents & POLLOUT) {
|
||||||
|
|
|
||||||
2
lib.c
2
lib.c
|
|
@ -588,7 +588,7 @@ void snprintf_can_error_frame(char *buf, size_t len, const struct canfd_frame *c
|
||||||
if (class & mask) {
|
if (class & mask) {
|
||||||
if (classes)
|
if (classes)
|
||||||
n += snprintf(buf + n, len - n, "%s", sep);
|
n += snprintf(buf + n, len - n, "%s", sep);
|
||||||
n += snprintf(buf + n, len - n, "%s", error_classes[i]);
|
n += snprintf(buf + n, len - n, "%s", error_classes[i]);
|
||||||
if (mask == CAN_ERR_LOSTARB)
|
if (mask == CAN_ERR_LOSTARB)
|
||||||
n += snprintf_error_lostarb(buf + n, len - n,
|
n += snprintf_error_lostarb(buf + n, len - n,
|
||||||
cf);
|
cf);
|
||||||
|
|
|
||||||
|
|
@ -64,8 +64,8 @@ static const char *libj1939_ifnam(int ifindex)
|
||||||
*/
|
*/
|
||||||
libj1939_cleanup();
|
libj1939_cleanup();
|
||||||
return libj1939_ifnam(ifindex);
|
return libj1939_ifnam(ifindex);
|
||||||
} else
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* retrieve index */
|
/* retrieve index */
|
||||||
|
|
@ -88,8 +88,8 @@ static int libj1939_ifindex(const char *str)
|
||||||
if (cached) {
|
if (cached) {
|
||||||
libj1939_cleanup();
|
libj1939_cleanup();
|
||||||
return libj1939_ifindex(str);
|
return libj1939_ifindex(str);
|
||||||
} else
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void libj1939_parse_canaddr(char *spec, struct sockaddr_can *paddr)
|
void libj1939_parse_canaddr(char *spec, struct sockaddr_can *paddr)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue