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,
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)
{
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)
......
......@@ -128,28 +128,32 @@ err_stat_s:
* The function uses a symbolic link in /dev, created by the local
* installation procedure.
*/
struct fdelay_board *fdelay_open_by_lun(int lun)
{
ssize_t ret;
char dev_id_str[4];
char path_pattern[] = "/dev/fine-delay.%d";
char path[sizeof(path_pattern) + 1];
int dev_id;
if (fdelay_is_verbose())
fprintf(stderr, "called: %s(lun %i);\n", __func__, lun);
ret = snprintf(path, sizeof(path), path_pattern, lun);
if (ret < 0 || ret >= sizeof(path)) {
errno = EINVAL;
return NULL;
}
ret = readlink(path, dev_id_str, sizeof(dev_id_str));
if (sscanf(dev_id_str, "%4x", &dev_id) != 1) {
errno = ENODEV;
return NULL;
}
return fdelay_open(dev_id);
}
struct fdelay_board *fdelay_open_by_lun(int lun)
{
ssize_t ret;
char dev_id_str[4];
char path_pattern[] = "/dev/fine-delay.%d";
char path[sizeof(path_pattern) + 1];
uint32_t dev_id;
if (fdelay_is_verbose())
fprintf(stderr, "called: %s(lun %i);\n", __func__, lun);
ret = snprintf(path, sizeof(path), path_pattern, lun);
if (ret < 0 || ret >= sizeof(path)) {
errno = EINVAL;
return NULL;
}
ret = readlink(path, dev_id_str, sizeof(dev_id_str));
if (ret < 0) {
errno = ENODEV;
return NULL;
}
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:
......
......@@ -136,6 +136,7 @@ enum fmctdc_error_numbers {
#ifdef FDELAY_INTERNAL /* Libray users should ignore what follows */
#include <unistd.h>
#include <fcntl.h>
#include <inttypes.h>
#include <sys/types.h>
#include <sys/stat.h>
......@@ -162,7 +163,7 @@ static inline int __fdelay_sysfs_get(char *path, uint32_t *resp)
if (!f)
return -1;
errno = 0;
if (fscanf(f, "%i", resp) != 1) {
if (fscanf(f, "%"SCNu32, resp) != 1) {
fclose(f);
if (!errno)
errno = EINVAL;
......@@ -177,7 +178,7 @@ static inline int __fdelay_sysfs_set(char *path, uint32_t *value)
char s[16];
int fd, ret, len;
len = sprintf(s, "%i\n", *value);
len = sprintf(s, "%"PRIu32"\n", *value);
fd = open(path, O_WRONLY);
if (fd < 0)
return -1;
......
......@@ -60,13 +60,14 @@ static int __fdelay_get_ch_fd(struct __fdelay_board *b,
int channel, int *fdc)
{
int ch14 = channel + 1;
char fname[128];
if (channel < 0 || channel > 3) {
errno = EINVAL;
return -1;
}
if (b->fdc[ch14] <= 0) {
char fname[128];
sprintf(fname, "%s-%i-0-ctrl", b->devbase, ch14);
b->fdc[ch14] = open(fname, O_WRONLY | O_NONBLOCK);
if (b->fdc[ch14] < 0)
......@@ -113,7 +114,7 @@ int fdelay_config_pulse(struct fdelay_board *userb,
a[FD_ATTR_OUT_DELTA_FINE] = pulse->loop.frac; /* only 0..f */
int mode = pulse->mode & 0x7f;
/* 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. */
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,
if (fdelay_get_config_pulse(userb, channel, &pulse) < 0)
return -1;
memset(ps, 0, sizeof(struct fdelay_pulse_ps));
ps->mode = pulse.mode;
ps->rep = pulse.rep;
......
......@@ -67,8 +67,9 @@ int fdelay_get_config_tdc(struct fdelay_board *userb)
static int __fdelay_open_tdc(struct __fdelay_board *b)
{
char fname[128];
if (b->fdc[0] <= 0) {
char fname[128];
sprintf(fname, "%s-0-0-ctrl", b->devbase);
b->fdc[0] = open(fname, O_RDONLY | O_NONBLOCK);
}
......@@ -102,12 +103,12 @@ int fdelay_fileno_tdc(struct fdelay_board *userb)
* empty
*/
int fdelay_read(struct fdelay_board *userb, struct fdelay_time *t, int n,
int flags)
int flags)
{
__define_board(b, userb);
struct zio_control ctrl;
uint32_t *attrs;
int i, j, fd;
int i, fd;
fd_set set;
fd = __fdelay_open_tdc(b);
......@@ -115,6 +116,8 @@ int fdelay_read(struct fdelay_board *userb, struct fdelay_time *t, int n,
return fd; /* errno already set */
for (i = 0; i < n;) {
int j;
j = read(fd, &ctrl, sizeof(ctrl));
if (j < 0 && errno != EAGAIN)
return -1;
......@@ -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 i, loop;
int i;
for (i = 0; i < n; ) {
int loop;
loop = fdelay_read(userb, t + i, n - i, 0);
if (loop < 0)
return -1;
......
......@@ -13,10 +13,11 @@ DESTDIR ?= /usr/local
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)\""
LDFLAGS = -L../lib
LDFLAGS = -L$(LIBFD)
LDLIBS = -lfdelay
CC ?= $(CROSS_COMPILE)gcc
......@@ -50,4 +51,4 @@ install:
install -D $(progs) $(DESTDIR)/bin
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)
exit(1);
}
int err = fdelay_check_wr_mode(b);
err = fdelay_check_wr_mode(b);
printf("WR Status: ");
switch(err)
{
......@@ -109,7 +109,7 @@ int main(int argc, char **argv)
default: printf("error: %s\n", strerror(errno)); break;
}
printf("Time: %lli.%09li\n", (long long)t.utc, (long)t.coarse * 8);
fdelay_close(b);
fdelay_exit();
return 0;
......@@ -130,7 +130,7 @@ int main(int argc, char **argv)
setbuf(stdout, NULL);
printf("Locking the card to WR: ");
int err = fdelay_wr_mode(b, 1);
err = fdelay_wr_mode(b, 1);
if(err == ENOTSUP)
{
......
......@@ -30,7 +30,7 @@ void dump_input(struct fdelay_time *t, int np, int umode)
int i;
for (i = 0; i < np; i++, t++) {
printf("seq %5i: ", t->seq_id);
printf("seq %5u: ", t->seq_id);
tools_report_time("", t, umode);
}
}
......
......@@ -85,7 +85,7 @@ int main(int argc, char **argv)
}
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_exit();
......
......@@ -3,6 +3,7 @@
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <inttypes.h>
#include "fdelay-lib.h"
#include "tools-common.h"
......@@ -60,20 +61,20 @@ void tools_report_time(char *name, struct fdelay_time *t, int umode)
printf("%s ", name);
switch(umode) {
case TOOLS_UMODE_USER:
printf ("%10llu:%03llu,%03llu,%03llu,%03llu ps\n",
(long long)(t->utc),
(picoseconds / (1000LL * 1000 * 1000)),
(picoseconds / (1000LL * 1000) % 1000),
(picoseconds / (1000LL) % 1000),
(picoseconds % 1000LL));
printf ("%10"PRIu64":%03llu,%03llu,%03llu,%03llu ps\n",
t->utc,
(picoseconds / (1000ULL * 1000 * 1000)),
(picoseconds / (1000ULL * 1000) % 1000),
(picoseconds / (1000ULL) % 1000),
(picoseconds % 1000ULL));
break;
case TOOLS_UMODE_FLOAT:
printf ("float %10llu.%012llu\n", (long long)(t->utc),
printf ("float %10"PRIu64".%012llu\n", t->utc,
picoseconds);
break;
case TOOLS_UMODE_RAW:
printf("raw utc %10lli, coarse %9li, frac %9li\n",
(long long)t->utc, (long)t->coarse, (long)t->frac);
printf("raw utc %10"PRIu64", coarse %9"PRIu32", frac %9"PRIu32"\n",
t->utc, t->coarse, t->frac);
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