public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Krzysztof Halasa <khc@pm.waw.pl>
To: "Miguel Ángel Álvarez" <gotzoncabanes@gmail.com>
Cc: netdev@vger.kernel.org
Subject: Re: ixp4xx_hss: Little improvement in create_chan function
Date: Thu, 04 Dec 2008 21:54:00 +0100	[thread overview]
Message-ID: <m34p1jzmon.fsf@maximus.localdomain> (raw)
In-Reply-To: <b0438a630811260938n14835453jda2da43c6f1445f9@mail.gmail.com> ("Miguel Ángel Álvarez"'s message of "Wed\, 26 Nov 2008 18\:38\:10 +0100")

"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

  reply	other threads:[~2008-12-04 20:54 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-26 17:38 ixp4xx_hss: Little improvement in create_chan function Miguel Ángel Álvarez
2008-12-04 20:54 ` Krzysztof Halasa [this message]
2008-12-05  8:32   ` Miguel Ángel Álvarez

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=m34p1jzmon.fsf@maximus.localdomain \
    --to=khc@pm.waw.pl \
    --cc=gotzoncabanes@gmail.com \
    --cc=netdev@vger.kernel.org \
    /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