LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [patch]cleanup and error reporting for sound/core/init.c
@ 2007-01-12 13:49 Oliver Neukum
  2007-01-12 17:42 ` Takashi Iwai
  0 siblings, 1 reply; 4+ messages in thread
From: Oliver Neukum @ 2007-01-12 13:49 UTC (permalink / raw)
  To: Jaroslav Kysela, linux-sound, linux-kernel

Hi,

please accept this patch, which makes the control flow clear with
indentation, adds some comments and improves error reporting.

	Regards
		Oliver

Signed-off-by: Oliver Neukum <oneukum@suse.de>

--
--- a/sound/core/init.c	2007-01-12 14:26:47.000000000 +0100
+++ b/sound/core/init.c	2007-01-12 14:46:13.000000000 +0100
@@ -114,22 +114,26 @@
 	if (idx < 0) {
 		int idx2;
 		for (idx2 = 0; idx2 < SNDRV_CARDS; idx2++)
+			/* idx == -1 == 0xffff means: take any free slot */
 			if (~snd_cards_lock & idx & 1<<idx2) {
 				idx = idx2;
 				if (idx >= snd_ecards_limit)
 					snd_ecards_limit = idx + 1;
 				break;
 			}
-	} else if (idx < snd_ecards_limit) {
-		if (snd_cards_lock & (1 << idx))
-			err = -ENODEV;	/* invalid */
-	} else if (idx < SNDRV_CARDS)
-		snd_ecards_limit = idx + 1; /* increase the limit */
-	else
-		err = -ENODEV;
+	} else {
+		 if (idx < snd_ecards_limit) {
+			if (snd_cards_lock & (1 << idx))
+				err = -EBUSY;	/* invalid */
+		} else if (idx < SNDRV_CARDS)
+				snd_ecards_limit = idx + 1; /* increase the limit */
+			else
+				err = -ENODEV;
+	}
 	if (idx < 0 || err < 0) {
 		mutex_unlock(&snd_card_mutex);
-		snd_printk(KERN_ERR "cannot find the slot for index %d (range 0-%i)\n", idx, snd_ecards_limit - 1);
+		snd_printk(KERN_ERR "cannot find the slot for index %d (range 0-%i), error: %d\n",
+			 idx, snd_ecards_limit - 1, err);
 		goto __error;
 	}
 	snd_cards_lock |= 1 << idx;		/* lock it */

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

* Re: [patch]cleanup and error reporting for sound/core/init.c
  2007-01-12 13:49 [patch]cleanup and error reporting for sound/core/init.c Oliver Neukum
@ 2007-01-12 17:42 ` Takashi Iwai
  2007-01-13  6:37   ` Oliver Neukum
  0 siblings, 1 reply; 4+ messages in thread
From: Takashi Iwai @ 2007-01-12 17:42 UTC (permalink / raw)
  To: Oliver Neukum; +Cc: Jaroslav Kysela, linux-sound, linux-kernel

At Fri, 12 Jan 2007 14:49:57 +0100,
Oliver Neukum wrote:
> 
> +	} else {
> +		 if (idx < snd_ecards_limit) {
> +			if (snd_cards_lock & (1 << idx))
> +				err = -EBUSY;	/* invalid */
> +		} else if (idx < SNDRV_CARDS)
> +				snd_ecards_limit = idx + 1; /* increase the limit */
> +			else
> +				err = -ENODEV;

The indent looks strange in the above three lines.
Also, for me it's not much better than before... :)
(all if's are comparisons of idx with other values.)


Takashi

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

* Re: [patch]cleanup and error reporting for sound/core/init.c
  2007-01-12 17:42 ` Takashi Iwai
@ 2007-01-13  6:37   ` Oliver Neukum
  2007-01-16 16:50     ` Takashi Iwai
  0 siblings, 1 reply; 4+ messages in thread
From: Oliver Neukum @ 2007-01-13  6:37 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: Jaroslav Kysela, linux-sound, linux-kernel

Am Freitag, 12. Januar 2007 18:42 schrieb Takashi Iwai:
> At Fri, 12 Jan 2007 14:49:57 +0100,
> Oliver Neukum wrote:
> > 
> > +	} else {
> > +		 if (idx < snd_ecards_limit) {
> > +			if (snd_cards_lock & (1 << idx))
> > +				err = -EBUSY;	/* invalid */
> > +		} else if (idx < SNDRV_CARDS)
> > +				snd_ecards_limit = idx + 1; /* increase the limit */
> > +			else
> > +				err = -ENODEV;
> 
> The indent looks strange in the above three lines.
> Also, for me it's not much better than before... :)
> (all if's are comparisons of idx with other values.)

Hi,

OK, how about this one? The original indentation makes the control
flow very hard to follow.

	Regards
		Oliver

Signed-off-by: Oliver Neukum <oneukum@suse.de>
--

--- sound/core/init.c.alt	2007-01-12 14:26:47.000000000 +0100
+++ sound/core/init.c	2007-01-13 07:34:29.000000000 +0100
@@ -114,22 +114,28 @@
 	if (idx < 0) {
 		int idx2;
 		for (idx2 = 0; idx2 < SNDRV_CARDS; idx2++)
+			/* idx == -1 == 0xffff means: take any free slot */
 			if (~snd_cards_lock & idx & 1<<idx2) {
 				idx = idx2;
 				if (idx >= snd_ecards_limit)
 					snd_ecards_limit = idx + 1;
 				break;
 			}
-	} else if (idx < snd_ecards_limit) {
-		if (snd_cards_lock & (1 << idx))
-			err = -ENODEV;	/* invalid */
-	} else if (idx < SNDRV_CARDS)
-		snd_ecards_limit = idx + 1; /* increase the limit */
-	else
-		err = -ENODEV;
+	} else {
+		 if (idx < snd_ecards_limit) {
+			if (snd_cards_lock & (1 << idx))
+				err = -EBUSY;	/* invalid */
+		} else {
+			if (idx < SNDRV_CARDS)
+				snd_ecards_limit = idx + 1; /* increase the limit */
+			else
+				err = -ENODEV;
+		}
+	}
 	if (idx < 0 || err < 0) {
 		mutex_unlock(&snd_card_mutex);
-		snd_printk(KERN_ERR "cannot find the slot for index %d (range 0-%i)\n", idx, snd_ecards_limit - 1);
+		snd_printk(KERN_ERR "cannot find the slot for index %d (range 0-%i), error: %d\n",
+			 idx, snd_ecards_limit - 1, err);
 		goto __error;
 	}
 	snd_cards_lock |= 1 << idx;		/* lock it */


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

* Re: [patch]cleanup and error reporting for sound/core/init.c
  2007-01-13  6:37   ` Oliver Neukum
@ 2007-01-16 16:50     ` Takashi Iwai
  0 siblings, 0 replies; 4+ messages in thread
From: Takashi Iwai @ 2007-01-16 16:50 UTC (permalink / raw)
  To: Oliver Neukum; +Cc: Jaroslav Kysela, linux-sound, linux-kernel

At Sat, 13 Jan 2007 07:37:59 +0100,
Oliver Neukum wrote:
> 
> Am Freitag, 12. Januar 2007 18:42 schrieb Takashi Iwai:
> > At Fri, 12 Jan 2007 14:49:57 +0100,
> > Oliver Neukum wrote:
> > > 
> > > +	} else {
> > > +		 if (idx < snd_ecards_limit) {
> > > +			if (snd_cards_lock & (1 << idx))
> > > +				err = -EBUSY;	/* invalid */
> > > +		} else if (idx < SNDRV_CARDS)
> > > +				snd_ecards_limit = idx + 1; /* increase the limit */
> > > +			else
> > > +				err = -ENODEV;
> > 
> > The indent looks strange in the above three lines.
> > Also, for me it's not much better than before... :)
> > (all if's are comparisons of idx with other values.)
> 
> Hi,
> 
> OK, how about this one? The original indentation makes the control
> flow very hard to follow.
> 
> 	Regards
> 		Oliver
> 
> Signed-off-by: Oliver Neukum <oneukum@suse.de>

Thanks, now applied to ALSA tree.


Takashi

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

end of thread, other threads:[~2007-01-16 16:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-01-12 13:49 [patch]cleanup and error reporting for sound/core/init.c Oliver Neukum
2007-01-12 17:42 ` Takashi Iwai
2007-01-13  6:37   ` Oliver Neukum
2007-01-16 16:50     ` Takashi Iwai

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