Subject: Re: device tree traversal, round 2
To: Jachym Holecek <freza@dspfpga.com>
From: Matt Thomas <matt@3am-software.com>
List: tech-kern
Date: 07/21/2006 06:06:56
On Jul 21, 2006, at 5:15 AM, Jachym Holecek wrote:
> Hello,
>
> I made some changes to the device tree traversal API [*]:
>
> * Change names as per chap's comment (s/DIF_TOPDOWN/DIF_PREORDER,
> s/DIF_DOWNTOP/DIF_POSTORDER).
> * Remove traversal stack depth limit from device_iterator_alloc().
> * Make it possible to reuse one iterator object for either traversal
> direction.
> * Fix allocation bug (thanks Magnus Larsson).
>
> New usage example:
>
> deviter_t di;
> device_t dv;
>
> di = device_iterator_alloc();
> if (di == NULL)
> panic("borked");
>
> device_iterator_init(di, TAILQ_FIRST(&alldevs),
> DIF_PREORDER | DIF_WAITOK);
>
> while ((dv = device_iterator_foreach(di)) != NULL)
> printf("FOO %s\n", device_xname(dv));
>
> device_iterator_init(di, TAILQ_FIRST(&alldevs),
> DIF_POSTORDER | DIF_WAITOK);
>
> while ((dv = device_iterator_foreach(di)) != NULL)
> printf("BAR %s\n", device_xname(dv));
>
> device_iterator_free(di);
Why do you need to pass TAILQ_FIRST(&alldevs)? Why wouldn't that be
used every time? I think removing that argument would be cleaner.