lkml.org 
[lkml]   [2015]   [Jul]   [21]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [RFC] Input: Add ps2emu module
On Tue, Jul 21, 2015 at 03:07:14PM -0400, Stephen Chandler Paul wrote:
> +#define ps2emu_warn(format, args...) \
> + dev_warn(ps2emu_misc.this_device, format, ## args)

Don't make a wrapper function for another wrapper function, just spell
the thing out in the code, makes it much easier to debug and maintain
over time.

It will also cause you to rename "this_device" to "dev" to make it
easier to type :)

> +static int ps2emu_char_open(struct inode *inode, struct file *file)
> +{
> + struct ps2emu_device *ps2emu = NULL;
> +
> + ps2emu = kzalloc(sizeof(struct ps2emu_device), GFP_KERNEL);
> + if (!ps2emu)
> + return -ENOMEM;
> +
> + init_waitqueue_head(&ps2emu->waitq);
> +
> + ps2emu->serio.write = ps2emu_device_write;
> + ps2emu->serio.port_data = ps2emu;
> +
> + file->private_data = ps2emu;
> +
> + nonseekable_open(inode, file);

Why call this at all?

> + ret = copy_to_user(buffer, &ps2emu->buf[ps2emu->tail], copylen);
> + if (ret)
> + return ret;

Wrong error value, please return -EFAULT.

> + rc = copy_from_user(&cmd, buffer, sizeof(cmd));
> + if (rc)
> + return rc;

Same thing here, -EFAULT.

> + case PS2EMU_CMD_SEND_INTERRUPT:
> + if (unlikely(!ps2emu->running)) {

Unless you can verify likely/unlikely actually makes a difference in
your code, don't ever use it. Hint, it's not needed here.

thanks,

greg k-h


\
 
 \ /
  Last update: 2015-07-21 21:41    [W:0.052 / U:0.060 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site