Re: [BK PATCH] SCSI host num allocation improvement

Andrew Morton
2004-02-27T01:19:59Z

Ben Collins <bcollins@debian.org> wrote:
>
> +next_host_num_try:
> + list_for_each_entry(cdev, &class->children, node) {
> + shost = class_to_shost(cdev);
> + if (shost->host_no == host_num) {
> + host_num++;
> + goto next_host_num_try;

yitch. I realise this is called rarely, for realtively small numbers of N
(which gets squared), but.

This allocate-me-the-lowest-available-number is a common idiom in the
kernel and we really should do it better. Seems we need to convert the
dynamic pty allocation to do it as well - it has yet another open-coded
ad-hoc allocator.

The lib/idr.c code is a bit clumsy but it does do the job relatively
efficiently. If it needs some helper wrappers or API simplification then
let's add those.