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.p...@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

Reply via email to