[PATCH 2/4] iio: pressure: mpl3115: clean up interrupt handling and locking

SeungJu Cheon <[email protected]>
Newsgroups dev.linux.lists.linux-kernel-mentees,org.kernel.vger.linux-iio
Message-ID <[email protected]>
Return IRQ_NONE instead of IRQ_HANDLED when reading
INT_SOURCE fails.

On shared interrupt lines, returning IRQ_HANDLED after a
failed register read may prevent other handlers from being
invoked.

Switch the trigger handler from explicit mutex_lock/unlock
to scoped_guard() for consistency with the locking style
used elsewhere in the driver.

Move mpl3115_config_interrupt() above the interrupt handler
in preparation for the FIFO support added in a subsequent
patch.

No functional change intended.

Signed-off-by: SeungJu Cheon <[email protected]>
---
 drivers/iio/pressure/mpl3115.c | 59 +++++++++++++++++-----------------
 1 file changed, 29 insertions(+), 30 deletions(-)

diff --git a/drivers/iio/pressure/mpl3115.c b/drivers/iio/pressure/mpl3115.c
index befb6d48efa9..52a3d0d59769 100644
--- a/drivers/iio/pressure/mpl3115.c
+++ b/drivers/iio/pressure/mpl3115.c
@@ -308,9 +308,8 @@ static irqreturn_t mpl3115_trigger_handler(int irq, void *p)
 	u8 buffer[16] __aligned(8) = { };
 	int ret;
 
-	mutex_lock(&data->lock);
-	ret = mpl3115_fill_trig_buffer(indio_dev, buffer);
-	mutex_unlock(&data->lock);
+	scoped_guard(mutex, &data->lock)
+		ret = mpl3115_fill_trig_buffer(indio_dev, buffer);
 	if (ret)
 		goto done;
 
@@ -322,6 +321,32 @@ static irqreturn_t mpl3115_trigger_handler(int irq, void *p)
 	return IRQ_HANDLED;
 }
 
+static int mpl3115_config_interrupt(struct mpl3115_data *data,
+				    u8 ctrl_reg1, u8 ctrl_reg4)
+{
+	int ret;
+
+	ret = i2c_smbus_write_byte_data(data->client, MPL3115_CTRL_REG1,
+					ctrl_reg1);
+	if (ret < 0)
+		return ret;
+
+	ret = i2c_smbus_write_byte_data(data->client, MPL3115_CTRL_REG4,
+					ctrl_reg4);
+	if (ret < 0)
+		goto reg1_cleanup;
+
+	data->ctrl_reg1 = ctrl_reg1;
+	data->ctrl_reg4 = ctrl_reg4;
+
+	return 0;
+
+reg1_cleanup:
+	i2c_smbus_write_byte_data(data->client, MPL3115_CTRL_REG1,
+				  data->ctrl_reg1);
+	return ret;
+}
+
 static const struct iio_event_spec mpl3115_temp_press_event[] = {
 	{
 		.type = IIO_EV_TYPE_THRESH,
@@ -381,7 +406,7 @@ static irqreturn_t mpl3115_interrupt_handler(int irq, void *private)
 
 	ret = i2c_smbus_read_byte_data(data->client, MPL3115_INT_SOURCE);
 	if (ret < 0)
-		return IRQ_HANDLED;
+		return IRQ_NONE;
 
 	if (!(ret & (MPL3115_INT_SRC_TTH | MPL3115_INT_SRC_PTH |
 		     MPL3115_INT_SRC_DRDY)))
@@ -420,32 +445,6 @@ static irqreturn_t mpl3115_interrupt_handler(int irq, void *private)
 	return IRQ_HANDLED;
 }
 
-static int mpl3115_config_interrupt(struct mpl3115_data *data,
-				    u8 ctrl_reg1, u8 ctrl_reg4)
-{
-	int ret;
-
-	ret = i2c_smbus_write_byte_data(data->client, MPL3115_CTRL_REG1,
-					ctrl_reg1);
-	if (ret < 0)
-		return ret;
-
-	ret = i2c_smbus_write_byte_data(data->client, MPL3115_CTRL_REG4,
-					ctrl_reg4);
-	if (ret < 0)
-		goto reg1_cleanup;
-
-	data->ctrl_reg1 = ctrl_reg1;
-	data->ctrl_reg4 = ctrl_reg4;
-
-	return 0;
-
-reg1_cleanup:
-	i2c_smbus_write_byte_data(data->client, MPL3115_CTRL_REG1,
-				  data->ctrl_reg1);
-	return ret;
-}
-
 static int mpl3115_set_trigger_state(struct iio_trigger *trig, bool state)
 {
 	struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig);
-- 
2.52.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.