linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: SF Markus Elfring <elfring@users.sourceforge.net>
To: linux-pm@vger.kernel.org, Sebastian Reichel <sre@kernel.org>
Cc: LKML <linux-kernel@vger.kernel.org>, kernel-janitors@vger.kernel.org
Subject: [PATCH 1/2] max8997_charger: Use common error handling code in max8997_battery_probe()
Date: Mon, 30 Oct 2017 22:35:25 +0100	[thread overview]
Message-ID: <d60769d4-97cc-5965-d282-8484987f019e@users.sourceforge.net> (raw)
In-Reply-To: <286b1fea-ccff-5fed-5e2d-fc3b0064cd4d@users.sourceforge.net>

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Mon, 30 Oct 2017 22:14:52 +0100

Add a jump target so that a specific error message is stored only once
at the end of this function implementation.
Replace two calls of the function "dev_err" by goto statements.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/power/supply/max8997_charger.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/power/supply/max8997_charger.c b/drivers/power/supply/max8997_charger.c
index fa861003fece..38a01706a56b 100644
--- a/drivers/power/supply/max8997_charger.c
+++ b/drivers/power/supply/max8997_charger.c
@@ -113,10 +113,8 @@ static int max8997_battery_probe(struct platform_device *pdev)
 
 		ret = max8997_update_reg(iodev->i2c,
 				MAX8997_REG_MBCCTRL5, val, 0xf);
-		if (ret < 0) {
-			dev_err(&pdev->dev, "Cannot use i2c bus.\n");
-			return ret;
-		}
+		if (ret < 0)
+			goto report_bus_failure;
 	}
 
 	switch (pdata->timeout) {
@@ -141,10 +139,8 @@ static int max8997_battery_probe(struct platform_device *pdev)
 				pdata->timeout);
 		return -EINVAL;
 	}
-	if (ret < 0) {
-		dev_err(&pdev->dev, "Cannot use i2c bus.\n");
-		return ret;
-	}
+	if (ret < 0)
+		goto report_bus_failure;
 
 	charger = devm_kzalloc(&pdev->dev, sizeof(struct charger_data),
 				GFP_KERNEL);
@@ -168,6 +164,10 @@ static int max8997_battery_probe(struct platform_device *pdev)
 	}
 
 	return 0;
+
+report_bus_failure:
+	dev_err(&pdev->dev, "Cannot use i2c bus.\n");
+	return ret;
 }
 
 static const struct platform_device_id max8997_battery_id[] = {
-- 
2.14.3


  reply	other threads:[~2017-10-30 21:35 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-30 21:34 [PATCH 0/2] max8997_charger: Fine-tuning for max8997_battery_probe() SF Markus Elfring
2017-10-30 21:35 ` SF Markus Elfring [this message]
2017-10-30 21:36 ` [PATCH 2/2] max8997_charger: Improve a size determination in max8997_battery_probe() SF Markus Elfring

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=d60769d4-97cc-5965-d282-8484987f019e@users.sourceforge.net \
    --to=elfring@users.sourceforge.net \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=sre@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).