From: Sebastian Reichel <sre@kernel.org>
To: Oliver Neukum <oliver@neukum.org>
Cc: Peter Ujfalusi <peter.ujfalusi@ti.com>,
Kai Vehmanen <kvcontact@nosignal.fi>, Pavel Machek <pavel@ucw.cz>,
Pali Rohar <pali.rohar@gmail.com>,
Aaro Koskinen <aaro.koskinen@iki.fi>,
Ivaylo Dimitrov <ivo.g.dimitrov.75@gmail.com>,
linux-omap@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-api@vger.kernel.org,
Joni Lapilainen <joni.lapilainen@gmail.com>
Subject: Re: [PATCH 1/9] HSI: cmt_speech: Add cmt-speech driver
Date: Mon, 2 Mar 2015 16:26:53 +0100 [thread overview]
Message-ID: <20150302152652.GB2834@earth> (raw)
In-Reply-To: <1425291753.2014.5.camel@neukum.org>
[-- Attachment #1: Type: text/plain, Size: 5284 bytes --]
Hi Oliver,
On Mon, Mar 02, 2015 at 11:22:33AM +0100, Oliver Neukum wrote:
> > +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.
I will change this in PATCHv2.
> > +
> > + 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?
Will be added in PATCHv2, so that -EINVAL is returned for values > 1.
> > + }
> > + 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?
cs_hsi_buf_config() calls check_buf_params().
> > + 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.
Right, this is fixed by a follow up patch. I kept the patchset split
to keep authorship information. I guess I can squash the first three
patches, though.
> > + 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;
> > +}
-- Sebastian
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
next prev parent reply other threads:[~2015-03-02 15:26 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
2015-03-02 15:26 ` Sebastian Reichel [this message]
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=20150302152652.GB2834@earth \
--to=sre@kernel.org \
--cc=aaro.koskinen@iki.fi \
--cc=ivo.g.dimitrov.75@gmail.com \
--cc=joni.lapilainen@gmail.com \
--cc=kvcontact@nosignal.fi \
--cc=linux-api@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-omap@vger.kernel.org \
--cc=oliver@neukum.org \
--cc=pali.rohar@gmail.com \
--cc=pavel@ucw.cz \
--cc=peter.ujfalusi@ti.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;
as well as URLs for NNTP newsgroup(s).