Commit 7a51d211 authored by Federico Vaga's avatar Federico Vaga Committed by Federico Vaga

apply cppcheck suggestions

Signed-off-by: Federico Vaga's avatarfederico.vaga@cern.ch <federico.vaga@cern.ch>
parent 7dc87c66
......@@ -72,7 +72,7 @@ static ssize_t zio_show_buffers(struct bus_type *bus, char *buf)
spin_lock(&zstat->lock);
list_for_each_entry(cur, &zstat->all_buffer_types.list, list)
len = sprintf(buf, "%s%s\n", buf, cur->name);
len = sprintf(buf + len, "%s\n", cur->name);
spin_unlock(&zstat->lock);
return len;
......@@ -89,7 +89,7 @@ static ssize_t zio_show_triggers(struct bus_type *bus, char *buf)
spin_lock(&zstat->lock);
list_for_each_entry(cur, &zstat->all_trigger_types.list, list)
len = sprintf(buf, "%s%s\n", buf, cur->name);
len = sprintf(buf + len, "%s\n", cur->name);
spin_unlock(&zstat->lock);
return len;
......@@ -175,7 +175,6 @@ static int zio_match_device(struct device *dev, struct device_driver *drv)
const struct zio_driver *zdrv = to_zio_drv(drv);
const struct zio_device_id *id;
struct zio_device *child;
int err = 0;
if (!zdrv->id_table)
return 0;
......@@ -186,7 +185,7 @@ static int zio_match_device(struct device *dev, struct device_driver *drv)
/* device and driver match */
if (dev->type == &zdevhw_device_type) {
/* Register the real zio device */
err = __zdev_register(to_zio_dev(dev), id);
int err = __zdev_register(to_zio_dev(dev), id);
if (err) {
pr_err("ZIO: Cannot register real zio_device (%d)\n",
err);
......@@ -258,7 +257,6 @@ static int zio_drv_remove(struct device *dev)
static int _zdev_template_check_and_init(struct zio_device *zdev,
const char *name)
{
struct zio_cset *cset;
int i;
if (!zdev) {
......@@ -279,7 +277,8 @@ static int _zdev_template_check_and_init(struct zio_device *zdev,
}
for (i = 0; i < zdev->n_cset; ++i) {
cset = &zdev->cset[i];
struct zio_cset *cset = &zdev->cset[i];
if (!cset->n_chan) {
dev_err(&zdev->head.dev,
"no channels in %s cset%i\n",
......
......@@ -198,8 +198,8 @@ int zio_create_chan_devices(struct zio_channel *chan)
return 0;
devt_c = zstat->basedev + chan->cset->minor + chan->index * 2;
mask = chan->flags & ZIO_CSET_CHAN_INTERLEAVE ? "%s-%i-i-ctrl" :
"%s-%i-%i-ctrl";
mask = (chan->flags & ZIO_CSET_CHAN_INTERLEAVE) ? "%s-%i-i-ctrl" :
"%s-%i-%i-ctrl";
chan->ctrl_dev = device_create(&zio_cdev_class, &chan->head.dev, devt_c,
&chan->flags, mask,
dev_name(&chan->cset->zdev->head.dev),
......@@ -211,8 +211,8 @@ int zio_create_chan_devices(struct zio_channel *chan)
}
devt_d = devt_c + 1;
mask = chan->flags & ZIO_CSET_CHAN_INTERLEAVE ? "%s-%i-i-data" :
"%s-%i-%i-data";
mask = (chan->flags & ZIO_CSET_CHAN_INTERLEAVE) ? "%s-%i-i-data" :
"%s-%i-%i-data";
chan->data_dev = device_create(&zio_cdev_class, &chan->head.dev, devt_d,
&chan->flags, mask,
dev_name(&chan->cset->zdev->head.dev),
......@@ -364,7 +364,6 @@ static int zio_can_w_ctrl(struct zio_f_priv *priv)
struct zio_channel *chan = priv->chan;
struct zio_bi *bi = chan->bi;
struct zio_block *block;
struct zio_control *ctrl;
const int ret_ok = POLLOUT | POLLWRNORM;
int ret;
......@@ -379,7 +378,7 @@ static int zio_can_w_ctrl(struct zio_f_priv *priv)
block = chan->user_block;
if (block && block->uoff) {
/* store a partial block */
ctrl = zio_get_ctrl(block);
struct zio_control *ctrl = zio_get_ctrl(block);
ctrl->nsamples = block->uoff / chan->cset->ssize;
if (ctrl->nsamples)
zio_buffer_store_block(bi, block);
......@@ -430,7 +429,7 @@ static ssize_t zio_generic_read(struct file *f, char __user *ubuf,
struct zio_bi *bi = chan->bi;
struct zio_block *block;
int (*can_read)(struct zio_f_priv *);
int fault, rflags;
int fault;
dev_dbg(&bi->head.dev, "%s:%d type %s\n", __func__, __LINE__,
priv->type == ZIO_CDEV_CTRL ? "ctrl" : "data");
......@@ -447,7 +446,7 @@ static ssize_t zio_generic_read(struct file *f, char __user *ubuf,
}
while (1) {
rflags = can_read(priv);
int rflags = can_read(priv);
if (rflags == 0 || rflags == POLLERR) {
if (f->f_flags & O_NONBLOCK)
return -EAGAIN;
......@@ -505,7 +504,7 @@ static ssize_t zio_generic_write(struct file *f, const char __user *ubuf,
struct zio_bi *bi = chan->bi;
struct zio_block *block;
int (*can_write)(struct zio_f_priv *);
int fault, wflags;
int fault;
dev_dbg(&bi->head.dev, "%s:%d type %s\n", __func__, __LINE__,
priv->type == ZIO_CDEV_CTRL ? "ctrl" : "data");
......@@ -521,7 +520,7 @@ static ssize_t zio_generic_write(struct file *f, const char __user *ubuf,
}
while (1) {
wflags = can_write(priv);
int wflags = can_write(priv);
if (wflags == 0 || wflags == POLLERR) {
if (f->f_flags & O_NONBLOCK)
return -EAGAIN;
......
......@@ -73,12 +73,12 @@ void zio_slab_exit(void) /* not __exit: called from zio_init on failures */
struct zio_device *zio_find_device(char *name, uint32_t dev_id)
{
struct zio_object_list_item *cur;
struct zio_device *zdev;
if (!name)
return NULL;
list_for_each_entry(cur, &zstat->all_devices.list, list) {
zdev = to_zio_dev(&cur->obj_head->dev);
struct zio_device * zdev = to_zio_dev(&cur->obj_head->dev);
if (strcmp(cur->name, name) == 0 && zdev->dev_id == dev_id)
return zdev; /* found */
}
......
......@@ -21,14 +21,13 @@
static int zio_calculate_nents(struct zio_blocks_sg *sg_blocks,
unsigned int n_blocks)
{
int i, bytesleft;
void *bufp;
int i;
int mapbytes;
int nents = 0;
for (i = 0; i < n_blocks; ++i) {
bytesleft = sg_blocks[i].block->datalen;
bufp = sg_blocks[i].block->data;
int bytesleft = sg_blocks[i].block->datalen;
void *bufp = sg_blocks[i].block->data;
sg_blocks[i].first_nent = nents;
while (bytesleft) {
nents++;
......@@ -36,7 +35,7 @@ static int zio_calculate_nents(struct zio_blocks_sg *sg_blocks,
mapbytes = bytesleft;
else
mapbytes = PAGE_SIZE - offset_in_page(bufp);
bufp += mapbytes;
bufp = (char *)bufp + mapbytes;
bytesleft -= mapbytes;
}
}
......@@ -46,8 +45,8 @@ static int zio_calculate_nents(struct zio_blocks_sg *sg_blocks,
static void zio_dma_setup_scatter(struct zio_dma_sgt *zdma)
{
struct scatterlist *sg;
int bytesleft = 0;
void *bufp = NULL;
int bytesleft = 0;
int mapbytes;
int i, i_blk;
......@@ -85,7 +84,7 @@ static void zio_dma_setup_scatter(struct zio_dma_sgt *zdma)
else
sg_set_buf(sg, bufp, mapbytes);
/* Configure next values */
bufp += mapbytes;
bufp = (char *)bufp + mapbytes;
bytesleft -= mapbytes;
pr_debug("sg item (%p(+0x%lx), len:%d, left:%d)\n",
virt_to_page(bufp), offset_in_page(bufp),
......
......@@ -19,10 +19,9 @@
static void __zio_internal_abort_free(struct zio_cset *cset)
{
struct zio_channel *chan;
struct zio_block *block;
chan_for_each(chan, cset) {
block = chan->active_block;
struct zio_block *block = chan->active_block;
zio_buffer_free_block(chan->bi, block);
chan->active_block = NULL;
}
......@@ -81,7 +80,7 @@ static int __zio_arm_input_trigger(struct zio_ti *ti)
struct zio_cset *cset;
struct zio_channel *chan;
struct zio_control *ctrl;
int i, datalen;
int i;
cset = ti->cset;
zdev = cset->zdev;
......@@ -89,6 +88,8 @@ static int __zio_arm_input_trigger(struct zio_ti *ti)
/* Allocate the buffer for the incoming sample, in active channels */
chan_for_each(chan, cset) {
int datalen;
ctrl = chan->current_ctrl;
ctrl->nsamples = ti->nsamples;
datalen = ctrl->ssize * ti->nsamples;
......
......@@ -16,11 +16,11 @@
/* Prototypes */
static void zio_trigger_put(struct zio_trigger_type *trig,
struct module *dev_owner);
const struct module *dev_owner);
static void zio_buffer_put(struct zio_buffer_type *zbuf,
struct module *dev_owner);
const struct module *dev_owner);
static void zobj_unregister(struct zio_object_list *zlist,
struct zio_obj_head *head);
const struct zio_obj_head *head);
static void __bi_destroy(struct zio_buffer_type *zbuf, struct zio_bi *bi);
static struct zio_status *zstat = &zio_global_status; /* Always use ptr */
......@@ -183,7 +183,7 @@ static struct zio_buffer_type *zio_buffer_get(struct zio_cset *cset,
return container_of(list_item->obj_head, struct zio_buffer_type, head);
}
static void zio_buffer_put(struct zio_buffer_type *zbuf,
struct module *dev_owner)
const struct module *dev_owner)
{
if (zbuf->owner != dev_owner)
module_put(zbuf->owner);
......@@ -204,7 +204,7 @@ static struct zio_trigger_type *zio_trigger_get(struct zio_cset *cset,
return container_of(list_item->obj_head, struct zio_trigger_type, head);
}
static void zio_trigger_put(struct zio_trigger_type *trig,
struct module *dev_owner)
const struct module *dev_owner)
{
if (trig->owner != dev_owner)
module_put(trig->owner);
......@@ -788,17 +788,18 @@ out_zattr_copy:
static void chan_unregister(struct zio_channel *chan)
{
int i;
if (!chan)
return;
zio_destroy_chan_devices(chan);
/* destroy buffer instance */
__bi_destroy(chan->cset->zbuf, chan->bi);
if (ZIO_HAS_BINARY_CONTROL)
if (ZIO_HAS_BINARY_CONTROL) {
int i;
for (i = 0; i < __ZIO_BIN_ATTR_NUM; ++i)
sysfs_remove_bin_file(&chan->head.dev.kobj,
&zio_bin_attr[i]);
}
zobj_remove_link(&chan->head);
device_unregister(&chan->head.dev);
}
......@@ -1066,7 +1067,7 @@ static int zobj_register(struct zio_object_list *zlist,
}
static void zobj_unregister(struct zio_object_list *zlist,
struct zio_obj_head *head)
const struct zio_obj_head *head)
{
struct zio_object_list_item *item;
......
......@@ -272,7 +272,7 @@ static int __zattr_chan_init_ctrl(struct zio_channel *chan, unsigned int start)
static int __zattr_cset_init_ctrl(struct zio_cset *cset, unsigned int start)
{
struct zio_attribute *zattr;
int i, err, start_c = start;
int i, start_c = start;
/* Fix cset extended attribute index */
zattr = cset->zattr_set.ext_zattr;
......@@ -289,7 +289,7 @@ static int __zattr_cset_init_ctrl(struct zio_cset *cset, unsigned int start)
for (i = 0; i < cset->n_chan; ++i) {
err = __zattr_chan_init_ctrl(&cset->chan[i], start_c);
int err = __zattr_chan_init_ctrl(&cset->chan[i], start_c);
if (err)
return err;
}
......@@ -303,7 +303,7 @@ static int __zattr_cset_init_ctrl(struct zio_cset *cset, unsigned int start)
int __zattr_dev_init_ctrl(struct zio_device *zdev)
{
struct zio_attribute *zattr;
int i, err, start = 0;
int i, start = 0;
/* Device level */
/* Fix device extended attribute index */
......@@ -315,7 +315,7 @@ int __zattr_dev_init_ctrl(struct zio_device *zdev)
zattr[i].index = ZIO_ATTR_INDEX_NONE;
for (i = 0; i < zdev->n_cset; ++i) {
err = __zattr_cset_init_ctrl(&zdev->cset[i], start);
int err = __zattr_cset_init_ctrl(&zdev->cset[i], start);
if (err)
return err;
}
......@@ -333,7 +333,6 @@ int __zattr_dev_init_ctrl(struct zio_device *zdev)
static void __chan_enable_interleave(struct zio_channel *chan,
unsigned int enable) {
struct zio_cset *cset = chan->cset;
int i;
/*
* If the cset is interleave only, then only the interleaved
......@@ -353,6 +352,8 @@ static void __chan_enable_interleave(struct zio_channel *chan,
* must be set to the opposite status.
*/
if (chan->flags & ZIO_CSET_CHAN_INTERLEAVE) { /* Interleaved channel */
int i;
for (i = 0; i < cset->n_chan - 1; ++i)
__zio_object_enable(&cset->chan[i].head, !enable);
} else { /* Normal channel */
......@@ -709,8 +710,8 @@ static ssize_t zobj_show_devname(struct device *dev,
dev_name(&cset->zdev->head.dev), cset->index);
case ZIO_CHAN:
chan = to_zio_chan(dev);
mask = chan->flags & ZIO_CSET_CHAN_INTERLEAVE ? "%s-%i-i\n" :
"%s-%i-%i\n";
mask = (chan->flags & ZIO_CSET_CHAN_INTERLEAVE) ? "%s-%i-i\n" :
"%s-%i-%i\n";
return sprintf(buf, mask, dev_name(&chan->cset->zdev->head.dev),
chan->cset->index, chan->index);
case ZIO_TI:
......@@ -721,8 +722,8 @@ static ssize_t zobj_show_devname(struct device *dev,
case ZIO_BI:
bi = to_zio_bi(dev);
chan = bi->chan;
mask = chan->flags & ZIO_CSET_CHAN_INTERLEAVE ? "%s-%i-i-b\n" :
"%s-%i-%i-b\n";
mask = (chan->flags & ZIO_CSET_CHAN_INTERLEAVE) ? "%s-%i-i-b\n" :
"%s-%i-%i-b\n";
return sprintf(buf, mask, dev_name(&chan->cset->zdev->head.dev),
chan->cset->index, chan->index);
default:
......@@ -761,7 +762,7 @@ static ssize_t zio_store_alarm(struct device *dev,
struct zio_control *ctrl = chan->current_ctrl;
unsigned int v1, v2;
switch (sscanf(buf, "%i %i", &v1, &v2)) {
switch (sscanf(buf, "%u %u", &v1, &v2)) {
case 2:
ctrl->drv_alarms &= (~v2);
fallthrough;
......@@ -826,7 +827,7 @@ static ssize_t zio_show_dire(struct device *dev,
{
struct zio_cset *cset = to_zio_cset(dev);
return sprintf(buf, "%s\n", cset->flags & ZIO_DIR ? "output" : "input");
return sprintf(buf, "%s\n", (cset->flags & ZIO_DIR) ? "output" : "input");
}
/**
......@@ -1080,9 +1081,9 @@ static ssize_t zio_show_attr_version(struct device *dev,
minor = (zattr->value & 0x00FF0000) >> 16;
flags = (zattr->value & 0xFFFF);
if (flags)
return sprintf(buf, "%d.%d 0x%04x\n", major, minor, flags);
return sprintf(buf, "%u.%u 0x%04x\n", major, minor, flags);
else
return sprintf(buf, "%d.%d\n", major, minor);
return sprintf(buf, "%u.%u\n", major, minor);
}
......
......@@ -13,7 +13,6 @@ ZIO_VERSION := -D__ZIO_MAJOR_VERSION=$(shell echo $(GIT_VERSION) | cut -d '-' -f
ZIO_VERSION += -D__ZIO_MINOR_VERSION=$(shell echo $(GIT_VERSION) | cut -d '-' -f 1 | cut -d '.' -f 2; )
ZIO_VERSION += -D__ZIO_PATCH_VERSION=$(shell echo $(GIT_VERSION) | cut -d '-' -f 1 | cut -d '.' -f 3; )
CFLAGS = -I$(M)/include/ -Wall -Werror $(ZIO_VERSION) $(EXTRACFLAGS)
INCLUDE = -I$(M)/include/
CFLAGS = $(INCLUDE) -Wall -Werror $(ZIO_VERSION) $(EXTRACFLAGS)
CFLAGS += -DGIT_VERSION=\"$(GIT_VERSION)\"
......@@ -37,4 +36,4 @@ clean:
cppcheck:
$(CPPCHECK) -q $(INCLUDE) --suppress=missingIncludeSystem --enable=all *.c *.h --error-exitcode=1
.PHONY: cppcheck"\"
.PHONY: cppcheck
......@@ -60,12 +60,12 @@ static int parse_ts(char *s, struct timespec *ts)
ts->tv_sec = 0;
ts->tv_nsec = 0;
if ( (i = sscanf(s, "%ld.%ld%c", &ts->tv_sec, &nano, &c)) == 1)
if ( (i = sscanf(s, "%ld.%lu%c", &ts->tv_sec, &nano, &c)) == 1)
return 0; /* seconds only */
if (i == 3)
return -1; /* trailing crap */
if (i == 0)
if (sscanf(s, ".%ld%c", &nano, &c) != 1)
if (sscanf(s, ".%lu%c", &nano, &c) != 1)
return -1; /* leading or trailing crap */
s = strchr(s, '.') + 1;
......
......@@ -137,7 +137,7 @@ int main(int argc, char **argv)
exit(1);
}
}
ptr = map + off;
ptr = (char *)map + off;
} else {
/* increase malloc size if needed */
while (size > buffersize) {
......@@ -167,7 +167,7 @@ int main(int argc, char **argv)
gettimeofday(&tv2, NULL);
i = (tv2.tv_sec - tv1.tv_sec) * 1000 * 1000
+ tv2.tv_usec - tv1.tv_usec;
fprintf(stderr, "%s: trasferred %li blocks, %li bytes, %i.%06i secs\n",
fprintf(stderr, "%s: trasferred %lu blocks, %lu bytes, %i.%06i secs\n",
argv[0], nblocks, datadone, i/1000/1000, i % (1000 * 1000));
exit(0);
......@@ -182,7 +182,7 @@ ctrl_read_error:
argv[0]);
break;
default:
fprintf(stderr, "%s: control read: expected %zi, got %i\n",
fprintf(stderr, "%s: control read: expected %zu, got %i\n",
argv[0], sizeof(ctrl), i);
break;
}
......
......@@ -45,7 +45,7 @@ void print_attr_set(char *name, int nattr, uint32_t mask, uint32_t *val)
for (i = 0; i < nattr; ++i) {
if (!(all || (mask & (1 << i))))
continue;
printf ("Ctrl: %s-%-2i 0x%08x %9i\n",
printf ("Ctrl: %s-%-2i 0x%08x %9u\n",
name, i, val[i], val[i]);
}
}
......@@ -113,7 +113,7 @@ void read_channel(int cfd, int dfd, FILE *log)
prgname);
exit(1);
default:
fprintf(stderr, "%s: ctrl read: %i bytes (expected %zi)\n",
fprintf(stderr, "%s: ctrl read: %i bytes (expected %zu)\n",
prgname, i, sizeof(ctrl));
/* continue anyways */
case sizeof(ctrl):
......@@ -154,9 +154,9 @@ void read_channel(int cfd, int dfd, FILE *log)
ctrl.ssize,
ctrl.nbits,
ctrl.flags,
ctrl.flags & ZIO_CONTROL_LITTLE_ENDIAN
(ctrl.flags & ZIO_CONTROL_LITTLE_ENDIAN)
? "little-endian" :
ctrl.flags & ZIO_CONTROL_BIG_ENDIAN
(ctrl.flags & ZIO_CONTROL_BIG_ENDIAN)
? "big-endian" : "unknown-endian");
printf("Ctrl: stamp %lli.%09lli (%lli)\n",
(long long)ctrl.tstamp.secs,
......
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