> -----Original Message----- > From: Hartmut Knaack [mailto:knaack.h@xxxxxx] > Sent: 17 July, 2015 11:52 > To: linux-iio@xxxxxxxxxxxxxxx > Cc: Jonathan Cameron; Lars-Peter Clausen; Peter Meerwald; Tirdea, Irina; Dogaru, Vlad > Subject: [PATCH 6/8] iio:magnetometer:bmc150_magn: protect runtime_resume with mutex > > Protect bmc150_magn_runtime_resume() with a mutex, as done with other > suspend/resume functions. > > Signed-off-by: Hartmut Knaack <knaack.h@xxxxxx> > --- > drivers/iio/magnetometer/bmc150_magn.c | 9 +++++++-- > 1 file changed, 7 insertions(+), 2 deletions(-) > > diff --git a/drivers/iio/magnetometer/bmc150_magn.c b/drivers/iio/magnetometer/bmc150_magn.c > index e1f804b2b244..ac0cdbde813b 100644 > --- a/drivers/iio/magnetometer/bmc150_magn.c > +++ b/drivers/iio/magnetometer/bmc150_magn.c > @@ -1052,9 +1052,14 @@ static int bmc150_magn_runtime_resume(struct device *dev) > { > struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev)); > struct bmc150_magn_data *data = iio_priv(indio_dev); > + int ret; > > - return bmc150_magn_set_power_mode(data, BMC150_MAGN_POWER_MODE_NORMAL, > - true); > + mutex_lock(&data->mutex); > + ret = bmc150_magn_set_power_mode(data, BMC150_MAGN_POWER_MODE_NORMAL, > + true); > + mutex_unlock(&data->mutex); > + > + return ret; This function does not have mutex_lock/unlock because it is called with data->mutex locked. I should have added a comment to specify this. Whenever we wake up the device, bmc150_magn_set_power_state is called after locking data->mutex. This in turn calls pm_runtime_get_sync which will immediately call bmc150_magn_runtime_resume. Trying to lock the mutex here would lead to a deadlock (e.g. when trying to read a value through sysfs _raw). Since this driver uses autosuspend delay, the situation is different for runtime suspend since that is called after 2 seconds in a separate thread. This is why there is a mutex locked in runtime suspend but not in runtime resume. > } > #endif > > -- > 2.4.3 -- To unsubscribe from this list: send the line "unsubscribe linux-iio" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html