Commit e7475bc0 authored by Federico Vaga's avatar Federico Vaga

lib: check return values

Recent compilers detected that we were not checking the return value
of some functions that we should have checked.

``asprintf`` may fail durint allocation
``read`` may fail in that context because of a ZIO bug

Both are unlikely to happen, but it is better to be informed when they do
Signed-off-by: Federico Vaga's avatarFederico Vaga <federico.vaga@cern.ch>
Signed-off-by: Dimitris Lampridis's avatarDimitris Lampridis <dimitris.lampridis@cern.ch>
parent 6bbeefdc
......@@ -41,12 +41,15 @@ static int adc_flush_input(struct __adc_dev_zio *fa)
/* Read the control until one is there; data is discarded by zio */
while (1) {
int ret;
int i = poll(&p, 1, 0);
if (i < 0)
return -1;
if ((p.revents & POLLIN) == 0)
return 0;
read(fa->fdc, &ctrl, sizeof(ctrl));
ret = read(fa->fdc, &ctrl, sizeof(ctrl));
if (ret != sizeof(ctrl))
return -1;
}
}
......@@ -61,17 +64,24 @@ struct adc_dev *adc_zio_open(const struct adc_board_type *b,
struct stat st;
char *syspath, *devpath, fname[128];
int udev_zio_dir = 1;
int ret;
/* Check if device exists by looking in sysfs */
asprintf(&syspath, "%s/%s-%04x", ZIO_SYS_PATH, b->devname, dev_id);
ret = asprintf(&syspath, "%s/%s-%04x", ZIO_SYS_PATH,
b->devname, dev_id);
if (ret < 0)
goto out_str_alloc_syspath;
if (stat(syspath, &st))
goto out_fa_stat; /* ENOENT or equivalent */
/* ZIO char devices are in /dev/zio or just /dev (older udev) */
if (stat("/dev/zio", &st) < 0)
udev_zio_dir = 0;
asprintf(&devpath, "%s/%s-%04x", (udev_zio_dir ? "/dev/zio" : "/dev"),
b->devname, dev_id);
ret = asprintf(&devpath, "%s/%s-%04x",
(udev_zio_dir ? "/dev/zio" : "/dev"),
b->devname, dev_id);
if (ret < 0)
goto out_str_alloc_devpath;
/* Sysfs path exists, so device is there, hopefully */
fa = calloc(1, sizeof(*fa));
......@@ -124,9 +134,10 @@ out_fa_open:
free(fa);
out_fa_alloc:
free(devpath);
out_str_alloc_devpath:
out_fa_stat:
free(syspath);
out_str_alloc_syspath:
return NULL;
}
......
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