alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: Mark Brown <broonie@kernel.org>
Cc: alsa-devel@alsa-project.org, Liam Girdwood <lgirdwood@gmail.com>
Subject: [PATCH 3/9] ASoC: ab8500: Fix invalid cast to long pointer
Date: Wed, 30 Oct 2013 08:35:01 +0100	[thread overview]
Message-ID: <1383118507-21503-4-git-send-email-tiwai@suse.de> (raw)
In-Reply-To: <1383118507-21503-1-git-send-email-tiwai@suse.de>

Don't cast to long pointers blindly just for using find_first_bit()
and co.  This is certainly not portable at all.

Reimplement the code with ffs() and fls() instead.  This is a slight
optimization, too.

Spotted by coverity CID 1056484 and 1056485.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 sound/soc/codecs/ab8500-codec.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/sound/soc/codecs/ab8500-codec.c b/sound/soc/codecs/ab8500-codec.c
index 0693faf7effb..272df538c1d5 100644
--- a/sound/soc/codecs/ab8500-codec.c
+++ b/sound/soc/codecs/ab8500-codec.c
@@ -2301,17 +2301,17 @@ static int ab8500_codec_set_dai_tdm_slot(struct snd_soc_dai *dai,
 	case 0:
 		break;
 	case 1:
-		slot = find_first_bit((unsigned long *)&tx_mask, 32);
+		slot = ffs(tx_mask);
 		snd_soc_update_bits(codec, AB8500_DASLOTCONF1, mask, slot);
 		snd_soc_update_bits(codec, AB8500_DASLOTCONF3, mask, slot);
 		snd_soc_update_bits(codec, AB8500_DASLOTCONF2, mask, slot);
 		snd_soc_update_bits(codec, AB8500_DASLOTCONF4, mask, slot);
 		break;
 	case 2:
-		slot = find_first_bit((unsigned long *)&tx_mask, 32);
+		slot = ffs(tx_mask);
 		snd_soc_update_bits(codec, AB8500_DASLOTCONF1, mask, slot);
 		snd_soc_update_bits(codec, AB8500_DASLOTCONF3, mask, slot);
-		slot = find_next_bit((unsigned long *)&tx_mask, 32, slot + 1);
+		slot = fls(tx_mask);
 		snd_soc_update_bits(codec, AB8500_DASLOTCONF2, mask, slot);
 		snd_soc_update_bits(codec, AB8500_DASLOTCONF4, mask, slot);
 		break;
@@ -2342,18 +2342,18 @@ static int ab8500_codec_set_dai_tdm_slot(struct snd_soc_dai *dai,
 	case 0:
 		break;
 	case 1:
-		slot = find_first_bit((unsigned long *)&rx_mask, 32);
+		slot = ffs(rx_mask);
 		snd_soc_update_bits(codec, AB8500_ADSLOTSEL(slot),
 				AB8500_MASK_SLOT(slot),
 				AB8500_ADSLOTSELX_AD_OUT_TO_SLOT(AB8500_AD_OUT3, slot));
 		break;
 	case 2:
-		slot = find_first_bit((unsigned long *)&rx_mask, 32);
+		slot = ffs(rx_mask);
 		snd_soc_update_bits(codec,
 				AB8500_ADSLOTSEL(slot),
 				AB8500_MASK_SLOT(slot),
 				AB8500_ADSLOTSELX_AD_OUT_TO_SLOT(AB8500_AD_OUT3, slot));
-		slot = find_next_bit((unsigned long *)&rx_mask, 32, slot + 1);
+		slot = fls(rx_mask);
 		snd_soc_update_bits(codec,
 				AB8500_ADSLOTSEL(slot),
 				AB8500_MASK_SLOT(slot),
-- 
1.8.4.1

  parent reply	other threads:[~2013-10-30  7:32 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-30  7:34 [PATCH 0/9] ASoC: Yet another small fixes Takashi Iwai
2013-10-30  7:34 ` [PATCH 1/9] ASoC: ab8500: Add missing of NULL check of devm_kzalloc() Takashi Iwai
2013-10-30 16:33   ` Mark Brown
2013-10-30  7:35 ` [PATCH 2/9] ASoC: ab8500: Add missing return in ab8500_codec_set_dai_fmt() Takashi Iwai
2013-10-30  7:35 ` Takashi Iwai [this message]
2013-10-30 16:34   ` [PATCH 3/9] ASoC: ab8500: Fix invalid cast to long pointer Mark Brown
2013-10-30  7:35 ` [PATCH 4/9] ASoC: wm_hubs: Add missing break in hp_supply_event() Takashi Iwai
2013-10-30 16:35   ` Mark Brown
2013-10-30  7:35 ` [PATCH 5/9] ASoC: wm0010: Fix possible out-of-bounds array read Takashi Iwai
2013-10-30 16:38   ` Mark Brown
2013-10-30 17:32     ` Takashi Iwai
2013-10-30 21:32       ` Mark Brown
2013-10-30  7:35 ` [PATCH 6/9] ASoC: max98095: Add missing negative channel checks Takashi Iwai
2013-10-30 16:46   ` Mark Brown
2013-10-30 17:36     ` Takashi Iwai
2013-10-30 21:31       ` Mark Brown
2013-10-31  7:24         ` Takashi Iwai
2013-10-30  7:35 ` [PATCH 7/9] ASoC: ml26124: Fix negative array index read Takashi Iwai
2013-10-30 16:48   ` Mark Brown
2013-10-30 17:40     ` Takashi Iwai
2013-10-30 21:33       ` Mark Brown
2013-10-30  7:35 ` [PATCH 8/9] ASoC: rt5640: Fix ignored error checks Takashi Iwai
2013-10-30 16:49   ` Mark Brown
2013-10-30  7:35 ` [PATCH 9/9] ASoC: wm8996: Fix negative array index read Takashi Iwai
2013-10-30 16:51   ` Mark Brown
2013-10-30 17:33     ` Takashi Iwai

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=1383118507-21503-4-git-send-email-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=lgirdwood@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;
as well as URLs for NNTP newsgroup(s).