The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Himanshu Jha <himanshujha199640@gmail.com>
To: Stefan Popa <stefan.popa@analog.com>
Cc: jic23@kernel.org, Michael.Hennerich@analog.com, lars@metafoo.de,
	knaack.h@gmx.de, pmeerw@pmeerw.net, mchehab@kernel.org,
	davem@davemloft.net, gregkh@linuxfoundation.org,
	akpm@linux-foundation.org, linus.walleij@linaro.org,
	rdunlap@infradead.org, lukas@wunner.de,
	Ismail.Kose@maximintegrated.com, vilhelm.gray@gmail.com,
	sean.nyekjaer@prevas.dk, pombredanne@nexb.com,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 1/2] iio: dac: Add AD5758 support
Date: Fri, 29 Jun 2018 03:18:18 +0530	[thread overview]
Message-ID: <20180628214818.GA3577@himanshu-Vostro-3559> (raw)
In-Reply-To: <1530188012-28253-1-git-send-email-stefan.popa@analog.com>

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

  parent reply	other threads:[~2018-06-28 21:48 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-28 12:13 [PATCH v3 1/2] iio: dac: Add AD5758 support Stefan Popa
2018-06-28 15:37 ` kbuild test robot
2018-06-28 15:37 ` [RFC PATCH] iio: dac: cmpfunc() can be static kbuild test robot
2018-06-28 21:48 ` Himanshu Jha [this message]
2018-06-29  5:35   ` [PATCH v3 1/2] iio: dac: Add AD5758 support Himanshu Jha

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180628214818.GA3577@himanshu-Vostro-3559 \
    --to=himanshujha199640@gmail.com \
    --cc=Ismail.Kose@maximintegrated.com \
    --cc=Michael.Hennerich@analog.com \
    --cc=akpm@linux-foundation.org \
    --cc=davem@davemloft.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=jic23@kernel.org \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linus.walleij@linaro.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lukas@wunner.de \
    --cc=mchehab@kernel.org \
    --cc=pmeerw@pmeerw.net \
    --cc=pombredanne@nexb.com \
    --cc=rdunlap@infradead.org \
    --cc=sean.nyekjaer@prevas.dk \
    --cc=stefan.popa@analog.com \
    --cc=vilhelm.gray@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox