[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <m34p1jzmon.fsf@maximus.localdomain>
Date: Thu, 04 Dec 2008 21:54:00 +0100
From: Krzysztof Halasa <khc@...waw.pl>
To: Miguel Ángel Álvarez <gotzoncabanes@...il.com>
Cc: netdev@...r.kernel.org
Subject: Re: ixp4xx_hss: Little improvement in create_chan function
"Miguel Ángel Álvarez" <gotzoncabanes@...il.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
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Powered by blists - more mailing lists