Commit 60f81f12 authored by Florian Mickler's avatar Florian Mickler Committed by Mauro Carvalho Chehab

[media] vp702x: use preallocated buffer in the frontend

Note: This change is tested to compile only as I don't have the
hardware.
Signed-off-by: default avatarFlorian Mickler <florian@mickler.org>
Cc: Patrick Boettcher <pb@linuxtv.org>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent ee52f120
...@@ -41,14 +41,13 @@ struct vp702x_fe_state { ...@@ -41,14 +41,13 @@ struct vp702x_fe_state {
static int vp702x_fe_refresh_state(struct vp702x_fe_state *st) static int vp702x_fe_refresh_state(struct vp702x_fe_state *st)
{ {
struct vp702x_device_state *dst = st->d->priv;
u8 *buf; u8 *buf;
if (time_after(jiffies, st->next_status_check)) { if (time_after(jiffies, st->next_status_check)) {
buf = kmalloc(10, GFP_KERNEL); mutex_lock(&dst->buf_mutex);
if (!buf) { buf = dst->buf;
deb_fe("%s: buffer alloc failed\n", __func__);
return -ENOMEM;
}
vp702x_usb_in_op(st->d, READ_STATUS, 0, 0, buf, 10); vp702x_usb_in_op(st->d, READ_STATUS, 0, 0, buf, 10);
st->lock = buf[4]; st->lock = buf[4];
...@@ -58,9 +57,8 @@ static int vp702x_fe_refresh_state(struct vp702x_fe_state *st) ...@@ -58,9 +57,8 @@ static int vp702x_fe_refresh_state(struct vp702x_fe_state *st)
vp702x_usb_in_op(st->d, READ_TUNER_REG_REQ, 0x15, 0, buf, 1); vp702x_usb_in_op(st->d, READ_TUNER_REG_REQ, 0x15, 0, buf, 1);
st->sig = buf[0]; st->sig = buf[0];
mutex_unlock(&dst->buf_mutex);
st->next_status_check = jiffies + (st->status_check_interval*HZ)/1000; st->next_status_check = jiffies + (st->status_check_interval*HZ)/1000;
kfree(buf);
} }
return 0; return 0;
} }
...@@ -141,15 +139,17 @@ static int vp702x_fe_set_frontend(struct dvb_frontend* fe, ...@@ -141,15 +139,17 @@ static int vp702x_fe_set_frontend(struct dvb_frontend* fe,
struct dvb_frontend_parameters *fep) struct dvb_frontend_parameters *fep)
{ {
struct vp702x_fe_state *st = fe->demodulator_priv; struct vp702x_fe_state *st = fe->demodulator_priv;
struct vp702x_device_state *dst = st->d->priv;
u32 freq = fep->frequency/1000; u32 freq = fep->frequency/1000;
/*CalFrequency*/ /*CalFrequency*/
/* u16 frequencyRef[16] = { 2, 4, 8, 16, 32, 64, 128, 256, 24, 5, 10, 20, 40, 80, 160, 320 }; */ /* u16 frequencyRef[16] = { 2, 4, 8, 16, 32, 64, 128, 256, 24, 5, 10, 20, 40, 80, 160, 320 }; */
u64 sr; u64 sr;
u8 *cmd; u8 *cmd;
cmd = kzalloc(10, GFP_KERNEL); mutex_lock(&dst->buf_mutex);
if (!cmd)
return -ENOMEM; cmd = dst->buf;
memset(cmd, 0, 10);
cmd[0] = (freq >> 8) & 0x7f; cmd[0] = (freq >> 8) & 0x7f;
cmd[1] = freq & 0xff; cmd[1] = freq & 0xff;
...@@ -192,7 +192,8 @@ static int vp702x_fe_set_frontend(struct dvb_frontend* fe, ...@@ -192,7 +192,8 @@ static int vp702x_fe_set_frontend(struct dvb_frontend* fe,
else else
deb_fe("tuning succeeded.\n"); deb_fe("tuning succeeded.\n");
kfree(cmd); mutex_unlock(&dst->buf_mutex);
return 0; return 0;
} }
...@@ -220,21 +221,18 @@ static int vp702x_fe_get_frontend(struct dvb_frontend* fe, ...@@ -220,21 +221,18 @@ static int vp702x_fe_get_frontend(struct dvb_frontend* fe,
static int vp702x_fe_send_diseqc_msg (struct dvb_frontend* fe, static int vp702x_fe_send_diseqc_msg (struct dvb_frontend* fe,
struct dvb_diseqc_master_cmd *m) struct dvb_diseqc_master_cmd *m)
{ {
int ret;
u8 *cmd; u8 *cmd;
struct vp702x_fe_state *st = fe->demodulator_priv; struct vp702x_fe_state *st = fe->demodulator_priv;
struct vp702x_device_state *dst = st->d->priv;
cmd = kzalloc(10, GFP_KERNEL);
if (!cmd)
return -ENOMEM;
deb_fe("%s\n",__func__); deb_fe("%s\n",__func__);
if (m->msg_len > 4) { if (m->msg_len > 4)
ret = -EINVAL; return -EINVAL;
goto out;
} mutex_lock(&dst->buf_mutex);
cmd = dst->buf;
cmd[1] = SET_DISEQC_CMD; cmd[1] = SET_DISEQC_CMD;
cmd[2] = m->msg_len; cmd[2] = m->msg_len;
memcpy(&cmd[3], m->msg, m->msg_len); memcpy(&cmd[3], m->msg, m->msg_len);
...@@ -246,10 +244,10 @@ static int vp702x_fe_send_diseqc_msg (struct dvb_frontend* fe, ...@@ -246,10 +244,10 @@ static int vp702x_fe_send_diseqc_msg (struct dvb_frontend* fe,
deb_fe("diseqc cmd failed.\n"); deb_fe("diseqc cmd failed.\n");
else else
deb_fe("diseqc cmd succeeded.\n"); deb_fe("diseqc cmd succeeded.\n");
ret = 0;
out: mutex_unlock(&dst->buf_mutex);
kfree(cmd);
return ret; return 0;
} }
static int vp702x_fe_send_diseqc_burst (struct dvb_frontend* fe, fe_sec_mini_cmd_t burst) static int vp702x_fe_send_diseqc_burst (struct dvb_frontend* fe, fe_sec_mini_cmd_t burst)
...@@ -261,14 +259,11 @@ static int vp702x_fe_send_diseqc_burst (struct dvb_frontend* fe, fe_sec_mini_cmd ...@@ -261,14 +259,11 @@ static int vp702x_fe_send_diseqc_burst (struct dvb_frontend* fe, fe_sec_mini_cmd
static int vp702x_fe_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone) static int vp702x_fe_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone)
{ {
struct vp702x_fe_state *st = fe->demodulator_priv; struct vp702x_fe_state *st = fe->demodulator_priv;
struct vp702x_device_state *dst = st->d->priv;
u8 *buf; u8 *buf;
deb_fe("%s\n",__func__); deb_fe("%s\n",__func__);
buf = kmalloc(10, GFP_KERNEL);
if (!buf)
return -ENOMEM;
st->tone_mode = tone; st->tone_mode = tone;
if (tone == SEC_TONE_ON) if (tone == SEC_TONE_ON)
...@@ -277,6 +272,10 @@ static int vp702x_fe_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone) ...@@ -277,6 +272,10 @@ static int vp702x_fe_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone)
st->lnb_buf[2] = 0x00; st->lnb_buf[2] = 0x00;
st->lnb_buf[7] = vp702x_chksum(st->lnb_buf, 0, 7); st->lnb_buf[7] = vp702x_chksum(st->lnb_buf, 0, 7);
mutex_lock(&dst->buf_mutex);
buf = dst->buf;
memcpy(buf, st->lnb_buf, 8); memcpy(buf, st->lnb_buf, 8);
vp702x_usb_inout_op(st->d, buf, 8, buf, 10, 100); vp702x_usb_inout_op(st->d, buf, 8, buf, 10, 100);
...@@ -285,7 +284,8 @@ static int vp702x_fe_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone) ...@@ -285,7 +284,8 @@ static int vp702x_fe_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone)
else else
deb_fe("set_tone cmd succeeded.\n"); deb_fe("set_tone cmd succeeded.\n");
kfree(buf); mutex_unlock(&dst->buf_mutex);
return 0; return 0;
} }
...@@ -293,13 +293,10 @@ static int vp702x_fe_set_voltage (struct dvb_frontend* fe, fe_sec_voltage_t ...@@ -293,13 +293,10 @@ static int vp702x_fe_set_voltage (struct dvb_frontend* fe, fe_sec_voltage_t
voltage) voltage)
{ {
struct vp702x_fe_state *st = fe->demodulator_priv; struct vp702x_fe_state *st = fe->demodulator_priv;
struct vp702x_device_state *dst = st->d->priv;
u8 *buf; u8 *buf;
deb_fe("%s\n",__func__); deb_fe("%s\n",__func__);
buf = kmalloc(10, GFP_KERNEL);
if (!buf)
return -ENOMEM;
st->voltage = voltage; st->voltage = voltage;
if (voltage != SEC_VOLTAGE_OFF) if (voltage != SEC_VOLTAGE_OFF)
...@@ -308,6 +305,10 @@ static int vp702x_fe_set_voltage (struct dvb_frontend* fe, fe_sec_voltage_t ...@@ -308,6 +305,10 @@ static int vp702x_fe_set_voltage (struct dvb_frontend* fe, fe_sec_voltage_t
st->lnb_buf[4] = 0x00; st->lnb_buf[4] = 0x00;
st->lnb_buf[7] = vp702x_chksum(st->lnb_buf, 0, 7); st->lnb_buf[7] = vp702x_chksum(st->lnb_buf, 0, 7);
mutex_lock(&dst->buf_mutex);
buf = dst->buf;
memcpy(buf, st->lnb_buf, 8); memcpy(buf, st->lnb_buf, 8);
vp702x_usb_inout_op(st->d, buf, 8, buf, 10, 100); vp702x_usb_inout_op(st->d, buf, 8, buf, 10, 100);
...@@ -316,7 +317,7 @@ static int vp702x_fe_set_voltage (struct dvb_frontend* fe, fe_sec_voltage_t ...@@ -316,7 +317,7 @@ static int vp702x_fe_set_voltage (struct dvb_frontend* fe, fe_sec_voltage_t
else else
deb_fe("set_voltage cmd succeeded.\n"); deb_fe("set_voltage cmd succeeded.\n");
kfree(buf); mutex_unlock(&dst->buf_mutex);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment