Subject: Re: device tree traversal, round 2
To: Matt Thomas <matt@3am-software.com>
From: Jachym Holecek <freza@dspfpga.com>
List: tech-kern
Date: 07/21/2006 15:12:51
# Matt Thomas 2006-07-21:
> On Jul 21, 2006, at 5:15 AM, Jachym Holecek wrote:
> >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.

That's just an example. The idea is that (for various use cases listed
in original posting) you want to iterate subtree given by arbitrary
device_t -- consider "want to detach foo0 and everything below it"
operation for instance.

	-- Jachym