Re: ixp4xx_hss: Little improvement in create_chan function
From: Krzysztof Halasa <khc@pm.waw.pl>
Date: 2008-12-04 20:54:03
"Miguel Ángel Álvarez" [off-list ref] writes:
quoted hunk ↗ jump to hunk
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