From: Oliver Neukum <oliver-GvhC2dPhHPQdnm+yROfE0A@public.gmane.org>
To: Sebastian Reichel <sre-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Cc: Peter Ujfalusi <peter.ujfalusi-l0cyMroinI0@public.gmane.org>,
Kai Vehmanen <kvcontact-nQfqiRJ1PMYxHbG02/KK1g@public.gmane.org>,
Pavel Machek <pavel-+ZI9xUNit7I@public.gmane.org>,
Pali Rohar <pali.rohar-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
Aaro Koskinen <aaro.koskinen-X3B1VOXEql0@public.gmane.org>,
Ivaylo Dimitrov
<ivo.g.dimitrov.75-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
linux-omap-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
Kai Vehmanen
<kai.vehmanen-xNZwKgViW5gAvxtiuMwx3w@public.gmane.org>,
Carlos Chinea
<carlos.chinea-xNZwKgViW5gAvxtiuMwx3w@public.gmane.org>,
Joni Lapilainen
<joni.lapilainen-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Subject: Re: [PATCH 1/9] HSI: cmt_speech: Add cmt-speech driver
Date: Mon, 02 Mar 2015 11:22:33 +0100 [thread overview]
Message-ID: <1425291753.2014.5.camel@neukum.org> (raw)
In-Reply-To: <1425271139-24715-2-git-send-email-sre-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
> +static ssize_t cs_char_read(struct file *file, char __user *buf, size_t count,
> + loff_t *unused)
> +{
> + struct cs_char *csdata = file->private_data;
> + u32 data;
> + ssize_t retval;
> +
> + if (count < sizeof(data))
> + return -EINVAL;
> +
> + for ( ; ; ) {
> + DEFINE_WAIT(wait);
> +
> + spin_lock_bh(&csdata->lock);
> + if (!list_empty(&csdata->chardev_queue)) {
> + data = cs_pop_entry(&csdata->chardev_queue);
> + } else if (!list_empty(&csdata->dataind_queue)) {
> + data = cs_pop_entry(&csdata->dataind_queue);
> + --csdata->dataind_pending;
> +
> + } else {
> + data = 0;
> + }
> + spin_unlock_bh(&csdata->lock);
> +
> + if (data)
> + break;
> + if (file->f_flags & O_NONBLOCK) {
> + retval = -EAGAIN;
> + goto out;
> + } else if (signal_pending(current)) {
> + retval = -ERESTARTSYS;
> + goto out;
> + }
> + prepare_to_wait_exclusive(&csdata->wait, &wait,
> + TASK_INTERRUPTIBLE);
> + schedule();
> + finish_wait(&csdata->wait, &wait);
> + }
> +
> + retval = put_user(data, (u32 __user *)buf);
> + if (!retval)
> + retval = sizeof(data);
> +
> +out:
> + return retval;
> +}
> +
> +static ssize_t cs_char_write(struct file *file, const char __user *buf,
> + size_t count, loff_t *unused)
> +{
> + struct cs_char *csdata = file->private_data;
> + u32 data;
> + int err;
> + ssize_t retval;
> +
> + if (count < sizeof(data))
> + return -EINVAL;
> +
> + if (get_user(data, (u32 __user *)buf))
> + retval = -EFAULT;
> + else
> + retval = count;
You want to execute the command even if you got -EFAULT?
That is highly unusual.
> +
> + err = cs_hsi_command(csdata->hi, data);
> + if (err < 0)
> + retval = err;
> +
> + return retval;
> +}
> +
> +static long cs_char_ioctl(struct file *file, unsigned int cmd,
> + unsigned long arg)
> +{
> + struct cs_char *csdata = file->private_data;
> + int r = 0;
> +
> + switch (cmd) {
> + case CS_GET_STATE: {
> + unsigned int state;
> +
> + state = cs_hsi_get_state(csdata->hi);
> + if (copy_to_user((void __user *)arg, &state, sizeof(state)))
> + r = -EFAULT;
> + }
> + break;
> + case CS_SET_WAKELINE: {
> + unsigned int state;
> +
> + if (copy_from_user(&state, (void __user *)arg, sizeof(state)))
> + r = -EFAULT;
> + else
> + cs_hsi_set_wakeline(csdata->hi, state);
No sanity checking for state?
> + }
> + break;
> + case CS_GET_IF_VERSION: {
> + unsigned int ifver = CS_IF_VERSION;
> +
> + if (copy_to_user((void __user *)arg, &ifver, sizeof(ifver)))
> + r = -EFAULT;
> + break;
> + }
> + case CS_CONFIG_BUFS: {
> + struct cs_buffer_config buf_cfg;
> +
> + if (copy_from_user(&buf_cfg, (void __user *)arg,
> + sizeof(buf_cfg)))
> + r = -EFAULT;
> + else
> + r = cs_hsi_buf_config(csdata->hi, &buf_cfg);
Sanity checking?
> + break;
> + }
> + default:
> + r = -ENOTTY;
> + break;
> + }
> +
> + return r;
> +}
> +
> +static int cs_char_mmap(struct file *file, struct vm_area_struct *vma)
> +{
> + if (vma->vm_end < vma->vm_start)
> + return -EINVAL;
> +
> + if (((vma->vm_end - vma->vm_start) >> PAGE_SHIFT) != 1)
> + return -EINVAL;
> +
> + vma->vm_flags |= VM_RESERVED;
> + vma->vm_ops = &cs_char_vm_ops;
> + vma->vm_private_data = file->private_data;
> +
> + return 0;
> +}
> +
> +static int cs_char_open(struct inode *unused, struct file *file)
> +{
> + int ret = 0;
> +
> + spin_lock_bh(&cs_char_data.lock);
> + if (cs_char_data.opened) {
> + ret = -EBUSY;
> + spin_unlock_bh(&cs_char_data.lock);
> + goto out;
> + }
> + cs_char_data.mmap_base = get_zeroed_page(GFP_ATOMIC);
This could be moved outside the locked sectionand use GFP_KERNEL.
> + if (!cs_char_data.mmap_base) {
> + dev_err(&cs_char_data.cl->device,
> + "Shared memory allocation failed.\n");
> + ret = -ENOMEM;
> + spin_unlock_bh(&cs_char_data.lock);
> + goto out;
> + }
> + cs_char_data.mmap_size = CS_MMAP_SIZE;
> + cs_char_data.dataind_pending = 0;
> + cs_char_data.opened = 1;
> + file->private_data = &cs_char_data;
> + spin_unlock_bh(&cs_char_data.lock);
> +
> + BUG_ON(cs_char_data.hi);
> +
> + ret = cs_hsi_start(&cs_char_data.hi, cs_char_data.cl,
> + cs_char_data.mmap_base, cs_char_data.mmap_size);
> + if (ret) {
> + dev_err(&cs_char_data.cl->device, "Unable to initialize HSI\n");
> + free_page(cs_char_data.mmap_base);
> + goto out;
> + }
> +
> +out:
> + return ret;
> +}
next prev parent reply other threads:[~2015-03-02 10:22 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-02 4:38 [PATCH 0/9] N900 Modem Speech Support Sebastian Reichel
2015-03-02 4:38 ` [PATCH 1/9] HSI: cmt_speech: Add cmt-speech driver Sebastian Reichel
[not found] ` <1425271139-24715-2-git-send-email-sre-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2015-03-02 10:22 ` Oliver Neukum [this message]
2015-03-02 15:26 ` Sebastian Reichel
2015-03-02 10:29 ` Oliver Neukum
2015-03-02 20:56 ` Aaro Koskinen
2015-03-02 4:38 ` [PATCH 2/9] HSI: cmt_speech: Avoid GFP_ATOMIC in cs_char_open Sebastian Reichel
2015-03-02 4:38 ` [PATCH 3/9] HSI: cmt_speech: Return error if HSI port not configured Sebastian Reichel
2015-03-02 4:38 ` [PATCH 4/9] HSI: cmt_speech: Fix build for 4.0 kernel Sebastian Reichel
2015-03-02 4:38 ` [PATCH 5/9] HSI: cmt_speech: Cleanup initialisation Sebastian Reichel
2015-03-02 4:38 ` [PATCH 6/9] HSI: cmt_speech: Rename driver to cmt-speech Sebastian Reichel
2015-03-02 4:38 ` [PATCH 7/9] HSI: cmt_speech: Move cs-protocol.h to include/uapi/linux/hsi Sebastian Reichel
2015-03-02 4:38 ` [PATCH 8/9] HSI: cmt_speech: Remove hardcoded channel numbers Sebastian Reichel
2015-03-02 4:38 ` [PATCH 9/9] HSI: nokia-modem: Add cmt_speech support Sebastian Reichel
2015-03-02 19:05 ` [PATCH 0/9] N900 Modem Speech Support Pali Rohár
2015-03-02 20:51 ` Sebastian Reichel
2015-03-03 17:46 ` Pali Rohár
2015-03-03 13:33 ` Pavel Machek
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=1425291753.2014.5.camel@neukum.org \
--to=oliver-gvhc2dphhpqdnm+yrofe0a@public.gmane.org \
--cc=aaro.koskinen-X3B1VOXEql0@public.gmane.org \
--cc=carlos.chinea-xNZwKgViW5gAvxtiuMwx3w@public.gmane.org \
--cc=ivo.g.dimitrov.75-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=joni.lapilainen-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=kai.vehmanen-xNZwKgViW5gAvxtiuMwx3w@public.gmane.org \
--cc=kvcontact-nQfqiRJ1PMYxHbG02/KK1g@public.gmane.org \
--cc=linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-omap-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=pali.rohar-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=pavel-+ZI9xUNit7I@public.gmane.org \
--cc=peter.ujfalusi-l0cyMroinI0@public.gmane.org \
--cc=sre-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
/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;
as well as URLs for NNTP newsgroup(s).