Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
+ strlen(type)
+ numstrlen
+ 6);
- if (filename == NULL)
+ if (filename == NULL) {
+ closedir(dp);
return -ENOMEM;
+ }
sprintf(filename, "%s%s%d/name",
iio_dir,
type,
number);
nameFile = fopen(filename, "r");
- if (!nameFile)
+ if (!nameFile) {
+ free(filename);
continue;
+ }
free(filename);
fscanf(nameFile, "%s", thisname);
- if (strcmp(name, thisname) == 0)
- return number;
fclose(nameFile);
+ if (strcmp(name, thisname) == 0) {
+ closedir(dp);
+ return number;
+ }
}
}
}
+ closedir(dp);
return -ENODEV;
}