kernel-janitors.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [patch] ALSA: bits vs bytes bug in snd_card_create()
@ 2014-01-23  8:21 Dan Carpenter
  2014-01-23  8:36 ` Takashi Iwai
  2014-01-23  8:55 ` walter harms
  0 siblings, 2 replies; 6+ messages in thread
From: Dan Carpenter @ 2014-01-23  8:21 UTC (permalink / raw)
  To: Jaroslav Kysela; +Cc: Takashi Iwai, Yacine Belkadi, alsa-devel, kernel-janitors

The test here is intended intended to prevent shift wrapping bugs when
we do "1U << idx2".  We should consider the number of bits in a u32
instead of the number of bytes.

Fixes: 7bb2491b35a2 ('ALSA: Add kconfig to specify the max card numbers')
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
WARNING:  Please check this one carefully because I might be wrong.

diff --git a/sound/core/init.c b/sound/core/init.c
index 1351f22f651c..e9e3db321e64 100644
--- a/sound/core/init.c
+++ b/sound/core/init.c
@@ -183,7 +183,7 @@ int snd_card_create(int idx, const char *xid,
 	if (idx < 0) {
 		for (idx2 = 0; idx2 < SNDRV_CARDS; idx2++) {
 			/* idx = -1 = 0xffff means: take any free slot */
-			if (idx2 < sizeof(int) && !(idx & (1U << idx2)))
+			if (idx2 < 32 && !(idx & (1U << idx2)))
 				continue;
 			if (!test_bit(idx2, snd_cards_lock)) {
 				if (!slots[idx2] || !*slots[idx2]) {

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

* Re: [patch] ALSA: bits vs bytes bug in snd_card_create()
  2014-01-23  8:21 [patch] ALSA: bits vs bytes bug in snd_card_create() Dan Carpenter
@ 2014-01-23  8:36 ` Takashi Iwai
  2014-01-23 10:48   ` Takashi Iwai
  2014-01-23  8:55 ` walter harms
  1 sibling, 1 reply; 6+ messages in thread
From: Takashi Iwai @ 2014-01-23  8:36 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Jaroslav Kysela, Yacine Belkadi, alsa-devel, kernel-janitors

At Thu, 23 Jan 2014 11:21:28 +0300,
Dan Carpenter wrote:
> 
> The test here is intended intended to prevent shift wrapping bugs when
> we do "1U << idx2".  We should consider the number of bits in a u32
> instead of the number of bytes.
> 
> Fixes: 7bb2491b35a2 ('ALSA: Add kconfig to specify the max card numbers')
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> WARNING:  Please check this one carefully because I might be wrong.

You're correct.  I obviously didn't test more than 4.
Applied (with Cc to stable) now, thanks.


Takashi

> 
> diff --git a/sound/core/init.c b/sound/core/init.c
> index 1351f22f651c..e9e3db321e64 100644
> --- a/sound/core/init.c
> +++ b/sound/core/init.c
> @@ -183,7 +183,7 @@ int snd_card_create(int idx, const char *xid,
>  	if (idx < 0) {
>  		for (idx2 = 0; idx2 < SNDRV_CARDS; idx2++) {
>  			/* idx = -1 = 0xffff means: take any free slot */
> -			if (idx2 < sizeof(int) && !(idx & (1U << idx2)))
> +			if (idx2 < 32 && !(idx & (1U << idx2)))
>  				continue;
>  			if (!test_bit(idx2, snd_cards_lock)) {
>  				if (!slots[idx2] || !*slots[idx2]) {
> 

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

* Re: [patch] ALSA: bits vs bytes bug in snd_card_create()
  2014-01-23  8:21 [patch] ALSA: bits vs bytes bug in snd_card_create() Dan Carpenter
  2014-01-23  8:36 ` Takashi Iwai
@ 2014-01-23  8:55 ` walter harms
  2014-01-23  9:02   ` Takashi Iwai
  1 sibling, 1 reply; 6+ messages in thread
From: walter harms @ 2014-01-23  8:55 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Jaroslav Kysela, Takashi Iwai, Yacine Belkadi, alsa-devel,
	kernel-janitors



Am 23.01.2014 09:21, schrieb Dan Carpenter:
> The test here is intended intended to prevent shift wrapping bugs when
> we do "1U << idx2".  We should consider the number of bits in a u32
> instead of the number of bytes.
> 
> Fixes: 7bb2491b35a2 ('ALSA: Add kconfig to specify the max card numbers')
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> WARNING:  Please check this one carefully because I might be wrong.
> 
> diff --git a/sound/core/init.c b/sound/core/init.c
> index 1351f22f651c..e9e3db321e64 100644
> --- a/sound/core/init.c
> +++ b/sound/core/init.c
> @@ -183,7 +183,7 @@ int snd_card_create(int idx, const char *xid,
>  	if (idx < 0) {
>  		for (idx2 = 0; idx2 < SNDRV_CARDS; idx2++) {
>  			/* idx = -1 = 0xffff means: take any free slot */
> -			if (idx2 < sizeof(int) && !(idx & (1U << idx2)))
> +			if (idx2 < 32 && !(idx & (1U << idx2)))
>  				continue;
>  			if (!test_bit(idx2, snd_cards_lock)) {
>  				if (!slots[idx2] || !*slots[idx2]) {
> --

Funny bug,
to be 100% sure you could multiply by CHAR_BIT ;)

other code simple does (1UL << (nr & 31))
on the other side a check like:

#if SNDRV_CARDS > 32
# error to much sound
#endif

whould give the user a hint what is going on instead of silently ignoring
that error.

re,
 wh


> To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

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

* Re: [patch] ALSA: bits vs bytes bug in snd_card_create()
  2014-01-23  8:55 ` walter harms
@ 2014-01-23  9:02   ` Takashi Iwai
  2014-01-23  9:27     ` walter harms
  0 siblings, 1 reply; 6+ messages in thread
From: Takashi Iwai @ 2014-01-23  9:02 UTC (permalink / raw)
  To: wharms
  Cc: Dan Carpenter, Jaroslav Kysela, Yacine Belkadi, alsa-devel,
	kernel-janitors

At Thu, 23 Jan 2014 09:55:31 +0100,
walter harms wrote:
> 
> 
> Am 23.01.2014 09:21, schrieb Dan Carpenter:
> > The test here is intended intended to prevent shift wrapping bugs when
> > we do "1U << idx2".  We should consider the number of bits in a u32
> > instead of the number of bytes.
> > 
> > Fixes: 7bb2491b35a2 ('ALSA: Add kconfig to specify the max card numbers')
> > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> > ---
> > WARNING:  Please check this one carefully because I might be wrong.
> > 
> > diff --git a/sound/core/init.c b/sound/core/init.c
> > index 1351f22f651c..e9e3db321e64 100644
> > --- a/sound/core/init.c
> > +++ b/sound/core/init.c
> > @@ -183,7 +183,7 @@ int snd_card_create(int idx, const char *xid,
> >  	if (idx < 0) {
> >  		for (idx2 = 0; idx2 < SNDRV_CARDS; idx2++) {
> >  			/* idx = -1 = 0xffff means: take any free slot */
> > -			if (idx2 < sizeof(int) && !(idx & (1U << idx2)))
> > +			if (idx2 < 32 && !(idx & (1U << idx2)))
> >  				continue;
> >  			if (!test_bit(idx2, snd_cards_lock)) {
> >  				if (!slots[idx2] || !*slots[idx2]) {
> > --
> 
> Funny bug,
> to be 100% sure you could multiply by CHAR_BIT ;)
> 
> other code simple does (1UL << (nr & 31))
> on the other side a check like:
> 
> #if SNDRV_CARDS > 32
> # error to much sound
> #endif
> 
> whould give the user a hint what is going on instead of silently ignoring
> that error.

SNDRV_CARDS can be more than 32.  That's why the check was
introduced.


Takashi

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

* Re: [patch] ALSA: bits vs bytes bug in snd_card_create()
  2014-01-23  9:02   ` Takashi Iwai
@ 2014-01-23  9:27     ` walter harms
  0 siblings, 0 replies; 6+ messages in thread
From: walter harms @ 2014-01-23  9:27 UTC (permalink / raw)
  To: Takashi Iwai
  Cc: Dan Carpenter, Jaroslav Kysela, Yacine Belkadi, alsa-devel,
	kernel-janitors



Am 23.01.2014 10:02, schrieb Takashi Iwai:
> At Thu, 23 Jan 2014 09:55:31 +0100,
> walter harms wrote:
>>
>>
>> Am 23.01.2014 09:21, schrieb Dan Carpenter:
>>> The test here is intended intended to prevent shift wrapping bugs when
>>> we do "1U << idx2".  We should consider the number of bits in a u32
>>> instead of the number of bytes.
>>>
>>> Fixes: 7bb2491b35a2 ('ALSA: Add kconfig to specify the max card numbers')
>>> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
>>> ---
>>> WARNING:  Please check this one carefully because I might be wrong.
>>>
>>> diff --git a/sound/core/init.c b/sound/core/init.c
>>> index 1351f22f651c..e9e3db321e64 100644
>>> --- a/sound/core/init.c
>>> +++ b/sound/core/init.c
>>> @@ -183,7 +183,7 @@ int snd_card_create(int idx, const char *xid,
>>>  	if (idx < 0) {
>>>  		for (idx2 = 0; idx2 < SNDRV_CARDS; idx2++) {
>>>  			/* idx = -1 = 0xffff means: take any free slot */
>>> -			if (idx2 < sizeof(int) && !(idx & (1U << idx2)))
>>> +			if (idx2 < 32 && !(idx & (1U << idx2)))
>>>  				continue;
>>>  			if (!test_bit(idx2, snd_cards_lock)) {
>>>  				if (!slots[idx2] || !*slots[idx2]) {
>>> --
>>
>> Funny bug,
>> to be 100% sure you could multiply by CHAR_BIT ;)
>>
>> other code simple does (1UL << (nr & 31))
>> on the other side a check like:
>>
>> #if SNDRV_CARDS > 32
>> # error to much sound
>> #endif
>>
>> whould give the user a hint what is going on instead of silently ignoring
>> that error.
> 
> SNDRV_CARDS can be more than 32.  That's why the check was
> introduced.
> 

yes of cause, but so far i understand this code will do "continue" if SNDRV_CARDS
is more that 31, no warning.
(warning Start academic discussion):
If anyone ever has more that 31 soundcard he will wonder why 31 are working but the
rest will remain silent. It would be nice to have a idea that there is an internal limit
and it is not sufficient to change  SNDRV_CARDS from 8 to 256. (did i understand the code
correctly ?) and there is no warning.

re,
 wh



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

* Re: [patch] ALSA: bits vs bytes bug in snd_card_create()
  2014-01-23  8:36 ` Takashi Iwai
@ 2014-01-23 10:48   ` Takashi Iwai
  0 siblings, 0 replies; 6+ messages in thread
From: Takashi Iwai @ 2014-01-23 10:48 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Jaroslav Kysela, Yacine Belkadi, alsa-devel, kernel-janitors

At Thu, 23 Jan 2014 09:36:24 +0100,
Takashi Iwai wrote:
> 
> At Thu, 23 Jan 2014 11:21:28 +0300,
> Dan Carpenter wrote:
> > 
> > The test here is intended intended to prevent shift wrapping bugs when
> > we do "1U << idx2".  We should consider the number of bits in a u32
> > instead of the number of bytes.
> > 
> > Fixes: 7bb2491b35a2 ('ALSA: Add kconfig to specify the max card numbers')
> > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> > ---
> > WARNING:  Please check this one carefully because I might be wrong.
> 
> You're correct.  I obviously didn't test more than 4.
> Applied (with Cc to stable) now, thanks.

I found there is another place doing it wrongly (a few lines above
there), so fixed similarly in the same patch.

(And, yes, the code should be refactored; the patch will be sent soon
 later.)


Takashi

-- 8< --
From: Dan Carpenter <dan.carpenter@oracle.com>
Subject: [PATCH] ALSA: bits vs bytes bug in snd_card_create()

The test here is intended intended to prevent shift wrapping bugs when
we do "1U << idx2".  We should consider the number of bits in a u32
instead of the number of bytes.

[fix another chunk similarly by tiwai]

Fixes: 7bb2491b35a2 ('ALSA: Add kconfig to specify the max card numbers')
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 sound/core/init.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sound/core/init.c b/sound/core/init.c
index 1351f22f651c..e3c93cd77ee7 100644
--- a/sound/core/init.c
+++ b/sound/core/init.c
@@ -170,7 +170,7 @@ int snd_card_create(int idx, const char *xid,
 	if (idx < 0) {
 		for (idx2 = 0; idx2 < SNDRV_CARDS; idx2++) {
 			/* idx = -1 = 0xffff means: take any free slot */
-			if (idx2 < sizeof(int) && !(idx & (1U << idx2)))
+			if (idx2 < 32 && !(idx & (1U << idx2)))
 				continue;
 			if (!test_bit(idx2, snd_cards_lock)) {
 				if (module_slot_match(module, idx2)) {
@@ -183,7 +183,7 @@ int snd_card_create(int idx, const char *xid,
 	if (idx < 0) {
 		for (idx2 = 0; idx2 < SNDRV_CARDS; idx2++) {
 			/* idx = -1 = 0xffff means: take any free slot */
-			if (idx2 < sizeof(int) && !(idx & (1U << idx2)))
+			if (idx2 < 32 && !(idx & (1U << idx2)))
 				continue;
 			if (!test_bit(idx2, snd_cards_lock)) {
 				if (!slots[idx2] || !*slots[idx2]) {
-- 
1.8.5.2


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

end of thread, other threads:[~2014-01-23 10:48 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-01-23  8:21 [patch] ALSA: bits vs bytes bug in snd_card_create() Dan Carpenter
2014-01-23  8:36 ` Takashi Iwai
2014-01-23 10:48   ` Takashi Iwai
2014-01-23  8:55 ` walter harms
2014-01-23  9:02   ` Takashi Iwai
2014-01-23  9:27     ` walter harms

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).