Re: [PATCH 1/3] ioctl: generic ioctl dispatcher

From: Andi Kleen
Date: Mon Sep 29 2008 - 13:16:47 EST


Avi Kivity <avi@xxxxxxxxxx> 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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/