Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tools: iio: generic_buffer: Fix generic scale extraction

When using generic_buffer to read data, the scale is not properly
detected for scale shared by type. This is caused by a problem
with the generation of generic name out of the full name.
E.g.: for current->name in_accel_z, the extracted generic name
is "in" (when it should be "in_accel"). This is used in generic_buffer
to generate scale and offset paths (in_accel_scale).

Consider the in_ or out_ prefix when extracting the generic name
from the full name.

Signed-off-by: Irina Tirdea <irina.tirdea@intel.com>
Reviewed-by: Daniel Baluta <daniel.baluta@intel.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>

authored by

Irina Tirdea and committed by
Jonathan Cameron
d9d7b990 8ea06893

+17 -3
+17 -3
tools/iio/iio_utils.c
··· 20 20 21 21 const char *iio_dir = "/sys/bus/iio/devices/"; 22 22 23 + static char * const iio_direction[] = { 24 + "in", 25 + "out", 26 + }; 27 + 23 28 /** 24 29 * iioutils_break_up_name() - extract generic name from full channel name 25 30 * @full_name: the full channel name ··· 35 30 { 36 31 char *current; 37 32 char *w, *r; 38 - char *working; 33 + char *working, *prefix = ""; 34 + int i; 39 35 40 - current = strdup(full_name); 36 + for (i = 0; i < sizeof(iio_direction) / sizeof(iio_direction[0]); i++) 37 + if (!strncmp(full_name, iio_direction[i], 38 + strlen(iio_direction[i]))) { 39 + prefix = iio_direction[i]; 40 + break; 41 + } 42 + 43 + current = strdup(full_name + strlen(prefix) + 1); 41 44 working = strtok(current, "_\0"); 45 + 42 46 w = working; 43 47 r = working; 44 48 ··· 59 45 r++; 60 46 } 61 47 *w = '\0'; 62 - *generic_name = strdup(working); 48 + asprintf(generic_name, "%s_%s", prefix, working); 63 49 free(current); 64 50 65 51 return 0;