All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lars-Peter Clausen <lars@metafoo.de>
To: Tim Gardner <tim.gardner@canonical.com>
Cc: linux-kernel@vger.kernel.org, Liam Girdwood <lgirdwood@gmail.com>,
	Mark Brown <broonie@opensource.wolfsonmicro.com>,
	Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.de>,
	device-drivers-devel@blackfin.uclinux.org,
	alsa-devel@alsa-project.org
Subject: Re: [PATCH] ASoC: adau1373: adau1373_hw_params: Silence overflow warning
Date: Mon, 11 Mar 2013 19:55:17 +0100	[thread overview]
Message-ID: <513E2895.6040904@metafoo.de> (raw)
In-Reply-To: <513DFA55.2050104@canonical.com>

On 03/11/2013 04:37 PM, Tim Gardner wrote:
> On 03/11/2013 04:01 AM, Lars-Peter Clausen wrote:
>> On 03/10/2013 06:34 PM, Tim Gardner wrote:
>>> ADAU1373_BCLKDIV_SOURCE is defined as BIT(5) which uses UL constants. On
>>> amd64 the result of the ones complement operator is then truncated to
>>> unsigned int according to the prototype of snd_soc_update_bits(). I think
>>> gcc is correctly warning that the upper 32 bits are lost.
>>>
>>> sound/soc/codecs/adau1373.c: In function 'adau1373_hw_params':
>>> sound/soc/codecs/adau1373.c:940:3: warning: large integer implicitly truncated to unsigned type [-Woverflow]
>>>
>>> gcc version 4.6.3
>>>
>>> Cc: Lars-Peter Clausen <lars@metafoo.de>
>>> Cc: Liam Girdwood <lgirdwood@gmail.com>
>>> Cc: Mark Brown <broonie@opensource.wolfsonmicro.com>
>>> Cc: Jaroslav Kysela <perex@perex.cz>
>>> Cc: Takashi Iwai <tiwai@suse.de>
>>> Cc: device-drivers-devel@blackfin.uclinux.org
>>> Cc: alsa-devel@alsa-project.org
>>> Signed-off-by: Tim Gardner <tim.gardner@canonical.com>
>>> ---
>>>  sound/soc/codecs/adau1373.c |    2 +-
>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/sound/soc/codecs/adau1373.c b/sound/soc/codecs/adau1373.c
>>> index 068b3ae..56ed788 100644
>>> --- a/sound/soc/codecs/adau1373.c
>>> +++ b/sound/soc/codecs/adau1373.c
>>> @@ -132,7 +132,7 @@ struct adau1373 {
>>>  #define ADAU1373_DAI_FORMAT_I2S		0x2
>>>  #define ADAU1373_DAI_FORMAT_DSP		0x3
>>>  
>>> -#define ADAU1373_BCLKDIV_SOURCE		BIT(5)
>>> +#define ADAU1373_BCLKDIV_SOURCE		(unsigned int)BIT(5)
>>
>> Hm, that's a bit ugly. How about the following instead:
>>
>> diff --git a/sound/soc/codecs/adau1373.c b/sound/soc/codecs/adau1373.c
>> index 068b3ae..1aa10dd 100644
>> --- a/sound/soc/codecs/adau1373.c
>> +++ b/sound/soc/codecs/adau1373.c
>> @@ -133,6 +133,8 @@ struct adau1373 {
>>  #define ADAU1373_DAI_FORMAT_DSP		0x3
>>
>>  #define ADAU1373_BCLKDIV_SOURCE		BIT(5)
>> +#define ADAU1373_BCLKDIV_SR_MASK	(0x07 << 2)
>> +#define ADAU1373_BCLKDIV_BCLK_MASK	0x03
>>  #define ADAU1373_BCLKDIV_32		0x03
>>  #define ADAU1373_BCLKDIV_64		0x02
>>  #define ADAU1373_BCLKDIV_128		0x01
>> @@ -937,7 +939,8 @@ static int adau1373_hw_params(struct snd_pcm_substream
>> *substream,
>>  	adau1373_dai->enable_src = (div != 0);
>>
>>  	snd_soc_update_bits(codec, ADAU1373_BCLKDIV(dai->id),
>> -		~ADAU1373_BCLKDIV_SOURCE, (div << 2) | ADAU1373_BCLKDIV_64);
>> +		ADAU1373_BCLKDIV_SR_MASK | ADAU1373_BCLKDIV_BCLK_MASK,
>> +		(div << 2) | ADAU1373_BCLKDIV_64);
>>
>>  	switch (params_format(params)) {
>>  	case SNDRV_PCM_FORMAT_S16_LE:
>>
>>
> 
> That seems way more complicated then need be. It also uses 2 bits in the
> mask whereas the original code only used 1, e.g., bit 5. Is that correct ?

The BCLKDIV has three fields. The bitclock divider (bit 0-1), the samplerate
(bit 2-4) and the source select (bit 5). Here we want to update the bitclock
divider field and the samplerate field. When I wrote the code I was lazy and
used ~ADAU1373_BCLKDIV_SOURCE as the mask, which for this register is
functional equivalent to ADAU1373_BCLKDIV_SR_MASK | ADAU1373_BCLKDIV_BCLK_MASK.

> 
> How about just open coding the macro thusly:
> 
> #define ADAU1373_BCLKDIV_SOURCE (1<<5) /*BIT(5)*/

But now there is a inconsistency where we sometimes use (1<<x) and sometimes
BIT(x). I prefer my solution.

- Lars

  reply	other threads:[~2013-03-11 18:55 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-10 17:34 [PATCH] ASoC: adau1373: adau1373_hw_params: Silence overflow warning Tim Gardner
2013-03-11 10:01 ` Lars-Peter Clausen
2013-03-11 15:37   ` Tim Gardner
2013-03-11 18:55     ` Lars-Peter Clausen [this message]
2013-03-11 19:18       ` [PATCH linux-next v2] " Tim Gardner
2013-03-11 19:26         ` Lars-Peter Clausen
2013-03-12 18:47         ` Mark Brown
2013-03-12 18:47           ` Mark Brown
2013-03-12 19:17           ` Tim Gardner
2013-03-12 19:39             ` Mark Brown
2013-03-12 19:39               ` Mark Brown

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=513E2895.6040904@metafoo.de \
    --to=lars@metafoo.de \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@opensource.wolfsonmicro.com \
    --cc=device-drivers-devel@blackfin.uclinux.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=tim.gardner@canonical.com \
    --cc=tiwai@suse.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.