Commit 0b9a0cd6 authored by Ricardo Ribalda's avatar Ricardo Ribalda Committed by Hans Verkuil

media: dvb-frontends/stv090x: Refactor tuner_i2c_lock

Move the lock logic to it's own function. There is less code duplication
and cocci is much happier.

Fix the following cocci warning:
drivers/media/dvb-frontends/stv090x.c:799:1-7: preceding lock on line 768
Signed-off-by: default avatarRicardo Ribalda <ribalda@chromium.org>
Signed-off-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
parent f56d1edb
...@@ -748,6 +748,22 @@ static int stv090x_write_reg(struct stv090x_state *state, unsigned int reg, u8 d ...@@ -748,6 +748,22 @@ static int stv090x_write_reg(struct stv090x_state *state, unsigned int reg, u8 d
return stv090x_write_regs(state, reg, &tmp, 1); return stv090x_write_regs(state, reg, &tmp, 1);
} }
static inline void stv090x_tuner_i2c_lock(struct stv090x_state *state)
{
if (state->config->tuner_i2c_lock)
state->config->tuner_i2c_lock(&state->frontend, 1);
else
mutex_lock(&state->internal->tuner_lock);
}
static inline void stv090x_tuner_i2c_unlock(struct stv090x_state *state)
{
if (state->config->tuner_i2c_lock)
state->config->tuner_i2c_lock(&state->frontend, 0);
else
mutex_unlock(&state->internal->tuner_lock);
}
static int stv090x_i2c_gate_ctrl(struct stv090x_state *state, int enable) static int stv090x_i2c_gate_ctrl(struct stv090x_state *state, int enable)
{ {
u32 reg; u32 reg;
...@@ -761,12 +777,8 @@ static int stv090x_i2c_gate_ctrl(struct stv090x_state *state, int enable) ...@@ -761,12 +777,8 @@ static int stv090x_i2c_gate_ctrl(struct stv090x_state *state, int enable)
* In case of any error, the lock is unlocked and exit within the * In case of any error, the lock is unlocked and exit within the
* relevant operations themselves. * relevant operations themselves.
*/ */
if (enable) { if (enable)
if (state->config->tuner_i2c_lock) stv090x_tuner_i2c_lock(state);
state->config->tuner_i2c_lock(&state->frontend, 1);
else
mutex_lock(&state->internal->tuner_lock);
}
reg = STV090x_READ_DEMOD(state, I2CRPT); reg = STV090x_READ_DEMOD(state, I2CRPT);
if (enable) { if (enable) {
...@@ -782,20 +794,13 @@ static int stv090x_i2c_gate_ctrl(struct stv090x_state *state, int enable) ...@@ -782,20 +794,13 @@ static int stv090x_i2c_gate_ctrl(struct stv090x_state *state, int enable)
goto err; goto err;
} }
if (!enable) { if (!enable)
if (state->config->tuner_i2c_lock) stv090x_tuner_i2c_unlock(state);
state->config->tuner_i2c_lock(&state->frontend, 0);
else
mutex_unlock(&state->internal->tuner_lock);
}
return 0; return 0;
err: err:
dprintk(FE_ERROR, 1, "I/O error"); dprintk(FE_ERROR, 1, "I/O error");
if (state->config->tuner_i2c_lock) stv090x_tuner_i2c_unlock(state);
state->config->tuner_i2c_lock(&state->frontend, 0);
else
mutex_unlock(&state->internal->tuner_lock);
return -1; return -1;
} }
......
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