Messages in this thread | | | Subject | Re: [PATCH 1/3] ioctl: generic ioctl dispatcher | From | Andi Kleen <> | Date | Mon, 29 Sep 2008 19:16:35 +0200 |
| |
Avi Kivity <avi@redhat.com> writes:
> +/** > + * dispatch_ioctl - dispatch to an ioctl handler based on ioctl number > + * @inode: inode to invoke ioctl method on > + * @filp: open file to invoke ioctl method on > + * @cmd: ioctl command to execute > + * @arg: command-specific argument for ioctl > + * @handlers: list of potential handlers for @cmd; null terminated; > + * place frequently used cmds first > + * @fallback: optional function to call if @cmd not found in @handlers > + * > + * Locates and calls ioctl handler in @handlers; if none exist, calls > + * @fallback; if that does not exist, return -ENOTTY. > + */ > +long dispatch_ioctl(struct inode *inode, struct file *filp, > + unsigned cmd, unsigned long arg, > + const struct ioctl_handler *handlers, > + long (*fallback)(const struct ioctl_arg *arg))
The basic idea is good, but i don't like the proliferation of callbacks, which tends to make complicated code and is ugly for simple code (which a lot of ioctls are)
How about you make it return an number that can index a switch() instead? Then everything could be still kept in the same function.
-Andi
| |