tools: iio: generic_buffer: Fix generic scale extraction
PATCH 1/1 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.
--- tools/iio/iio_utils.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-)
tools/iio/iio_utils.c +17 -3
@@ -18,6 +18,11 @@const char *iio_dir ="/sys/bus/iio/devices/" ; +static char *const iio_direction[] = { +"in" , +"out" , +}; +/** * iioutils_break_up_name() - extract generic name from full channel name * @full_name: the full channel name
@@ -28,10 +33,19 @@ int iioutils_break_up_name(const char *full_name, {char *current;char *w, *r; -char *working; +char *working, *prefix ="" ; +int i; - current =strdup (full_name); +for (i =0 ; i <sizeof (iio_direction) /sizeof (iio_direction[0 ]); i++) +if (!strncmp (full_name, iio_direction[i], +strlen (iio_direction[i]))) { + prefix = iio_direction[i]; +break ; + } + + current =strdup (full_name +strlen (prefix) +1 ); working =strtok (current,"_\0" ); + w = working; r = working;
@@ -43,7 +57,7 @@ int iioutils_break_up_name(const char *full_name, r++; } *w ='\0' ; - *generic_name =strdup (working); +asprintf (generic_name,"%s_%s" , prefix, working);free (current);return 0 ;
Signature · 1 line
1.9.1
Quoted 11 lines · Irina Tirdea
When using
generic_bufferto 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.: forcurrent->namein_accel_z, the extracted generic name is "in" (when it should be "in_accel"). This is used ingeneric_bufferto generate scale and offset paths (in_accel_scale).Consider the
in_orout_prefix when extracting the generic name from the full name.Signed-off-by Irina Tirdea <[email protected]>
Quoted 58 lines
--- tools/iio/iio_utils.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-)tools/iio/iio_utils.c +17
-4@@ -18,6 +18,11 @@const char *iio_dir ="/sys/bus/iio/devices/" ; +static char *const iio_direction[] = { +"in" , +"out" , +}; +/** * iioutils_break_up_name() - extract generic name from full channel name * @full_name: the full channel name @@ -28,10 +33,19 @@ int iioutils_break_up_name(const char *full_name, {char *current;char *w, *r; -char *working; +char *working, *prefix ="" ; +int i; - current =strdup (full_name); +for (i =0 ; i <sizeof (iio_direction) /sizeof (iio_direction[0 ]); i++) +if (!strncmp (full_name, iio_direction[i], +strlen (iio_direction[i]))) { + prefix = iio_direction[i]; +break ; + } + + current =strdup (full_name +strlen (prefix) +1 ); working =strtok (current,"_\0" ); + w = working; r = working;@@ -43,7 +57,7 @@ int iioutils_break_up_name(const char *full_name, r++; } *w ='\0' ; - *generic_name =strdup (working); +asprintf (generic_name,"%s_%s" , prefix, working);free (current);return 0 ; --1.9.1
--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 8 lines · Daniel Baluta
Quoted 7 lines · Irina Tirdea
When using
generic_bufferto 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.: forcurrent->namein_accel_z, the extracted generic name is "in" (when it should be "in_accel"). This is used ingeneric_bufferto generate scale and offset paths (in_accel_scale).
Quoted 6 lines
Quoted 4 lines
Consider the
in_orout_prefix when extracting the generic name from the full name.Signed-off-by Irina Tirdea <[email protected]>Reviewed-by Daniel Baluta <[email protected]>
Applied to the togreg branch of iio.git. Might be worth backporting once it is in mainline.
J
Quoted 64 lines
Quoted 55 lines
--- tools/iio/iio_utils.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-)tools/iio/iio_utils.c +17
-4@@ -18,6 +18,11 @@const char *iio_dir ="/sys/bus/iio/devices/" ; +static char *const iio_direction[] = { +"in" , +"out" , +}; +/** * iioutils_break_up_name() - extract generic name from full channel name * @full_name: the full channel name @@ -28,10 +33,19 @@ int iioutils_break_up_name(const char *full_name, {char *current;char *w, *r; -char *working; +char *working, *prefix ="" ; +int i; - current =strdup (full_name); +for (i =0 ; i <sizeof (iio_direction) /sizeof (iio_direction[0 ]); i++) +if (!strncmp (full_name, iio_direction[i], +strlen (iio_direction[i]))) { + prefix = iio_direction[i]; +break ; + } + + current =strdup (full_name +strlen (prefix) +1 ); working =strtok (current,"_\0" ); + w = working; r = working;@@ -43,7 +57,7 @@ int iioutils_break_up_name(const char *full_name, r++; } *w ='\0' ; - *generic_name =strdup (working); +asprintf (generic_name,"%s_%s" , prefix, working);free (current);return 0 ; --1.9.1
Quoted 4 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html