V4L/DVB (13547): radio: add trivial checks on the tuner and type args.

Many radio drivers did not check the tuner and type field correctly
for g/s_frequency. These checks have now been added.

Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
This commit is contained in:
Hans Verkuil 2009-11-27 04:33:25 -03:00 committed by Mauro Carvalho Chehab
parent cda4303f55
commit a3a9e287da
14 changed files with 55 additions and 1 deletions

View file

@ -268,6 +268,8 @@ static int vidioc_s_frequency(struct file *file, void *priv,
{ {
struct rtrack *rt = video_drvdata(file); struct rtrack *rt = video_drvdata(file);
if (f->tuner != 0 || f->type != V4L2_TUNER_RADIO)
return -EINVAL;
rt_setfreq(rt, f->frequency); rt_setfreq(rt, f->frequency);
return 0; return 0;
} }
@ -277,6 +279,8 @@ static int vidioc_g_frequency(struct file *file, void *priv,
{ {
struct rtrack *rt = video_drvdata(file); struct rtrack *rt = video_drvdata(file);
if (f->tuner != 0)
return -EINVAL;
f->type = V4L2_TUNER_RADIO; f->type = V4L2_TUNER_RADIO;
f->frequency = rt->curfreq; f->frequency = rt->curfreq;
return 0; return 0;

View file

@ -254,6 +254,8 @@ static int vidioc_s_frequency(struct file *file, void *priv,
{ {
struct aztech *az = video_drvdata(file); struct aztech *az = video_drvdata(file);
if (f->tuner != 0 || f->type != V4L2_TUNER_RADIO)
return -EINVAL;
az_setfreq(az, f->frequency); az_setfreq(az, f->frequency);
return 0; return 0;
} }
@ -263,6 +265,8 @@ static int vidioc_g_frequency(struct file *file, void *priv,
{ {
struct aztech *az = video_drvdata(file); struct aztech *az = video_drvdata(file);
if (f->tuner != 0)
return -EINVAL;
f->type = V4L2_TUNER_RADIO; f->type = V4L2_TUNER_RADIO;
f->frequency = az->curfreq; f->frequency = az->curfreq;
return 0; return 0;

View file

@ -240,6 +240,8 @@ static int vidioc_s_frequency(struct file *file, void *priv,
{ {
struct gemtek_pci *card = video_drvdata(file); struct gemtek_pci *card = video_drvdata(file);
if (f->tuner != 0 || f->type != V4L2_TUNER_RADIO)
return -EINVAL;
if (f->frequency < GEMTEK_PCI_RANGE_LOW || if (f->frequency < GEMTEK_PCI_RANGE_LOW ||
f->frequency > GEMTEK_PCI_RANGE_HIGH) f->frequency > GEMTEK_PCI_RANGE_HIGH)
return -EINVAL; return -EINVAL;
@ -253,6 +255,8 @@ static int vidioc_g_frequency(struct file *file, void *priv,
{ {
struct gemtek_pci *card = video_drvdata(file); struct gemtek_pci *card = video_drvdata(file);
if (f->tuner != 0)
return -EINVAL;
f->type = V4L2_TUNER_RADIO; f->type = V4L2_TUNER_RADIO;
f->frequency = card->current_frequency; f->frequency = card->current_frequency;
return 0; return 0;

View file

@ -200,6 +200,8 @@ static int vidioc_s_frequency(struct file *file, void *priv,
{ {
struct maestro *dev = video_drvdata(file); struct maestro *dev = video_drvdata(file);
if (f->tuner != 0 || f->type != V4L2_TUNER_RADIO)
return -EINVAL;
if (f->frequency < FREQ_LO || f->frequency > FREQ_HI) if (f->frequency < FREQ_LO || f->frequency > FREQ_HI)
return -EINVAL; return -EINVAL;
mutex_lock(&dev->lock); mutex_lock(&dev->lock);
@ -213,6 +215,8 @@ static int vidioc_g_frequency(struct file *file, void *priv,
{ {
struct maestro *dev = video_drvdata(file); struct maestro *dev = video_drvdata(file);
if (f->tuner != 0)
return -EINVAL;
f->type = V4L2_TUNER_RADIO; f->type = V4L2_TUNER_RADIO;
mutex_lock(&dev->lock); mutex_lock(&dev->lock);
f->frequency = BITS2FREQ(radio_bits_get(dev)); f->frequency = BITS2FREQ(radio_bits_get(dev));

View file

@ -262,6 +262,8 @@ static int vidioc_s_frequency(struct file *file, void *priv,
{ {
struct maxiradio *dev = video_drvdata(file); struct maxiradio *dev = video_drvdata(file);
if (f->tuner != 0 || f->type != V4L2_TUNER_RADIO)
return -EINVAL;
if (f->frequency < FREQ_LO || f->frequency > FREQ_HI) { if (f->frequency < FREQ_LO || f->frequency > FREQ_HI) {
dprintk(dev, 1, "radio freq (%d.%02d MHz) out of range (%d-%d)\n", dprintk(dev, 1, "radio freq (%d.%02d MHz) out of range (%d-%d)\n",
f->frequency / 16000, f->frequency / 16000,
@ -285,6 +287,8 @@ static int vidioc_g_frequency(struct file *file, void *priv,
{ {
struct maxiradio *dev = video_drvdata(file); struct maxiradio *dev = video_drvdata(file);
if (f->tuner != 0)
return -EINVAL;
f->type = V4L2_TUNER_RADIO; f->type = V4L2_TUNER_RADIO;
f->frequency = dev->freq; f->frequency = dev->freq;

View file

@ -374,6 +374,8 @@ static int vidioc_s_frequency(struct file *file, void *priv,
{ {
struct amradio_device *radio = file->private_data; struct amradio_device *radio = file->private_data;
if (f->tuner != 0 || f->type != V4L2_TUNER_RADIO)
return -EINVAL;
return amradio_setfreq(radio, f->frequency); return amradio_setfreq(radio, f->frequency);
} }
@ -383,6 +385,8 @@ static int vidioc_g_frequency(struct file *file, void *priv,
{ {
struct amradio_device *radio = file->private_data; struct amradio_device *radio = file->private_data;
if (f->tuner != 0)
return -EINVAL;
f->type = V4L2_TUNER_RADIO; f->type = V4L2_TUNER_RADIO;
f->frequency = radio->curfreq; f->frequency = radio->curfreq;

View file

@ -167,6 +167,8 @@ static int vidioc_s_frequency(struct file *file, void *priv,
{ {
struct rtrack2 *rt = video_drvdata(file); struct rtrack2 *rt = video_drvdata(file);
if (f->tuner != 0 || f->type != V4L2_TUNER_RADIO)
return -EINVAL;
rt_setfreq(rt, f->frequency); rt_setfreq(rt, f->frequency);
return 0; return 0;
} }
@ -176,6 +178,8 @@ static int vidioc_g_frequency(struct file *file, void *priv,
{ {
struct rtrack2 *rt = video_drvdata(file); struct rtrack2 *rt = video_drvdata(file);
if (f->tuner != 0)
return -EINVAL;
f->type = V4L2_TUNER_RADIO; f->type = V4L2_TUNER_RADIO;
f->frequency = rt->curfreq; f->frequency = rt->curfreq;
return 0; return 0;

View file

@ -168,6 +168,8 @@ static int vidioc_s_frequency(struct file *file, void *priv,
{ {
struct fmi *fmi = video_drvdata(file); struct fmi *fmi = video_drvdata(file);
if (f->tuner != 0 || f->type != V4L2_TUNER_RADIO)
return -EINVAL;
if (f->frequency < RSF16_MINFREQ || if (f->frequency < RSF16_MINFREQ ||
f->frequency > RSF16_MAXFREQ) f->frequency > RSF16_MAXFREQ)
return -EINVAL; return -EINVAL;
@ -182,6 +184,8 @@ static int vidioc_g_frequency(struct file *file, void *priv,
{ {
struct fmi *fmi = video_drvdata(file); struct fmi *fmi = video_drvdata(file);
if (f->tuner != 0)
return -EINVAL;
f->type = V4L2_TUNER_RADIO; f->type = V4L2_TUNER_RADIO;
f->frequency = fmi->curfreq; f->frequency = fmi->curfreq;
return 0; return 0;

View file

@ -251,6 +251,8 @@ static int vidioc_s_frequency(struct file *file, void *priv,
{ {
struct fmr2 *fmr2 = video_drvdata(file); struct fmr2 *fmr2 = video_drvdata(file);
if (f->tuner != 0 || f->type != V4L2_TUNER_RADIO)
return -EINVAL;
if (f->frequency < RSF16_MINFREQ || if (f->frequency < RSF16_MINFREQ ||
f->frequency > RSF16_MAXFREQ) f->frequency > RSF16_MAXFREQ)
return -EINVAL; return -EINVAL;
@ -272,6 +274,8 @@ static int vidioc_g_frequency(struct file *file, void *priv,
{ {
struct fmr2 *fmr2 = video_drvdata(file); struct fmr2 *fmr2 = video_drvdata(file);
if (f->tuner != 0)
return -EINVAL;
f->type = V4L2_TUNER_RADIO; f->type = V4L2_TUNER_RADIO;
f->frequency = fmr2->curfreq; f->frequency = fmr2->curfreq;
return 0; return 0;

View file

@ -349,7 +349,7 @@ static int vidioc_s_frequency(struct file *file, void *priv,
{ {
struct tea5764_device *radio = video_drvdata(file); struct tea5764_device *radio = video_drvdata(file);
if (f->tuner != 0) if (f->tuner != 0 || f->type != V4L2_TUNER_RADIO)
return -EINVAL; return -EINVAL;
if (f->frequency == 0) { if (f->frequency == 0) {
/* We special case this as a power down control. */ /* We special case this as a power down control. */
@ -370,6 +370,8 @@ static int vidioc_g_frequency(struct file *file, void *priv,
struct tea5764_device *radio = video_drvdata(file); struct tea5764_device *radio = video_drvdata(file);
struct tea5764_regs *r = &radio->regs; struct tea5764_regs *r = &radio->regs;
if (f->tuner != 0)
return -EINVAL;
tea5764_i2c_read(radio); tea5764_i2c_read(radio);
memset(f, 0, sizeof(f)); memset(f, 0, sizeof(f));
f->type = V4L2_TUNER_RADIO; f->type = V4L2_TUNER_RADIO;

View file

@ -240,6 +240,8 @@ static int vidioc_s_frequency(struct file *file, void *priv,
{ {
struct terratec *tt = video_drvdata(file); struct terratec *tt = video_drvdata(file);
if (f->tuner != 0 || f->type != V4L2_TUNER_RADIO)
return -EINVAL;
tt_setfreq(tt, f->frequency); tt_setfreq(tt, f->frequency);
return 0; return 0;
} }
@ -249,6 +251,8 @@ static int vidioc_g_frequency(struct file *file, void *priv,
{ {
struct terratec *tt = video_drvdata(file); struct terratec *tt = video_drvdata(file);
if (f->tuner != 0)
return -EINVAL;
f->type = V4L2_TUNER_RADIO; f->type = V4L2_TUNER_RADIO;
f->frequency = tt->curfreq; f->frequency = tt->curfreq;
return 0; return 0;

View file

@ -239,6 +239,8 @@ static int vidioc_s_frequency(struct file *file, void *priv,
{ {
struct trust *tr = video_drvdata(file); struct trust *tr = video_drvdata(file);
if (f->tuner != 0 || f->type != V4L2_TUNER_RADIO)
return -EINVAL;
tr_setfreq(tr, f->frequency); tr_setfreq(tr, f->frequency);
return 0; return 0;
} }
@ -248,6 +250,8 @@ static int vidioc_g_frequency(struct file *file, void *priv,
{ {
struct trust *tr = video_drvdata(file); struct trust *tr = video_drvdata(file);
if (f->tuner != 0)
return -EINVAL;
f->type = V4L2_TUNER_RADIO; f->type = V4L2_TUNER_RADIO;
f->frequency = tr->curfreq; f->frequency = tr->curfreq;
return 0; return 0;

View file

@ -207,6 +207,8 @@ static int vidioc_g_frequency(struct file *file, void *priv,
{ {
struct typhoon *dev = video_drvdata(file); struct typhoon *dev = video_drvdata(file);
if (f->tuner != 0)
return -EINVAL;
f->type = V4L2_TUNER_RADIO; f->type = V4L2_TUNER_RADIO;
f->frequency = dev->curfreq; f->frequency = dev->curfreq;
return 0; return 0;
@ -217,6 +219,8 @@ static int vidioc_s_frequency(struct file *file, void *priv,
{ {
struct typhoon *dev = video_drvdata(file); struct typhoon *dev = video_drvdata(file);
if (f->tuner != 0 || f->type != V4L2_TUNER_RADIO)
return -EINVAL;
dev->curfreq = f->frequency; dev->curfreq = f->frequency;
typhoon_setfreq(dev, dev->curfreq); typhoon_setfreq(dev, dev->curfreq);
return 0; return 0;

View file

@ -266,6 +266,8 @@ static int vidioc_s_frequency(struct file *file, void *priv,
{ {
struct zoltrix *zol = video_drvdata(file); struct zoltrix *zol = video_drvdata(file);
if (f->tuner != 0 || f->type != V4L2_TUNER_RADIO)
return -EINVAL;
if (zol_setfreq(zol, f->frequency) != 0) if (zol_setfreq(zol, f->frequency) != 0)
return -EINVAL; return -EINVAL;
return 0; return 0;
@ -276,6 +278,8 @@ static int vidioc_g_frequency(struct file *file, void *priv,
{ {
struct zoltrix *zol = video_drvdata(file); struct zoltrix *zol = video_drvdata(file);
if (f->tuner != 0)
return -EINVAL;
f->type = V4L2_TUNER_RADIO; f->type = V4L2_TUNER_RADIO;
f->frequency = zol->curfreq; f->frequency = zol->curfreq;
return 0; return 0;