From: Oliver Neukum <oneukum@suse.de>
To: Kurachkin Michail <Michail.Kurachkin@promwad.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Kuten Ivan <Ivan.Kuten@promwad.com>,
"benavi@marvell.com" <benavi@marvell.com>,
Palstsiuk Viktar <Viktar.Palstsiuk@promwad.com>
Subject: Re: TDM bus support in Linux Kernel [PATCH]
Date: Wed, 30 Jan 2013 14:28:47 +0100 [thread overview]
Message-ID: <1803515.qlJg32fkH4@linux-5eaq.site> (raw)
In-Reply-To: <F7F628C32E67B04DAECC5CA53521253E5FAB15CE@sv-exmb01-lo1.promwad.corp>
On Wednesday 30 January 2013 12:37:25 Kurachkin Michail wrote:
> Hi Greg,
>
> I followed your recommendations and created a diff using Linux 3.8-rc5 sources. Please review it and give your comments.
Part #3
+/*
+ * method "open" for character device
+ */
+static int slic_chr_open(struct inode *inode, struct file *file)
+{
+ struct slic_chr_dev *chr_dev;
+ struct si3226x_slic *slic;
+ struct si3226x_line *line;
+ struct tdm_device *tdm_dev;
+ struct tdm_voice_channel *ch;
+ int status = -ENXIO;
+
+ mutex_lock(&slic_chr_dev_lock);
+
+ list_for_each_entry(chr_dev, &slic_chr_dev_list, list) {
+ switch (chr_dev->type) {
+ case SLIC_CHR_DEV:
+ slic = dev_get_drvdata(chr_dev->dev);
+
+ if (slic->devt != inode->i_rdev)
+ continue;;
+
+ if (slic->file_opened) {
+ status = -EBUSY;
+ goto out;
+ }
+
+ slic->file_opened = 1;
+ status = 0;
+ break;
+
+ case LINE_CHR_DEV:
+ line = dev_get_drvdata(chr_dev->dev);
+ tdm_dev = line->tdm_dev;
+
+ if (line->devt != inode->i_rdev)
+ continue;
+
+ if (line->file_opened) {
+ status = -EBUSY;
+ goto out;
+ }
+
+ line->audio_buffer_size = tdm_get_voice_block_size(tdm_dev);
+
+ line->rx_buffer = kzalloc(line->audio_buffer_size, GFP_KERNEL);
+ if (!line->rx_buffer) {
+ status = -ENOMEM;
+ goto out;
+ }
+
+ line->tx_buffer = kzalloc(line->audio_buffer_size, GFP_KERNEL);
+ if (!line->tx_buffer) {
+ status = -ENOMEM;
memory leak of line->rx_buffer
+ goto out;
+ }
+
+ /* store pointer to transmit wait_queue_head_t for use in poll() */
+ ch = tdm_dev->ch;
+ line->tx_wait_queue = &ch->tx_queue;
+ line->rx_wait_queue = &ch->rx_queue;
+ line->file_opened = 1;
+ status = 0;
+
+ break;
+ }
+
+ file->private_data = chr_dev;
+ status = 0;
+ goto out;
a bit pointless
+ }
+
+out:
+ mutex_unlock(&slic_chr_dev_lock);
+ return status;
+}
+/*
+ * method "ioctl" for character device
+ */
+static long
+slic_chr_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
+{
+ struct slic_chr_dev *chr_dev = file->private_data;
+ struct si3226x_slic *slic;
+ struct si3226x_line *line;
+ int status = -ENXIO;
+
+ if (_IOC_TYPE(cmd) != SI3226X_IOC_MAGIC)
+ return -ENOTTY;
+
+ mutex_lock(&slic_chr_dev_lock);
+
+ if (!file->private_data) {
+ status = -EPERM;
-EPERM?
+ goto out;
+ }
+
+ switch(chr_dev->type) {
+ case SLIC_CHR_DEV:
+ slic = dev_get_drvdata(chr_dev->dev);
+ if (!slic->file_opened) {
+ status = -ENODEV;
+ goto out;
+ }
+
+ status = slic_control(slic, cmd, arg);
+ break;
+
+ case LINE_CHR_DEV:
+ line = dev_get_drvdata(chr_dev->dev);
+ if (!line->file_opened) {
+ status = -ENODEV;
+ goto out;
+ }
+
+ status = line_control(line, cmd, arg);
+ break;
+ }
+
+out:
+ mutex_unlock(&slic_chr_dev_lock);
+ return status;
+}
+/*
+ * method "read" for character device
+ */
+static ssize_t
+slic_chr_read(struct file *file, char *buff, size_t count, loff_t *offp)
+{
+ struct slic_chr_dev *chr_dev = file->private_data;
+ struct si3226x_line *line;
+ struct tdm_device *tdm_dev;
+ int rc;
+
+ if (!file->private_data)
+ return -EPERM;
+
+ if(chr_dev->type != LINE_CHR_DEV)
+ return -EPERM;
+
+ mutex_lock(&slic_chr_dev_lock);
+
+ line = dev_get_drvdata(chr_dev->dev);
+ tdm_dev = line->tdm_dev;
+
+ if (count != line->audio_buffer_size) {
+ rc = -ENODATA;
+ goto out;
+ }
+
+ rc = tdm_recv(tdm_dev, line->rx_buffer);
+ if (rc) {
+ rc = -EFAULT;
EFAULT is usually not what you return upon a read error.
+ goto out;
+ }
+
+ rc = copy_to_user(buff, line->rx_buffer, count);
+ if (rc) {
+ rc = -EFAULT;
+ goto out;
+ }
+
+ rc = count;
+out:
+ mutex_unlock(&slic_chr_dev_lock);
+ return rc;
+}
next prev parent reply other threads:[~2013-01-30 13:28 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-30 12:37 TDM bus support in Linux Kernel [PATCH] Kurachkin Michail
2013-01-30 12:59 ` Oliver Neukum
2013-02-04 13:08 ` Re[2]: " Michail Kurachkin
2013-02-05 15:34 ` Oliver Neukum
2013-02-13 17:08 ` Re[2]: " Michail Kurachkin
2013-02-14 12:46 ` Ivan Kuten
2013-01-30 13:03 ` Oliver Neukum
2013-01-30 13:28 ` Oliver Neukum [this message]
2013-01-30 13:35 ` Oliver Neukum
2013-01-30 13:43 ` Oliver Neukum
2013-01-30 15:57 ` Greg Kroah-Hartman
[not found] ` <511044C9.9090809@gmail.com>
2013-02-04 23:49 ` Greg Kroah-Hartman
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=1803515.qlJg32fkH4@linux-5eaq.site \
--to=oneukum@suse.de \
--cc=Ivan.Kuten@promwad.com \
--cc=Michail.Kurachkin@promwad.com \
--cc=Viktar.Palstsiuk@promwad.com \
--cc=benavi@marvell.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.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