All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ASoC: cs42l73: don't use negative array index
@ 2012-04-12 19:54 ` Jesper Juhl
  0 siblings, 0 replies; 4+ messages in thread
From: Jesper Juhl @ 2012-04-12 19:54 UTC (permalink / raw)
  To: linux-kernel
  Cc: alsa-devel, Vinod Koul, Lars-Peter Clausen, Brian Austin,
	Axel Lin, Takashi Iwai, Jaroslav Kysela, Liam Girdwood,
	Mark Brown, joe, brian.austin

If cs42l73_get_mclkx_coeff() returns < 0 (which it can) in
sound/soc/codecs/cs42l73.c::cs42l73_set_mclk(), then we'll be using
the (negative) return value as array index on the very next line of
code - that's bad.

Catch the negative return value and propagate it to the caller (which
checks for it) and things are a bit more sane :-)

Signed-off-by: Jesper Juhl <jj@chaosbits.net>
---
 sound/soc/codecs/cs42l73.c |    2 ++
 1 file changed, 2 insertions(+)

diff --git a/sound/soc/codecs/cs42l73.c b/sound/soc/codecs/cs42l73.c
index 78979b3..07c44b7 100644
--- a/sound/soc/codecs/cs42l73.c
+++ b/sound/soc/codecs/cs42l73.c
@@ -929,6 +929,8 @@ static int cs42l73_set_mclk(struct snd_soc_dai *dai, unsigned int freq)
 
 	/* MCLKX -> MCLK */
 	mclkx_coeff = cs42l73_get_mclkx_coeff(freq);
+	if (mclkx_coeff < 0)
+		return mclkx_coeff;
 
 	mclk = cs42l73_mclkx_coeffs[mclkx_coeff].mclkx /
 		cs42l73_mclkx_coeffs[mclkx_coeff].ratio;
-- 
1.7.10


-- 
Jesper Juhl <jj@chaosbits.net>       http://www.chaosbits.net/
Don't top-post http://www.catb.org/jargon/html/T/top-post.html
Plain text mails only, please.


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH] ASoC: cs42l73: don't use negative array index
@ 2012-04-12 19:54 ` Jesper Juhl
  0 siblings, 0 replies; 4+ messages in thread
From: Jesper Juhl @ 2012-04-12 19:54 UTC (permalink / raw)
  To: linux-kernel
  Cc: brian.austin, Lars-Peter Clausen, Vinod Koul, joe, Takashi Iwai,
	Mark Brown, alsa-devel, Axel Lin, Liam Girdwood

If cs42l73_get_mclkx_coeff() returns < 0 (which it can) in
sound/soc/codecs/cs42l73.c::cs42l73_set_mclk(), then we'll be using
the (negative) return value as array index on the very next line of
code - that's bad.

Catch the negative return value and propagate it to the caller (which
checks for it) and things are a bit more sane :-)

Signed-off-by: Jesper Juhl <jj@chaosbits.net>
---
 sound/soc/codecs/cs42l73.c |    2 ++
 1 file changed, 2 insertions(+)

diff --git a/sound/soc/codecs/cs42l73.c b/sound/soc/codecs/cs42l73.c
index 78979b3..07c44b7 100644
--- a/sound/soc/codecs/cs42l73.c
+++ b/sound/soc/codecs/cs42l73.c
@@ -929,6 +929,8 @@ static int cs42l73_set_mclk(struct snd_soc_dai *dai, unsigned int freq)
 
 	/* MCLKX -> MCLK */
 	mclkx_coeff = cs42l73_get_mclkx_coeff(freq);
+	if (mclkx_coeff < 0)
+		return mclkx_coeff;
 
 	mclk = cs42l73_mclkx_coeffs[mclkx_coeff].mclkx /
 		cs42l73_mclkx_coeffs[mclkx_coeff].ratio;
-- 
1.7.10


-- 
Jesper Juhl <jj@chaosbits.net>       http://www.chaosbits.net/
Don't top-post http://www.catb.org/jargon/html/T/top-post.html
Plain text mails only, please.

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] ASoC: cs42l73: don't use negative array index
  2012-04-12 19:54 ` Jesper Juhl
@ 2012-04-13  9:02   ` Mark Brown
  -1 siblings, 0 replies; 4+ messages in thread
From: Mark Brown @ 2012-04-13  9:02 UTC (permalink / raw)
  To: Jesper Juhl
  Cc: linux-kernel, alsa-devel, Vinod Koul, Lars-Peter Clausen,
	Brian Austin, Axel Lin, Takashi Iwai, Jaroslav Kysela,
	Liam Girdwood, joe

[-- Attachment #1: Type: text/plain, Size: 301 bytes --]

On Thu, Apr 12, 2012 at 09:54:34PM +0200, Jesper Juhl wrote:
> If cs42l73_get_mclkx_coeff() returns < 0 (which it can) in
> sound/soc/codecs/cs42l73.c::cs42l73_set_mclk(), then we'll be using
> the (negative) return value as array index on the very next line of
> code - that's bad.

Applied, thanks.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] ASoC: cs42l73: don't use negative array index
@ 2012-04-13  9:02   ` Mark Brown
  0 siblings, 0 replies; 4+ messages in thread
From: Mark Brown @ 2012-04-13  9:02 UTC (permalink / raw)
  To: Jesper Juhl
  Cc: Brian Austin, Lars-Peter Clausen, Vinod Koul, joe, Takashi Iwai,
	alsa-devel, linux-kernel, Axel Lin, Liam Girdwood


[-- Attachment #1.1: Type: text/plain, Size: 301 bytes --]

On Thu, Apr 12, 2012 at 09:54:34PM +0200, Jesper Juhl wrote:
> If cs42l73_get_mclkx_coeff() returns < 0 (which it can) in
> sound/soc/codecs/cs42l73.c::cs42l73_set_mclk(), then we'll be using
> the (negative) return value as array index on the very next line of
> code - that's bad.

Applied, thanks.

[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

[-- Attachment #2: Type: text/plain, Size: 0 bytes --]



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-04-13  9:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-12 19:54 [PATCH] ASoC: cs42l73: don't use negative array index Jesper Juhl
2012-04-12 19:54 ` Jesper Juhl
2012-04-13  9:02 ` Mark Brown
2012-04-13  9:02   ` Mark Brown

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.