Commit 54eafb43 authored by Federico Vaga's avatar Federico Vaga

cppcheck fixes

Signed-off-by: Federico Vaga's avatarFederico Vaga <federico.vaga@cern.ch>
parent 718f35cf
...@@ -280,11 +280,11 @@ static inline void fd_iowrite(struct fd_dev *fd, ...@@ -280,11 +280,11 @@ static inline void fd_iowrite(struct fd_dev *fd,
static inline uint32_t fd_readl(struct fd_dev *fd, unsigned long reg) static inline uint32_t fd_readl(struct fd_dev *fd, unsigned long reg)
{ {
return fd_ioread(fd, fd->fd_regs_base + reg); return fd_ioread(fd, (char *)fd->fd_regs_base + reg);
} }
static inline void fd_writel(struct fd_dev *fd, uint32_t v, unsigned long reg) static inline void fd_writel(struct fd_dev *fd, uint32_t v, unsigned long reg)
{ {
fd_iowrite(fd, v, fd->fd_regs_base + reg); fd_iowrite(fd, v, (char *)fd->fd_regs_base + reg);
} }
static inline void __check_chan(int x) static inline void __check_chan(int x)
......
...@@ -128,28 +128,32 @@ err_stat_s: ...@@ -128,28 +128,32 @@ err_stat_s:
* The function uses a symbolic link in /dev, created by the local * The function uses a symbolic link in /dev, created by the local
* installation procedure. * installation procedure.
*/ */
struct fdelay_board *fdelay_open_by_lun(int lun) struct fdelay_board *fdelay_open_by_lun(int lun)
{ {
ssize_t ret; ssize_t ret;
char dev_id_str[4]; char dev_id_str[4];
char path_pattern[] = "/dev/fine-delay.%d"; char path_pattern[] = "/dev/fine-delay.%d";
char path[sizeof(path_pattern) + 1]; char path[sizeof(path_pattern) + 1];
int dev_id; uint32_t dev_id;
if (fdelay_is_verbose()) if (fdelay_is_verbose())
fprintf(stderr, "called: %s(lun %i);\n", __func__, lun); fprintf(stderr, "called: %s(lun %i);\n", __func__, lun);
ret = snprintf(path, sizeof(path), path_pattern, lun); ret = snprintf(path, sizeof(path), path_pattern, lun);
if (ret < 0 || ret >= sizeof(path)) { if (ret < 0 || ret >= sizeof(path)) {
errno = EINVAL; errno = EINVAL;
return NULL; return NULL;
} }
ret = readlink(path, dev_id_str, sizeof(dev_id_str)); ret = readlink(path, dev_id_str, sizeof(dev_id_str));
if (sscanf(dev_id_str, "%4x", &dev_id) != 1) { if (ret < 0) {
errno = ENODEV; errno = ENODEV;
return NULL; return NULL;
} }
return fdelay_open(dev_id); if (sscanf(dev_id_str, "%4"SCNu32, &dev_id) != 1) {
} errno = ENODEV;
return NULL;
}
return fdelay_open(dev_id);
}
/** /**
* Close an FMC Fine Delay device opened with one of the following functions: * Close an FMC Fine Delay device opened with one of the following functions:
......
...@@ -136,6 +136,7 @@ enum fmctdc_error_numbers { ...@@ -136,6 +136,7 @@ enum fmctdc_error_numbers {
#ifdef FDELAY_INTERNAL /* Libray users should ignore what follows */ #ifdef FDELAY_INTERNAL /* Libray users should ignore what follows */
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
#include <inttypes.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
...@@ -162,7 +163,7 @@ static inline int __fdelay_sysfs_get(char *path, uint32_t *resp) ...@@ -162,7 +163,7 @@ static inline int __fdelay_sysfs_get(char *path, uint32_t *resp)
if (!f) if (!f)
return -1; return -1;
errno = 0; errno = 0;
if (fscanf(f, "%i", resp) != 1) { if (fscanf(f, "%"SCNu32, resp) != 1) {
fclose(f); fclose(f);
if (!errno) if (!errno)
errno = EINVAL; errno = EINVAL;
...@@ -177,7 +178,7 @@ static inline int __fdelay_sysfs_set(char *path, uint32_t *value) ...@@ -177,7 +178,7 @@ static inline int __fdelay_sysfs_set(char *path, uint32_t *value)
char s[16]; char s[16];
int fd, ret, len; int fd, ret, len;
len = sprintf(s, "%i\n", *value); len = sprintf(s, "%"PRIu32"\n", *value);
fd = open(path, O_WRONLY); fd = open(path, O_WRONLY);
if (fd < 0) if (fd < 0)
return -1; return -1;
......
...@@ -60,13 +60,14 @@ static int __fdelay_get_ch_fd(struct __fdelay_board *b, ...@@ -60,13 +60,14 @@ static int __fdelay_get_ch_fd(struct __fdelay_board *b,
int channel, int *fdc) int channel, int *fdc)
{ {
int ch14 = channel + 1; int ch14 = channel + 1;
char fname[128];
if (channel < 0 || channel > 3) { if (channel < 0 || channel > 3) {
errno = EINVAL; errno = EINVAL;
return -1; return -1;
} }
if (b->fdc[ch14] <= 0) { if (b->fdc[ch14] <= 0) {
char fname[128];
sprintf(fname, "%s-%i-0-ctrl", b->devbase, ch14); sprintf(fname, "%s-%i-0-ctrl", b->devbase, ch14);
b->fdc[ch14] = open(fname, O_WRONLY | O_NONBLOCK); b->fdc[ch14] = open(fname, O_WRONLY | O_NONBLOCK);
if (b->fdc[ch14] < 0) if (b->fdc[ch14] < 0)
...@@ -113,7 +114,7 @@ int fdelay_config_pulse(struct fdelay_board *userb, ...@@ -113,7 +114,7 @@ int fdelay_config_pulse(struct fdelay_board *userb,
a[FD_ATTR_OUT_DELTA_FINE] = pulse->loop.frac; /* only 0..f */ a[FD_ATTR_OUT_DELTA_FINE] = pulse->loop.frac; /* only 0..f */
int mode = pulse->mode & 0x7f; int mode = pulse->mode & 0x7f;
/* hotfix: the ZIO has a bug blocking the output when the output raw_io function returns an error. /* hotfix: the ZIO has a bug blocking the output when the output raw_io function returns an error.
therefore we temporarily have to check the output programming correctness in the user library. */ therefore we temporarily have to check the output programming correctness in the user library. */
if (mode == FD_OUT_MODE_DELAY || mode == FD_OUT_MODE_DISABLED) if (mode == FD_OUT_MODE_DELAY || mode == FD_OUT_MODE_DISABLED)
...@@ -339,7 +340,7 @@ int fdelay_get_config_pulse_ps(struct fdelay_board *userb, ...@@ -339,7 +340,7 @@ int fdelay_get_config_pulse_ps(struct fdelay_board *userb,
if (fdelay_get_config_pulse(userb, channel, &pulse) < 0) if (fdelay_get_config_pulse(userb, channel, &pulse) < 0)
return -1; return -1;
memset(ps, 0, sizeof(struct fdelay_pulse_ps)); memset(ps, 0, sizeof(struct fdelay_pulse_ps));
ps->mode = pulse.mode; ps->mode = pulse.mode;
ps->rep = pulse.rep; ps->rep = pulse.rep;
......
...@@ -67,8 +67,9 @@ int fdelay_get_config_tdc(struct fdelay_board *userb) ...@@ -67,8 +67,9 @@ int fdelay_get_config_tdc(struct fdelay_board *userb)
static int __fdelay_open_tdc(struct __fdelay_board *b) static int __fdelay_open_tdc(struct __fdelay_board *b)
{ {
char fname[128];
if (b->fdc[0] <= 0) { if (b->fdc[0] <= 0) {
char fname[128];
sprintf(fname, "%s-0-0-ctrl", b->devbase); sprintf(fname, "%s-0-0-ctrl", b->devbase);
b->fdc[0] = open(fname, O_RDONLY | O_NONBLOCK); b->fdc[0] = open(fname, O_RDONLY | O_NONBLOCK);
} }
...@@ -102,12 +103,12 @@ int fdelay_fileno_tdc(struct fdelay_board *userb) ...@@ -102,12 +103,12 @@ int fdelay_fileno_tdc(struct fdelay_board *userb)
* empty * empty
*/ */
int fdelay_read(struct fdelay_board *userb, struct fdelay_time *t, int n, int fdelay_read(struct fdelay_board *userb, struct fdelay_time *t, int n,
int flags) int flags)
{ {
__define_board(b, userb); __define_board(b, userb);
struct zio_control ctrl; struct zio_control ctrl;
uint32_t *attrs; uint32_t *attrs;
int i, j, fd; int i, fd;
fd_set set; fd_set set;
fd = __fdelay_open_tdc(b); fd = __fdelay_open_tdc(b);
...@@ -115,6 +116,8 @@ int fdelay_read(struct fdelay_board *userb, struct fdelay_time *t, int n, ...@@ -115,6 +116,8 @@ int fdelay_read(struct fdelay_board *userb, struct fdelay_time *t, int n,
return fd; /* errno already set */ return fd; /* errno already set */
for (i = 0; i < n;) { for (i = 0; i < n;) {
int j;
j = read(fd, &ctrl, sizeof(ctrl)); j = read(fd, &ctrl, sizeof(ctrl));
if (j < 0 && errno != EAGAIN) if (j < 0 && errno != EAGAIN)
return -1; return -1;
...@@ -166,9 +169,11 @@ int fdelay_read(struct fdelay_board *userb, struct fdelay_time *t, int n, ...@@ -166,9 +169,11 @@ int fdelay_read(struct fdelay_board *userb, struct fdelay_time *t, int n,
*/ */
int fdelay_fread(struct fdelay_board *userb, struct fdelay_time *t, int n) int fdelay_fread(struct fdelay_board *userb, struct fdelay_time *t, int n)
{ {
int i, loop; int i;
for (i = 0; i < n; ) { for (i = 0; i < n; ) {
int loop;
loop = fdelay_read(userb, t + i, n - i, 0); loop = fdelay_read(userb, t + i, n - i, 0);
if (loop < 0) if (loop < 0)
return -1; return -1;
......
...@@ -13,10 +13,11 @@ DESTDIR ?= /usr/local ...@@ -13,10 +13,11 @@ DESTDIR ?= /usr/local
GIT_VERSION := $(shell git describe --dirty --long --tags) GIT_VERSION := $(shell git describe --dirty --long --tags)
CFLAGS += -I../kernel -I../lib -Wno-trigraphs -Wall -Werror -ggdb $(EXTRACFLAGS) LIBFD := ../lib
CFLAGS += -I../kernel -I$(LIBFD) -Wno-trigraphs -Wall -Werror -ggdb $(EXTRACFLAGS)
CFLAGS += -DGIT_VERSION="\"$(GIT_VERSION)\"" CFLAGS += -DGIT_VERSION="\"$(GIT_VERSION)\""
LDFLAGS = -L../lib LDFLAGS = -L$(LIBFD)
LDLIBS = -lfdelay LDLIBS = -lfdelay
CC ?= $(CROSS_COMPILE)gcc CC ?= $(CROSS_COMPILE)gcc
...@@ -50,4 +51,4 @@ install: ...@@ -50,4 +51,4 @@ install:
install -D $(progs) $(DESTDIR)/bin install -D $(progs) $(DESTDIR)/bin
cppcheck: cppcheck:
$(CPPCHECK) -q -I. -I../kernel -I$(LIBTDC) --suppress=missingIncludeSystem --enable=all *.c *.h $(CPPCHECK) -q -I. -I../kernel -I$(LIBFD) --suppress=missingIncludeSystem --enable=all *.c *.h
...@@ -98,7 +98,7 @@ int main(int argc, char **argv) ...@@ -98,7 +98,7 @@ int main(int argc, char **argv)
exit(1); exit(1);
} }
int err = fdelay_check_wr_mode(b); err = fdelay_check_wr_mode(b);
printf("WR Status: "); printf("WR Status: ");
switch(err) switch(err)
{ {
...@@ -109,7 +109,7 @@ int main(int argc, char **argv) ...@@ -109,7 +109,7 @@ int main(int argc, char **argv)
default: printf("error: %s\n", strerror(errno)); break; default: printf("error: %s\n", strerror(errno)); break;
} }
printf("Time: %lli.%09li\n", (long long)t.utc, (long)t.coarse * 8); printf("Time: %lli.%09li\n", (long long)t.utc, (long)t.coarse * 8);
fdelay_close(b); fdelay_close(b);
fdelay_exit(); fdelay_exit();
return 0; return 0;
...@@ -130,7 +130,7 @@ int main(int argc, char **argv) ...@@ -130,7 +130,7 @@ int main(int argc, char **argv)
setbuf(stdout, NULL); setbuf(stdout, NULL);
printf("Locking the card to WR: "); printf("Locking the card to WR: ");
int err = fdelay_wr_mode(b, 1); err = fdelay_wr_mode(b, 1);
if(err == ENOTSUP) if(err == ENOTSUP)
{ {
......
...@@ -30,7 +30,7 @@ void dump_input(struct fdelay_time *t, int np, int umode) ...@@ -30,7 +30,7 @@ void dump_input(struct fdelay_time *t, int np, int umode)
int i; int i;
for (i = 0; i < np; i++, t++) { for (i = 0; i < np; i++, t++) {
printf("seq %5i: ", t->seq_id); printf("seq %5u: ", t->seq_id);
tools_report_time("", t, umode); tools_report_time("", t, umode);
} }
} }
......
...@@ -85,7 +85,7 @@ int main(int argc, char **argv) ...@@ -85,7 +85,7 @@ int main(int argc, char **argv)
} }
printf("%s: termination is %s\n", argv[0], printf("%s: termination is %s\n", argv[0],
hwval & FD_TDCF_TERM_50 ? "on" : "off"); (hwval & FD_TDCF_TERM_50) ? "on" : "off");
fdelay_close(b); fdelay_close(b);
fdelay_exit(); fdelay_exit();
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include <unistd.h> #include <unistd.h>
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include <inttypes.h>
#include "fdelay-lib.h" #include "fdelay-lib.h"
#include "tools-common.h" #include "tools-common.h"
...@@ -60,20 +61,20 @@ void tools_report_time(char *name, struct fdelay_time *t, int umode) ...@@ -60,20 +61,20 @@ void tools_report_time(char *name, struct fdelay_time *t, int umode)
printf("%s ", name); printf("%s ", name);
switch(umode) { switch(umode) {
case TOOLS_UMODE_USER: case TOOLS_UMODE_USER:
printf ("%10llu:%03llu,%03llu,%03llu,%03llu ps\n", printf ("%10"PRIu64":%03llu,%03llu,%03llu,%03llu ps\n",
(long long)(t->utc), t->utc,
(picoseconds / (1000LL * 1000 * 1000)), (picoseconds / (1000ULL * 1000 * 1000)),
(picoseconds / (1000LL * 1000) % 1000), (picoseconds / (1000ULL * 1000) % 1000),
(picoseconds / (1000LL) % 1000), (picoseconds / (1000ULL) % 1000),
(picoseconds % 1000LL)); (picoseconds % 1000ULL));
break; break;
case TOOLS_UMODE_FLOAT: case TOOLS_UMODE_FLOAT:
printf ("float %10llu.%012llu\n", (long long)(t->utc), printf ("float %10"PRIu64".%012llu\n", t->utc,
picoseconds); picoseconds);
break; break;
case TOOLS_UMODE_RAW: case TOOLS_UMODE_RAW:
printf("raw utc %10lli, coarse %9li, frac %9li\n", printf("raw utc %10"PRIu64", coarse %9"PRIu32", frac %9"PRIu32"\n",
(long long)t->utc, (long)t->coarse, (long)t->frac); t->utc, t->coarse, t->frac);
break; break;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment