public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* ixp4xx_hss: Little improvement in create_chan function
@ 2008-11-26 17:38 Miguel Ángel Álvarez
  2008-12-04 20:54 ` Krzysztof Halasa
  0 siblings, 1 reply; 3+ messages in thread
From: Miguel Ángel Álvarez @ 2008-11-26 17:38 UTC (permalink / raw)
  To: netdev, Krzysztof Halasa

Hi.

We are searching for the desired channel three times in the same list.
So I think we could erase two of them. What do you think?

Signed-off-by: Miguel Ángel Álvarez (gotzoncabanes@gmail.com)
---
--- ixp4xx_hss.c.orig	2008-11-19 11:26:54.000000000 +0100
+++ ixp4xx_hss.c.create_chan	2008-11-26 18:34:23.000000000 +0100
@@ -2273,10 +2273,13 @@
 	}

 	for (ch = 0; ch < MAX_CHANNELS; ch++)
-		if (channels[ch] && port->channels[ch] != CHANNEL_UNUSED) {
-			printk(KERN_DEBUG "Channel #%i already in use\n", ch);
-			err = -EBUSY;
-			goto free;
+		if (channels[ch]) {
+		 	if (port->channels[ch] != CHANNEL_UNUSED) {
+				printk(KERN_DEBUG "Channel #%i already in use\n", ch);
+				err = -EBUSY;
+				goto free;
+			} else
+				break;
 		}

 	for (id = 0; id < MAX_CHAN_DEVICES; id++)
@@ -2288,10 +2291,6 @@
 		goto free;
 	}

-	for (ch = 0; ch < MAX_CHANNELS; ch++)
-		if (channels[ch])
-			break;
-
 	minor = port->id * MAX_CHAN_DEVICES + ch;
 	chan_dev->id = id;
 	chan_dev->port = port;
@@ -2307,9 +2306,7 @@
 	if ((err = cdev_add(&chan_dev->cdev, MKDEV(chan_major, minor), 1)))
 		goto destroy_device;

-	for (ch = 0; ch < MAX_CHANNELS; ch++)
-		if (channels[ch])
-			port->channels[ch] = id;
+	port->channels[ch] = id;
 	port->chan_devices[id] = chan_dev;
 	dev_set_drvdata(chan_dev->dev, chan_dev);
 	BUG_ON(device_create_file(chan_dev->dev, &chan_attr));

Thanks

Miguel Ángel Álvarez

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

* Re: ixp4xx_hss: Little improvement in create_chan function
  2008-11-26 17:38 ixp4xx_hss: Little improvement in create_chan function Miguel Ángel Álvarez
@ 2008-12-04 20:54 ` Krzysztof Halasa
  2008-12-05  8:32   ` Miguel Ángel Álvarez
  0 siblings, 1 reply; 3+ messages in thread
From: Krzysztof Halasa @ 2008-12-04 20:54 UTC (permalink / raw)
  To: Miguel Ángel Álvarez; +Cc: netdev

"Miguel Ángel Álvarez" <gotzoncabanes@gmail.com> writes:

> We are searching for the desired channel three times in the same list.
> So I think we could erase two of them. What do you think?
>
> +++ ixp4xx_hss.c.create_chan	2008-11-26 18:34:23.000000000 +0100
>
>  	for (ch = 0; ch < MAX_CHANNELS; ch++)
> -		if (channels[ch] && port->channels[ch] != CHANNEL_UNUSED) {
> -			printk(KERN_DEBUG "Channel #%i already in use\n", ch);
> -			err = -EBUSY;
> -			goto free;

Well, the above checks if _all_ needed port->channels[] are unused.

> +		if (channels[ch]) {
> +		 	if (port->channels[ch] != CHANNEL_UNUSED) {
> +				printk(KERN_DEBUG "Channel #%i already in use\n", ch);
> +				err = -EBUSY;
> +				goto free;
> +			} else
> +				break;

We can't break here because we have to check all the remaining
channels (which are in channels[]).

>  		}
>

> -	for (ch = 0; ch < MAX_CHANNELS; ch++)
> -		if (channels[ch])
> -			break;
> -

This simply seeks the first channel (to pick up number for the
device name).

> -	for (ch = 0; ch < MAX_CHANNELS; ch++)
> -		if (channels[ch])
> -			port->channels[ch] = id;

This sets the ID of all requested channels (i.e., it's some sort of
a bitmap).

> +	port->channels[ch] = id;
>  	port->chan_devices[id] = chan_dev;
>  	dev_set_drvdata(chan_dev->dev, chan_dev);
>  	BUG_ON(device_create_file(chan_dev->dev, &chan_attr));

We need to
a) first check if all needed channels are free, then
b) mark the above as used (with our ID), and
c) note the first requested ID for the device name.

"c" could be optimized (in terms of execution speed), perhaps. Since
it's a slow path (device setup), I didn't bother, I just tried to use
something simple and readable.
-- 
Krzysztof Halasa

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

* Re: ixp4xx_hss: Little improvement in create_chan function
  2008-12-04 20:54 ` Krzysztof Halasa
@ 2008-12-05  8:32   ` Miguel Ángel Álvarez
  0 siblings, 0 replies; 3+ messages in thread
From: Miguel Ángel Álvarez @ 2008-12-05  8:32 UTC (permalink / raw)
  To: Krzysztof Halasa; +Cc: netdev

Hi

You are absolutely right with create_chan function... I read it badly.

Miguel Ángel Álvarez

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

end of thread, other threads:[~2008-12-05  8:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-26 17:38 ixp4xx_hss: Little improvement in create_chan function Miguel Ángel Álvarez
2008-12-04 20:54 ` Krzysztof Halasa
2008-12-05  8:32   ` Miguel Ángel Álvarez

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox