diff mbox series

[v5,03/15] iio: sx9310: Fix irq handling

Message ID 20200803175559.v5.3.Idbfcd2e92d2fd89b6ed2e83211bd3e6c06852c33@changeid (mailing list archive)
State New, archived
Headers show
Series sx9310 iio driver updates | expand

Commit Message

Daniel Campello Aug. 3, 2020, 11:58 p.m. UTC
Fixes enable/disable irq handling at various points. The driver needs to
only enable/disable irqs if there is an actual irq handler installed.

Signed-off-by: Daniel Campello <campello@chromium.org>
Reviewed-by: Stephen Boyd <swboyd@chromium.org>
---

Changes in v5: None
Changes in v4:
 - Reverted condition check logic on enable/disable_irq methods.

Changes in v3:
 - Moved irq presence check down to lower methods

Changes in v2:
 - Reordered error handling on sx9310_resume()

 drivers/iio/proximity/sx9310.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

Comments

Andy Shevchenko Aug. 4, 2020, 7:26 a.m. UTC | #1
On Tue, Aug 4, 2020 at 2:58 AM Daniel Campello <campello@chromium.org> wrote:
>
> Fixes enable/disable irq handling at various points. The driver needs to
> only enable/disable irqs if there is an actual irq handler installed.

Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>

> Signed-off-by: Daniel Campello <campello@chromium.org>
> Reviewed-by: Stephen Boyd <swboyd@chromium.org>
> ---
>
> Changes in v5: None
> Changes in v4:
>  - Reverted condition check logic on enable/disable_irq methods.
>
> Changes in v3:
>  - Moved irq presence check down to lower methods
>
> Changes in v2:
>  - Reordered error handling on sx9310_resume()
>
>  drivers/iio/proximity/sx9310.c | 11 ++++++++---
>  1 file changed, 8 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/iio/proximity/sx9310.c b/drivers/iio/proximity/sx9310.c
> index d7c77fc661ba86..dafee85018aa6d 100644
> --- a/drivers/iio/proximity/sx9310.c
> +++ b/drivers/iio/proximity/sx9310.c
> @@ -323,11 +323,15 @@ static int sx9310_put_event_channel(struct sx9310_data *data, int channel)
>
>  static int sx9310_enable_irq(struct sx9310_data *data, unsigned int irq)
>  {
> +       if (!data->client->irq)
> +               return 0;
>         return regmap_update_bits(data->regmap, SX9310_REG_IRQ_MSK, irq, irq);
>  }
>
>  static int sx9310_disable_irq(struct sx9310_data *data, unsigned int irq)
>  {
> +       if (!data->client->irq)
> +               return 0;
>         return regmap_update_bits(data->regmap, SX9310_REG_IRQ_MSK, irq, 0);
>  }
>
> @@ -381,7 +385,7 @@ static int sx9310_read_proximity(struct sx9310_data *data,
>
>         mutex_unlock(&data->mutex);
>
> -       if (data->client->irq > 0) {
> +       if (data->client->irq) {
>                 ret = wait_for_completion_interruptible(&data->completion);
>                 reinit_completion(&data->completion);
>         } else {
> @@ -1010,10 +1014,11 @@ static int __maybe_unused sx9310_resume(struct device *dev)
>
>  out:
>         mutex_unlock(&data->mutex);
> +       if (ret)
> +               return ret;
>
>         enable_irq(data->client->irq);
> -
> -       return ret;
> +       return 0;
>  }
>
>  static const struct dev_pm_ops sx9310_pm_ops = {
> --
> 2.28.0.163.g6104cc2f0b6-goog
>
diff mbox series

Patch

diff --git a/drivers/iio/proximity/sx9310.c b/drivers/iio/proximity/sx9310.c
index d7c77fc661ba86..dafee85018aa6d 100644
--- a/drivers/iio/proximity/sx9310.c
+++ b/drivers/iio/proximity/sx9310.c
@@ -323,11 +323,15 @@  static int sx9310_put_event_channel(struct sx9310_data *data, int channel)
 
 static int sx9310_enable_irq(struct sx9310_data *data, unsigned int irq)
 {
+	if (!data->client->irq)
+		return 0;
 	return regmap_update_bits(data->regmap, SX9310_REG_IRQ_MSK, irq, irq);
 }
 
 static int sx9310_disable_irq(struct sx9310_data *data, unsigned int irq)
 {
+	if (!data->client->irq)
+		return 0;
 	return regmap_update_bits(data->regmap, SX9310_REG_IRQ_MSK, irq, 0);
 }
 
@@ -381,7 +385,7 @@  static int sx9310_read_proximity(struct sx9310_data *data,
 
 	mutex_unlock(&data->mutex);
 
-	if (data->client->irq > 0) {
+	if (data->client->irq) {
 		ret = wait_for_completion_interruptible(&data->completion);
 		reinit_completion(&data->completion);
 	} else {
@@ -1010,10 +1014,11 @@  static int __maybe_unused sx9310_resume(struct device *dev)
 
 out:
 	mutex_unlock(&data->mutex);
+	if (ret)
+		return ret;
 
 	enable_irq(data->client->irq);
-
-	return ret;
+	return 0;
 }
 
 static const struct dev_pm_ops sx9310_pm_ops = {