From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Stephen Chandler Paul <cpaul@redhat.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Mauro Carvalho Chehab <mchehab@osg.samsung.com>,
Greg KH <gregkh@linuxfoundation.org>,
Arnd Bergmann <arnd@arndb.de>, Joe Perches <joe@perches.com>,
Jiri Slaby <jslaby@suse.com>,
Vishnu Patekar <vishnupatekar0510@gmail.com>,
Sebastian Ott <sebott@linux.vnet.ibm.com>,
linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-input@vger.kernel.org, linux-api@vger.kernel.org,
Benjamin Tissoires <benjamin.tissoires@redhat.com>,
Hans de Goede <hdegoede@redhat.com>
Subject: Re: [RFC v3 1/1] Input: Add userio module
Date: Wed, 22 Jul 2015 14:39:59 -0700 [thread overview]
Message-ID: <20150722213959.GD14875@dtor-ws> (raw)
In-Reply-To: <1437594773-22274-2-git-send-email-cpaul@redhat.com>
Hi Stephen,
On Wed, Jul 22, 2015 at 03:52:53PM -0400, Stephen Chandler Paul wrote:
> +static int userio_char_open(struct inode *inode, struct file *file)
> +{
> + struct userio_device *userio;
> +
> + userio = devm_kzalloc(userio_misc.this_device,
> + sizeof(struct userio_device), GFP_KERNEL);
> + if (!userio)
> + return -ENOMEM;
Never ever use devm_ API outside of device probe() calls because
devm-managed resources only freed after failed probe() or after remove()
callback on driver model device and not any other device (block, char,
etc) in the system.
> +
> + spin_lock_init(&userio->head_lock);
> + mutex_init(&userio->tail_lock);
> + init_waitqueue_head(&userio->waitq);
> +
> + userio->serio = kzalloc(sizeof(struct serio), GFP_KERNEL);
> + if (!userio->serio) {
> + devm_kfree(userio_misc.this_device, userio);
And indeed here you have ot manually release the acquired resource. So
the only benefit you got form devm* is wasted resousrces.
> + return -ENOMEM;
> + }
> +
> + userio->serio->write = userio_device_write;
> + userio->serio->port_data = userio;
> +
> + file->private_data = userio;
> +
> + return 0;
> +}
> +
> +static int userio_char_release(struct inode *inode, struct file *file)
> +{
> + struct userio_device *userio = file->private_data;
> +
> + if (userio->serio) {
> + userio->serio->port_data = NULL;
No need to reset, it is going away.
> +
> + if (userio->running)
> + serio_unregister_port(userio->serio);
> + else
> + kfree(userio->serio);
> + }
> +
> + devm_kfree(userio_misc.this_device, userio);
> +
> + return 0;
> +}
> +
> +static ssize_t userio_char_read(struct file *file, char __user *buffer,
> + size_t count, loff_t *ppos)
> +{
> + struct userio_device *userio = file->private_data;
> + int ret;
> + size_t nonwrap_len, copylen;
> +
> + if (!count)
> + return 0;
> +
> + if (file->f_flags & O_NONBLOCK && userio->head == userio->tail)
> + return -EAGAIN;
> + else {
This is racy. If there was data and other thread "stole" it here then
your O_NONBLOCK will block. See evdev_read() how you supposed to handle
this.
Thanks.
--
Dmitry
prev parent reply other threads:[~2015-07-22 21:40 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-22 19:52 [RFC v3 0/1] userio (originally ps2emu) - virtual serio device module Stephen Chandler Paul
2015-07-22 19:52 ` [RFC v3 1/1] Input: Add userio module Stephen Chandler Paul
2015-07-22 20:16 ` Stephen Chandler Paul
2015-07-22 20:53 ` Benjamin Tissoires
2015-07-22 21:39 ` Dmitry Torokhov [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150722213959.GD14875@dtor-ws \
--to=dmitry.torokhov@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=arnd@arndb.de \
--cc=benjamin.tissoires@redhat.com \
--cc=cpaul@redhat.com \
--cc=gregkh@linuxfoundation.org \
--cc=hdegoede@redhat.com \
--cc=joe@perches.com \
--cc=jslaby@suse.com \
--cc=linux-api@vger.kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mchehab@osg.samsung.com \
--cc=sebott@linux.vnet.ibm.com \
--cc=vishnupatekar0510@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox