lkml.org 
[lkml]   [2018]   [Jun]   [28]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v3 1/2] iio: dac: Add AD5758 support
On Thu, Jun 28, 2018 at 03:13:32PM +0300, Stefan Popa wrote:
> The AD5758 is a single channel DAC with 16-bit precision which uses the
> SPI interface that operates at clock rates up to 50MHz.
>
> The output can be configured as voltage or current and is available on a
> single terminal.
>
> Datasheet:
> http://www.analog.com/media/en/technical-documentation/data-sheets/ad5758.pdf
>
> Signed-off-by: Stefan Popa <stefan.popa@analog.com>
> ---
[..]
> +static const int ad5758_dc_dc_ilim[6] = {
> + 150000, 200000, 250000, 300000, 350000, 400000
> +};
[..]
> +int cmpfunc(const void *a, const void *b)
> +{
> + return (*(int *)a - *(int *)b);
> +}

Since Kbuild hit a Sparse error in this function, I would also like to
add that the above implementation of cmpfunc() is not safe.

For eg: https://wandbox.org/permlink/MqGnA3nVg7eAN4I7

The following will be safer:

static int cmpfunc(const void *a, const void *b)
{
int arg1 = *(const int*)a;
int arg2 = *(const int*)b;
return (arg1 > arg2) - (arg1 < arg2);
}

[..]
> + index = (int *) bsearch(&tmp, ad5758_dc_dc_ilim,
> + ARRAY_SIZE(ad5758_dc_dc_ilim),
> + sizeof(int), cmpfunc);

Thanks.
--
Himanshu Jha
Undergraduate Student
Department of Electronics & Communication
Guru Tegh Bahadur Institute of Technology

\
 
 \ /
  Last update: 2018-06-28 23:49    [W:0.156 / U:0.160 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site