RE: [PATCH] Staging: IIO: Documentation: iio_utils: fix channel array generation.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Greg KH wrote on 2011-03-07:
> On Thu, Mar 03, 2011 at 04:50:03PM +0100, michael.hennerich@xxxxxxxxxx
> wrote:
>> From: Michael Hennerich <michael.hennerich@xxxxxxxxxx>
>>
>> The previous implementation flawed, in case some channels are not
>> enabled. The sorted array would then include channel information of
>> disabled channels, And misses the enabled ones, when the count is
>> reached. More troublesome, the loop would not even terminate.
>>
>> The fix is twofold:
>>
>> First we skip channels that are not enabled.
>> Then we use a tested bubble sort algorithm to sort the array.
>> Since we already allocated exactly the number of bytes we need.
>> We can exercise bubble sort on the original memory.
>> In all cases I've seen, the array is already sorted, so this sort
>> terminates immediately.
>>
>> Signed-off-by: Michael Hennerich <michael.hennerich@xxxxxxxxxx>
>> Acked-by: Jonathan Cameron <jic23@xxxxxxxxx>
>> ---
>>  drivers/staging/iio/Documentation/iio_utils.h |   53 ++++++++++++++-
>>  --------- 1 files changed, 31 insertions(+), 22 deletions(-)
>> diff --git a/drivers/staging/iio/Documentation/iio_utils.h
>> b/drivers/staging/iio/Documentation/iio_utils.h
>> index 1b33c04..da10b4e 100644
>> --- a/drivers/staging/iio/Documentation/iio_utils.h
>> +++ b/drivers/staging/iio/Documentation/iio_utils.h
>> @@ -242,6 +242,25 @@ error_ret:
>>      return ret;
>>  }
>> +/**
>> + * bsort_channel_array_by_index() - reorder so that the array is in
>> +index order
>> + *
>> + **/
>> +
>> +inline 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;
>> +                    }
>> +}
>
> This fails the checkpatch tool.  It might be documentation, but it
> still needs to follow the correct rules :)

This one slipped - updated patch on the way.

Greetings,
Michael

--
Analog Devices GmbH      Wilhelm-Wagenfeld-Str. 6      80807 Muenchen
Sitz der Gesellschaft: Muenchen; Registergericht: Muenchen HRB 40368; Geschaeftsfuehrer:Dr.Carsten Suckrow, Thomas Wessel, William A. Martin, Margaret Seif

--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Input]     [Linux Kernel]     [Linux SCSI]     [X.org]

  Powered by Linux