Staging: IIO: Documentation: iio_utils: fix channel array generation.
commit8b68bb20812ba82460e22942ae22ce45880df232
authorMichael Hennerich <michael.hennerich@analog.com>
Tue, 8 Mar 2011 07:55:48 +0000 (8 08:55 +0100)
committerGreg Kroah-Hartman <gregkh@suse.de>
Wed, 9 Mar 2011 23:50:28 +0000 (9 15:50 -0800)
tree1b2c7258f9cfe730992863aa7a33e5e2a5d4fd29
parent14f88f1b07e03b064b86ebc9f2f1ed0719dfaa30
Staging: IIO: Documentation: iio_utils: fix channel array generation.

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.

Changes since V1:
Fix coding style issues.

Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
Acked-by: Jonathan Cameron <jic23@cam.ac.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
drivers/staging/iio/Documentation/iio_utils.h