Re: [PATCH 1/1] LinuxPPS core support.

From: Christoph Hellwig
Date: Tue Feb 03 2009 - 04:15:11 EST


> +static long pps_cdev_ioctl(struct file *file,
> + unsigned int cmd, unsigned long arg)
> +{
> + struct pps_device *pps = file->private_data;
> + struct pps_kparams params;
> + struct pps_fdata fdata;
> + unsigned long ticks;
> + void __user *uarg = (void __user *) arg;
> + int __user *iuarg = (int __user *) arg;
> + int err;
> +
> + switch (cmd) {
> + case PPS_CHECK:
> +
> + /* This does nothing but signal we are a PPS source... */
> +
> + return 0;

I think this one is superflous. Just doing a PPS_GETPARAMS: should get
your the same information..

> + case PPS_GETPARAMS:
> + pr_debug("PPS_GETPARAMS: source %d\n", pps->id);
> +
> + /* Return current parameters */
> + err = copy_to_user(uarg, &pps->params,
> + sizeof(struct pps_kparams));
> + if (err)
> + return -EFAULT;
> +
> + break;
> +
> + case PPS_SETPARAMS:
> + pr_debug("PPS_SETPARAMS: source %d\n", pps->id);
> +
> + /* Check the capabilities */
> + if (!capable(CAP_SYS_TIME))
> + return -EPERM;
> +
> + err = copy_from_user(&params, uarg, sizeof(struct pps_kparams));
> + if (err)
> + return -EFAULT;
> + if (!(params.mode & (PPS_CAPTUREASSERT | PPS_CAPTURECLEAR))) {
> + pr_debug("capture mode unspecified (%x)\n",
> + params.mode);
> + return -EINVAL;
> + }

Note that splitting out any non-trivial ioctl into it's own small helper
function gives generally much cleaner code.

> + if (pps_devt)
> + unregister_chrdev_region(pps_devt, PPS_MAX_SOURCES);

Given that you have proper error handling in pps_init this can't
ever be zero.

> +
> + pr_info("LinuxPPS API ver. %d removed\n", PPS_API_VERS);

Printing stuff on exit is rather noisy and should be avoided

--
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/