linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Nuno Sá" <nuno.sa@analog.com>
To: <devicetree@vger.kernel.org>, <linux-gpio@vger.kernel.org>,
	<linux-input@vger.kernel.org>
Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	Bartosz Golaszewski <brgl@bgdev.pl>,
	Michael Hennerich <michael.hennerich@analog.com>,
	"Rob Herring" <robh+dt@kernel.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
	Linus Walleij <linus.walleij@linaro.org>
Subject: [PATCH 03/10] input: keyboard: adp5588-keys: bail out on returned error
Date: Fri, 8 Jul 2022 11:34:41 +0200	[thread overview]
Message-ID: <20220708093448.42617-4-nuno.sa@analog.com> (raw)
In-Reply-To: <20220708093448.42617-1-nuno.sa@analog.com>

Don't continue in code paths after some error is found. It makes no
sense to do any other device configuration if a previous one failed.

Signed-off-by: Nuno Sá <nuno.sa@analog.com>
---
 drivers/input/keyboard/adp5588-keys.c | 56 ++++++++++++++++++---------
 1 file changed, 38 insertions(+), 18 deletions(-)

diff --git a/drivers/input/keyboard/adp5588-keys.c b/drivers/input/keyboard/adp5588-keys.c
index dad8862f6c76..10f24283d7a3 100644
--- a/drivers/input/keyboard/adp5588-keys.c
+++ b/drivers/input/keyboard/adp5588-keys.c
@@ -146,9 +146,13 @@ static int adp5588_gpio_direction_output(struct gpio_chip *chip,
 
 	ret = adp5588_write(kpad->client, GPIO_DAT_OUT1 + bank,
 				 kpad->dat_out[bank]);
-	ret |= adp5588_write(kpad->client, GPIO_DIR1 + bank,
+	if (ret)
+		goto out_unlock;
+
+	ret = adp5588_write(kpad->client, GPIO_DIR1 + bank,
 				 kpad->dir[bank]);
 
+out_unlock:
 	mutex_unlock(&kpad->gpio_lock);
 
 	return ret;
@@ -439,42 +443,58 @@ static int adp5588_setup(struct i2c_client *client)
 	int i, ret;
 
 	ret = adp5588_write(client, KP_GPIO1, KP_SEL(pdata->rows));
-	ret |= adp5588_write(client, KP_GPIO2, KP_SEL(pdata->cols) & 0xFF);
-	ret |= adp5588_write(client, KP_GPIO3, KP_SEL(pdata->cols) >> 8);
+	if (ret)
+		return ret;
+
+	ret = adp5588_write(client, KP_GPIO2, KP_SEL(pdata->cols) & 0xFF);
+	if (ret)
+		return ret;
+
+	ret = adp5588_write(client, KP_GPIO3, KP_SEL(pdata->cols) >> 8);
+	if (ret)
+		return ret;
 
 	if (pdata->en_keylock) {
-		ret |= adp5588_write(client, UNLOCK1, pdata->unlock_key1);
-		ret |= adp5588_write(client, UNLOCK2, pdata->unlock_key2);
-		ret |= adp5588_write(client, KEY_LCK_EC_STAT, ADP5588_K_LCK_EN);
+		ret = adp5588_write(client, UNLOCK1, pdata->unlock_key1);
+		if (ret)
+			return ret;
+
+		ret = adp5588_write(client, UNLOCK2, pdata->unlock_key2);
+		if (ret)
+			return ret;
+
+		ret = adp5588_write(client, KEY_LCK_EC_STAT, ADP5588_K_LCK_EN);
+		if (ret)
+			return ret;
 	}
 
-	for (i = 0; i < KEYP_MAX_EVENT; i++)
-		ret |= adp5588_read(client, Key_EVENTA);
+	for (i = 0; i < KEYP_MAX_EVENT; i++) {
+		ret = adp5588_read(client, Key_EVENTA);
+		if (ret)
+			return ret;
+	}
 
 	if (gpio_data) {
 		for (i = 0; i <= ADP5588_BANK(ADP5588_MAXGPIO); i++) {
 			int pull_mask = gpio_data->pullup_dis_mask;
 
-			ret |= adp5588_write(client, GPIO_PULL1 + i,
+			ret = adp5588_write(client, GPIO_PULL1 + i,
 				(pull_mask >> (8 * i)) & 0xFF);
+			if (ret)
+				return ret;
 		}
 	}
 
-	ret |= adp5588_write(client, INT_STAT,
+	ret = adp5588_write(client, INT_STAT,
 				ADP5588_CMP2_INT | ADP5588_CMP1_INT |
 				ADP5588_OVR_FLOW_INT | ADP5588_K_LCK_INT |
 				ADP5588_GPI_INT | ADP5588_KE_INT); /* Status is W1C */
+	if (ret)
+		return ret;
 
-	ret |= adp5588_write(client, CFG, ADP5588_INT_CFG |
+	return adp5588_write(client, CFG, ADP5588_INT_CFG |
 					  ADP5588_OVR_FLOW_IEN |
 					  ADP5588_KE_IEN);
-
-	if (ret < 0) {
-		dev_err(&client->dev, "Write Error\n");
-		return ret;
-	}
-
-	return 0;
 }
 
 static int adp5588_probe(struct i2c_client *client,
-- 
2.37.0


  parent reply	other threads:[~2022-07-08  9:34 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-08  9:34 [PATCH 00/10] adp5588-keys refactor and fw properties support Nuno Sá
2022-07-08  9:34 ` [PATCH 01/10] input: keyboard: adp5588-keys: support gpi key events as 'gpio keys' Nuno Sá
2022-07-08 14:18   ` Andy Shevchenko
2022-07-08 14:55     ` Sa, Nuno
2022-07-08 15:04       ` Andy Shevchenko
2022-07-08 15:24         ` Sa, Nuno
2022-07-11 14:16           ` Nuno Sá
2022-07-09  4:10   ` kernel test robot
2022-07-09 11:52     ` Andy Shevchenko
2022-07-12  5:29   ` kernel test robot
2022-07-08  9:34 ` [PATCH 02/10] gpio: gpio-adp5588: drop the driver Nuno Sá
2022-07-08 13:28   ` Bartosz Golaszewski
2022-07-08  9:34 ` Nuno Sá [this message]
2022-07-08 14:25   ` [PATCH 03/10] input: keyboard: adp5588-keys: bail out on returned error Andy Shevchenko
2022-07-08 14:35     ` Sa, Nuno
2022-07-08 14:57       ` Andy Shevchenko
2022-07-08  9:34 ` [PATCH 04/10] input: keyboard: adp5588-keys: add support for fw properties Nuno Sá
2022-07-08 14:56   ` Andy Shevchenko
2022-07-08 15:04     ` Sa, Nuno
2022-07-08 15:07       ` Andy Shevchenko
2022-07-12 14:31         ` Nuno Sá
2022-07-09  1:14   ` kernel test robot
2022-07-08  9:34 ` [PATCH 05/10] dt-bindings: input: adp5588-keys: add bindings Nuno Sá
2022-07-11 23:03   ` Rob Herring
2022-07-08  9:34 ` [PATCH 06/10] input: keyboard: adp5588-keys: do not check for irq presence Nuno Sá
2022-07-08  9:34 ` [PATCH 07/10] input: keyboard: adp5588-keys: fix coding style warnings Nuno Sá
2022-07-08 14:49   ` Andy Shevchenko
2022-07-08 15:05     ` Sa, Nuno
2022-07-08 15:10       ` Andy Shevchenko
2022-07-08  9:34 ` [PATCH 08/10] input: keyboard: adp5588-keys: add optional reset gpio Nuno Sá
2022-07-11 12:52   ` Linus Walleij
2022-07-08  9:34 ` [PATCH 09/10] input: keyboard: adp5588-keys: add regulator support Nuno Sá
2022-07-08 14:47   ` Andy Shevchenko
2022-07-08 15:00     ` Sa, Nuno
2022-07-08  9:34 ` [PATCH 10/10] input: keyboard: adp5588-keys: Use new PM macros Nuno Sá
2022-07-08 13:59 ` [PATCH 00/10] adp5588-keys refactor and fw properties support Andy Shevchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220708093448.42617-4-nuno.sa@analog.com \
    --to=nuno.sa@analog.com \
    --cc=brgl@bgdev.pl \
    --cc=devicetree@vger.kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=michael.hennerich@analog.com \
    --cc=robh+dt@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).