From: "istvan_v@mailbox.hu" <istvan_v@mailbox.hu>
To: linux-media@vger.kernel.org
Subject: XC4000: added mutex
Date: Fri, 03 Jun 2011 17:23:33 +0200 [thread overview]
Message-ID: <4DE8FC75.8060008@mailbox.hu> (raw)
In-Reply-To: <BANLkTimEEGsMP6PDXf5W5p9wW7wdWEEOiA@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 174 bytes --]
This patch adds a mutex to xc4000_priv, to protect the driver
from being accessed by multiple processes at the same time.
Signed-off-by: Istvan Varga <istvan_v@mailbox.hu>
[-- Attachment #2: xc4000_mutex.patch --]
[-- Type: text/x-patch, Size: 5400 bytes --]
diff -uNr xc4000_orig/drivers/media/common/tuners/xc4000.c xc4000/drivers/media/common/tuners/xc4000.c
--- xc4000_orig/drivers/media/common/tuners/xc4000.c 2011-06-03 16:35:23.000000000 +0200
+++ xc4000/drivers/media/common/tuners/xc4000.c 2011-06-03 17:02:59.000000000 +0200
@@ -28,6 +28,7 @@
#include <linux/delay.h>
#include <linux/dvb/frontend.h>
#include <linux/i2c.h>
+#include <linux/mutex.h>
#include <asm/unaligned.h>
#include "dvb_frontend.h"
@@ -91,6 +92,7 @@
struct firmware_properties cur_fw;
__u16 hwmodel;
__u16 hwvers;
+ struct mutex lock;
};
/* Misc Defines */
@@ -1144,10 +1146,12 @@
{
struct xc4000_priv *priv = fe->tuner_priv;
unsigned int type;
- int ret;
+ int ret = -EREMOTEIO;
dprintk(1, "%s() frequency=%d (Hz)\n", __func__, params->frequency);
+ mutex_lock(&priv->lock);
+
if (fe->ops.info.type == FE_ATSC) {
dprintk(1, "%s() ATSC\n", __func__);
switch (params->u.vsb.modulation) {
@@ -1171,7 +1175,8 @@
type = DTV6;
break;
default:
- return -EINVAL;
+ ret = -EINVAL;
+ goto fail;
}
} else if (fe->ops.info.type == FE_OFDM) {
dprintk(1, "%s() OFDM\n", __func__);
@@ -1207,28 +1212,29 @@
break;
default:
printk(KERN_ERR "xc4000 bandwidth not set!\n");
- return -EINVAL;
+ ret = -EINVAL;
+ goto fail;
}
priv->rf_mode = XC_RF_MODE_AIR;
} else {
printk(KERN_ERR "xc4000 modulation type not supported!\n");
- return -EINVAL;
+ ret = -EINVAL;
+ goto fail;
}
dprintk(1, "%s() frequency=%d (compensated)\n",
__func__, priv->freq_hz);
/* Make sure the correct firmware type is loaded */
- if (check_firmware(fe, type, 0, priv->if_khz) != XC_RESULT_SUCCESS) {
- return -EREMOTEIO;
- }
+ if (check_firmware(fe, type, 0, priv->if_khz) != XC_RESULT_SUCCESS)
+ goto fail;
ret = xc_SetSignalSource(priv, priv->rf_mode);
if (ret != XC_RESULT_SUCCESS) {
printk(KERN_ERR
- "xc4000: xc_SetSignalSource(%d) failed\n",
- priv->rf_mode);
- return -EREMOTEIO;
+ "xc4000: xc_SetSignalSource(%d) failed\n",
+ priv->rf_mode);
+ goto fail;
}
ret = xc_SetTVStandard(priv,
@@ -1236,33 +1242,32 @@
XC4000_Standard[priv->video_standard].AudioMode);
if (ret != XC_RESULT_SUCCESS) {
printk(KERN_ERR "xc4000: xc_SetTVStandard failed\n");
- return -EREMOTEIO;
- }
-#ifdef DJH_DEBUG
- ret = xc_set_IF_frequency(priv, priv->if_khz);
- if (ret != XC_RESULT_SUCCESS) {
- printk(KERN_ERR "xc4000: xc_Set_IF_frequency(%d) failed\n",
- priv->if_khz);
- return -EIO;
+ goto fail;
}
-#endif
xc_tune_channel(priv, priv->freq_hz, XC_TUNE_DIGITAL);
if (debug)
xc_debug_dump(priv);
- return 0;
+ ret = 0;
+
+fail:
+ mutex_unlock(&priv->lock);
+
+ return ret;
}
static int xc4000_set_analog_params(struct dvb_frontend *fe,
struct analog_parameters *params)
{
struct xc4000_priv *priv = fe->tuner_priv;
- int ret;
+ int ret = -EREMOTEIO;
dprintk(1, "%s() frequency=%d (in units of 62.5khz)\n",
__func__, params->frequency);
+ mutex_lock(&priv->lock);
+
/* Fix me: it could be air. */
priv->rf_mode = params->mode;
if (params->mode > XC_RF_MODE_CABLE)
@@ -1317,16 +1322,15 @@
tune_channel:
/* FIXME - firmware type not being set properly */
- if (check_firmware(fe, DTV8, 0, priv->if_khz) != XC_RESULT_SUCCESS) {
- return -EREMOTEIO;
- }
+ if (check_firmware(fe, DTV8, 0, priv->if_khz) != XC_RESULT_SUCCESS)
+ goto fail;
ret = xc_SetSignalSource(priv, priv->rf_mode);
if (ret != XC_RESULT_SUCCESS) {
printk(KERN_ERR
- "xc4000: xc_SetSignalSource(%d) failed\n",
- priv->rf_mode);
- return -EREMOTEIO;
+ "xc4000: xc_SetSignalSource(%d) failed\n",
+ priv->rf_mode);
+ goto fail;
}
ret = xc_SetTVStandard(priv,
@@ -1334,7 +1338,7 @@
XC4000_Standard[priv->video_standard].AudioMode);
if (ret != XC_RESULT_SUCCESS) {
printk(KERN_ERR "xc4000: xc_SetTVStandard failed\n");
- return -EREMOTEIO;
+ goto fail;
}
xc_tune_channel(priv, priv->freq_hz, XC_TUNE_ANALOG);
@@ -1342,7 +1346,12 @@
if (debug)
xc_debug_dump(priv);
- return 0;
+ ret = 0;
+
+fail:
+ mutex_unlock(&priv->lock);
+
+ return ret;
}
static int xc4000_get_frequency(struct dvb_frontend *fe, u32 *freq)
@@ -1367,8 +1376,12 @@
struct xc4000_priv *priv = fe->tuner_priv;
u16 lock_status = 0;
+ mutex_lock(&priv->lock);
+
xc_get_lock_status(priv, &lock_status);
+ mutex_unlock(&priv->lock);
+
dprintk(1, "%s() lock_status = 0x%08x\n", __func__, lock_status);
*status = lock_status;
@@ -1385,9 +1398,13 @@
static int xc4000_init(struct dvb_frontend *fe)
{
struct xc4000_priv *priv = fe->tuner_priv;
+ int ret;
dprintk(1, "%s()\n", __func__);
- if (check_firmware(fe, DTV8, 0, priv->if_khz) != XC_RESULT_SUCCESS) {
+ mutex_lock(&priv->lock);
+ ret = check_firmware(fe, DTV8, 0, priv->if_khz);
+ mutex_unlock(&priv->lock);
+ if (ret != XC_RESULT_SUCCESS) {
printk(KERN_ERR "xc4000: Unable to initialise tuner\n");
return -EREMOTEIO;
}
@@ -1471,6 +1488,7 @@
case 1:
/* new tuner instance */
priv->bandwidth = BANDWIDTH_6_MHZ;
+ mutex_init(&priv->lock);
fe->tuner_priv = priv;
break;
default:
@@ -1522,7 +1540,9 @@
/* FIXME: For now, load the firmware at startup. We will remove this
before the code goes to production... */
+ mutex_lock(&priv->lock);
check_firmware(fe, DTV8, 0, priv->if_khz);
+ mutex_unlock(&priv->lock);
return fe;
fail:
next prev parent reply other threads:[~2011-06-03 15:23 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-08 14:54 [linux-dvb] XC4000 patches for kernel 2.6.37.2 Mirek Slugeň
2011-05-31 2:48 ` Dmitri Belimov
2011-05-31 3:49 ` Devin Heitmueller
2011-05-31 7:43 ` Dmitri Belimov
2011-06-02 10:52 ` Devin Heitmueller
2011-06-02 14:41 ` Mauro Carvalho Chehab
2011-06-02 15:17 ` Devin Heitmueller
2011-06-02 16:35 ` Mauro Carvalho Chehab
2011-06-03 1:41 ` Dmitri Belimov
2011-06-03 12:12 ` Mauro Carvalho Chehab
2011-06-02 15:53 ` Mohammad Bahathir Hashim
2011-06-02 17:05 ` Mauro Carvalho Chehab
2011-06-03 3:54 ` Mohammad Bahathir Hashim
[not found] ` <4DE8D5AC.7060002@mailbox.hu>
2011-06-03 12:46 ` [linux-dvb] XC4000: added card_type Devin Heitmueller
[not found] ` <4DE8DEC6.6080008@mailbox.hu>
2011-06-03 14:00 ` Mauro Carvalho Chehab
2011-06-03 14:22 ` istvan_v
2011-06-03 13:17 ` Mauro Carvalho Chehab
2011-06-03 13:55 ` XC4000: updated standards table istvan_v
2011-06-03 15:17 ` XC4000: added support for 7 MHz DVB-T istvan_v
2011-06-03 15:23 ` istvan_v [this message]
2011-06-03 15:27 ` XC4000: fixed frequency error istvan_v
2011-06-04 14:48 ` XC4000: added firmware_name parameter istvan_v
2011-06-04 14:52 ` XC4000: simplified seek_firmware() istvan_v
2011-06-04 14:56 ` XC4000: simplified load_scode istvan_v
2011-06-04 14:59 ` XC4000: check_firmware() cleanup istvan_v
2011-06-04 15:03 ` XC4000: implemented power management istvan_v
2011-06-04 15:04 ` XC4000: firmware initialization istvan_v
2011-06-04 15:08 ` XC4000: debug message improvements istvan_v
2011-06-04 15:12 ` XC4000: setting registers istvan_v
2011-06-05 12:05 ` Mauro Carvalho Chehab
2011-06-05 12:28 ` Istvan Varga
2011-06-05 12:56 ` Mauro Carvalho Chehab
2011-06-05 14:30 ` Istvan Varga
2011-06-04 15:15 ` XC4000: added audio_std module parameter istvan_v
2011-06-04 15:17 ` XC4000: implemented analog TV and radio istvan_v
2011-06-04 15:18 ` XC4000: xc_tune_channel() cleanup istvan_v
2011-06-04 15:21 ` XC4000: removed redundant tuner reset istvan_v
2011-06-04 15:25 ` XC4000: detect XC4100 istvan_v
2011-06-02 4:58 ` [linux-dvb] XC4000 patches for kernel 2.6.37.2 Mohammad Bahathir Hashim
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=4DE8FC75.8060008@mailbox.hu \
--to=istvan_v@mailbox.hu \
--cc=linux-media@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.