Skip to content

Commit

Permalink
fix mutex double lock deadlock problem
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamV committed Jun 23, 2020
1 parent 322a7a8 commit ce23497
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 23 deletions.
8 changes: 5 additions & 3 deletions availink/avl62x1/avl62x1_top.c
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,10 @@ static int read_status(struct dvb_frontend *fe, enum fe_status *status)
mutex_lock(&i2cctl_fe_mutex);

r = avl62x1_get_lock_status(&lock, priv->chip);
if (!r && lock == avl62x1_status_locked)

safe_mutex_unlock(&i2cctl_fe_mutex);

if (!r && lock == avl62x1_status_locked)
{
*status = FE_HAS_SIGNAL | FE_HAS_CARRIER |
FE_HAS_VITERBI | FE_HAS_SYNC |
Expand All @@ -905,7 +908,6 @@ static int read_status(struct dvb_frontend *fe, enum fe_status *status)
*status = FE_HAS_SIGNAL;
}

safe_mutex_unlock(&i2cctl_fe_mutex);

return r;
}
Expand Down Expand Up @@ -1704,4 +1706,4 @@ MODULE_DESCRIPTION("Availink AVL62X1 DVB-S/S2/S2X demodulator driver");
MODULE_AUTHOR("Availink, Inc. ([email protected])");
MODULE_LICENSE("GPL");
MODULE_VERSION(AVL62X1_VERSION);
MODULE_FIRMWARE(AVL62X1_FIRMWARE);
MODULE_FIRMWARE(AVL62X1_FIRMWARE);
43 changes: 23 additions & 20 deletions availink/avl68x2/avl68x2_top.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,26 +192,26 @@ static long i2cctl_dev_ioctl(struct file *file, unsigned int cmd, unsigned long
{
case I2CCTL_IOCLOCK:
if(req->demod) {
mutex_lock(&i2cctl_fe_mutex);
p_debug_lvl(4,"locked demod");
mutex_lock(&i2cctl_fe_mutex);
p_debug_lvl(4,"locked demod");
}
if(req->tuner) {
mutex_lock(&i2cctl_tuneri2c_mutex);
mutex_lock(&i2cctl_tuneri2c_mutex);
p_debug_lvl(4,"locked tuner");
}
break;
case I2CCTL_IOCUNLOCK:
if(req->demod) {
if(mutex_is_locked(&i2cctl_fe_mutex)) {
mutex_unlock(&i2cctl_fe_mutex);
p_debug_lvl(4,"unlocked demod");
}
if(mutex_is_locked(&i2cctl_fe_mutex)) {
mutex_unlock(&i2cctl_fe_mutex);
p_debug_lvl(4,"unlocked demod");
}
}
if(req->tuner) {
if(mutex_is_locked(&i2cctl_tuneri2c_mutex)) {
mutex_unlock(&i2cctl_tuneri2c_mutex);
p_debug_lvl(4,"unlocked tuner");
}
if(mutex_is_locked(&i2cctl_tuneri2c_mutex)) {
mutex_unlock(&i2cctl_tuneri2c_mutex);
p_debug_lvl(4,"unlocked tuner");
}
}
break;
default: /* redundant, as cmd was checked against MAXNR */
Expand Down Expand Up @@ -366,7 +366,7 @@ static int diseqc_set_voltage(
p_debug("voltage 18");
break;
default:
safe_mutex_unlock(&i2cctl_fe_mutex);
safe_mutex_unlock(&i2cctl_fe_mutex);
return -EINVAL;
}
ret = avl68x2_demod_set_gpio(AVL_Pin37, pwr, priv->chip);
Expand All @@ -386,7 +386,7 @@ static int avl68x2_i2c_gate_ctrl(struct dvb_frontend *fe, int enable)

if (enable)
{
mutex_lock(&i2cctl_tuneri2c_mutex);
mutex_lock(&i2cctl_tuneri2c_mutex);
ret = avl68x2_demod_i2c_passthru_on(priv->chip);
}
else
Expand Down Expand Up @@ -1275,7 +1275,16 @@ static int avl68x2_read_status(struct dvb_frontend *fe, enum fe_status *status)
mutex_lock(&i2cctl_fe_mutex);

ret = avl68x2_demod_get_lock_status(&lock, priv->chip);
if (!ret && lock == AVL_STATUS_LOCK)

if(debug > 1) {
ret |= avl68x2_demod_get_snr (&SNR_x100db, priv->chip);
ret = (int)avl68x2_demod_get_per(&ber, priv->chip);
printk("read status %d, snr = %d, per = %d\n",*status, SNR_x100db, ber);
}

safe_mutex_unlock(&i2cctl_fe_mutex);

if (!ret && lock == AVL_STATUS_LOCK)
{
*status = FE_HAS_SIGNAL | FE_HAS_CARRIER |
FE_HAS_VITERBI | FE_HAS_SYNC | FE_HAS_LOCK;
Expand All @@ -1288,19 +1297,13 @@ static int avl68x2_read_status(struct dvb_frontend *fe, enum fe_status *status)
avl68x2_set_lock_led(fe,0);
}

if(debug > 1) {
ret |= avl68x2_demod_get_snr (&SNR_x100db, priv->chip);
ret = (int)avl68x2_demod_get_per(&ber, priv->chip);
printk("read status %d, snr = %d, per = %d\n",*status, SNR_x100db, ber);
}

#if INCLUDE_STDOUT
if(debug > 2) {
printk("%s",read_stdout(fe));
}
#endif

safe_mutex_unlock(&i2cctl_fe_mutex);
return ret;
}

Expand Down

0 comments on commit ce23497

Please sign in to comment.