tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Some changes to autoconfiguration APIs



> Date: Wed, 4 Aug 2021 17:52:46 -0700
> From: Jason Thorpe <thorpej%me.com@localhost>
> 
> > On Aug 1, 2021, at 11:10 AM, Martin Husemann <martin%duskware.de@localhost> wrote:
> > 
> > On Sun, Aug 01, 2021 at 07:57:20AM -0700, Jason Thorpe wrote:
> >> The situation hasn't changed.  I'm still waiting for concrete proposals.
> > 
> > The concrete proposal is backout - if there is no better idea how to deal
> > with it properly.
> 
> I have reworked it on the thorpej-cfargs2 branch.  It addresses the
> concerns about compile-time type checking by using an anonymous
> structure constructed in-line with the help of a variadic
> preprocessor macro (to save wear and tear on your fingers and
> keyboard that might otherwise occur because of annoying boilerplate
> syntax to construct the structure in-line).

Thanks, this looks much better!  No more objections from me.


For future work (definitely not a blocker for this or netbsd-10 or
anything) it would be nice if we could incorporate typed interface
attributes rather than just strings that are copied & pasted into the
source code and never checked until runtime.  For example, in
files.usb we could have something like

	define	usbdevif <struct usb_attach_args> { [port = -1], ... }

which would lead config(8) to generate

	static struct ifattachargs
	IA_USBDEVIF(struct usb_attach_args *args)
	{
		return (struct ifattachargs) {
			.iaa_name = "usbdevif",
			.iaa_args = args,
		};
	}

and in usb_subr.c the code would be

	dv = config_found(parent, IA_USBDEVIF(&uaa), ...);

with everything here verified by the compiler at compile-time.
Shouldn't be much effort to implement this -- just local changes in
config(8).  (I did something similar in picopb, e.g.
<https://mumble.net/~campbell/hg/picopb/test/disk/disk.pb.h-good> and
<https://mumble.net/~campbell/hg/picopb/test/disk/disk.c>.)

A stretch goal would be to push the types into the attach function
too, e.g.

	int
	uwhatever_attach(device_t parent, device_t self,
	    struct usb_attach_args *uaa)
	{
		...
	}

but that might take a bit more work.


Home | Main Index | Thread Index | Old Index