Merge tag 'for-linus-20150909' of git://git.infradead.org/linux-mtd
[firefly-linux-kernel-4.4.55.git] / tools / iio / iio_utils.c
index 4bbd6e7959cdad471e6cb0bdbf0d0cda915cd743..5eb6793f3972e64ed2c46533cd2e6aa5d65168fa 100644 (file)
@@ -286,17 +286,17 @@ error_free_builtname:
  * @cnt: the amount of array elements
  **/
 
-void bsort_channel_array_by_index(struct iio_channel_info **ci_array, int cnt)
+void bsort_channel_array_by_index(struct iio_channel_info *ci_array, int cnt)
 {
        struct iio_channel_info temp;
        int x, y;
 
        for (x = 0; x < cnt; x++)
                for (y = 0; y < (cnt - 1); y++)
-                       if ((*ci_array)[y].index > (*ci_array)[y + 1].index) {
-                               temp = (*ci_array)[y + 1];
-                               (*ci_array)[y + 1] = (*ci_array)[y];
-                               (*ci_array)[y] = temp;
+                       if (ci_array[y].index > ci_array[y + 1].index) {
+                               temp = ci_array[y + 1];
+                               ci_array[y + 1] = ci_array[y];
+                               ci_array[y] = temp;
                        }
 }
 
@@ -516,7 +516,7 @@ int build_channel_array(const char *device_dir,
 
        free(scan_el_dir);
        /* reorder so that the array is in index order */
-       bsort_channel_array_by_index(ci_array, *counter);
+       bsort_channel_array_by_index(*ci_array, *counter);
 
        return 0;
 
@@ -526,6 +526,8 @@ error_cleanup_array:
                free((*ci_array)[i].generic_name);
        }
        free(*ci_array);
+       *ci_array = NULL;
+       *counter = 0;
 error_close_dir:
        if (dp)
                if (closedir(dp) == -1)