From patchwork Thu Oct 26 08:40:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SF Markus Elfring X-Patchwork-Id: 10027809 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id AEEBC6032C for ; Thu, 26 Oct 2017 08:40:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9E14728D1E for ; Thu, 26 Oct 2017 08:40:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9267F28D5F; Thu, 26 Oct 2017 08:40:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2D2E728D1E for ; Thu, 26 Oct 2017 08:40:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751173AbdJZIkj (ORCPT ); Thu, 26 Oct 2017 04:40:39 -0400 Received: from mout.web.de ([212.227.17.11]:61924 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750884AbdJZIkf (ORCPT ); Thu, 26 Oct 2017 04:40:35 -0400 Received: from [192.168.1.2] ([78.48.35.118]) by smtp.web.de (mrweb101 [213.165.67.124]) with ESMTPSA (Nemesis) id 0M5Oct-1dFurY1ckh-00zTpC; Thu, 26 Oct 2017 10:40:15 +0200 To: linux-iio@vger.kernel.org, Akinobu Mita , Crestez Dan Leonard , Hartmut Knaack , Jonathan Cameron , Lars-Peter Clausen , Peter Meerwald-Stadler Cc: LKML , kernel-janitors@vger.kernel.org From: SF Markus Elfring Subject: [PATCH] iio/light/max44000: Use common error handling code in max44000_probe() Message-ID: <28854212-d360-8636-4de5-017fbee0db36@users.sourceforge.net> Date: Thu, 26 Oct 2017 10:40:12 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 Content-Language: en-GB X-Provags-ID: V03:K0:Sx0vCYVHeTJI4OY8/9anhQIPMpoZeUwHsfOufGfPJPYpwRasLlH ShHle6FxLKtZTXZDKBXgYM1iKA+MaG/+QQAUR0eeRFGRpl6tP+qj30qB1ECD8Xz2OQE1Lqp k4NUVmIW/4GVGu0l9opYlFUVjxs3dTNTaCEYc4rIc2AiULDiUEPJouXlb1UK54YECbI3ccY ey95F1jzrAbJXUCvDJrDg== X-UI-Out-Filterresults: notjunk:1; V01:K0:I0SCKsQrsWc=:GO8bzlE8nMyzxbICqNlN8W M4BGSTJ44tzxfAh4STpdV1343LYJ2WLcn9X8QHXFaKbZSqWGGkvMxzBe954EUIqb9o24LScC1 ubSm8jBW/LootNLfZc+tl445a7F7dRhnO51lPeqOg9zrIPHga+EMJCCnXOmBOFKaGPkxGOOw9 wThWaABfXYwayS4DtFmJ9JL5khfPQgDiE3XjBAXi+3U4SUoYq/WdM4PCDMillov9acMTVVPOF AfOBVymj6t2e9BnGMm4yPKvEAAu5SaXRywk7E3azsbxZ7icblWkC7163WfAyZk38ASwX9tJfB xyh9vkSDy3N9MYKJ+7+5CeR9gYlJC0njter7j4AgS9ruCpc/rq0pHnfp7ljT7K5sQgzsuiVHR +yu8CECm9uy5WzLGWbkNutIL0I/PBZY7eYvP9iwurGAKA0gdg5K4vlgsdpVklX33sDylcYfrD NgQpbG8fbES/D9vUea6nyIr+0cezTtvQkjY596osFhYIjkwbuX6J11i8owo3R1kbrMzq+gkhl Xhzh6aSq9dBLoa4aXwufcaSlKDuAZ18m/WJOyNVWgZwZnuZzwOFotjdMQ0RRMImevwPTC2FV+ vsd2oyU+peornk5P19a6pH3foGEydfFk4ZUSIyi9ar33Kl0nPq7GJLLVVQMhALLdViMl2kvmt hzui2jJlu8K3edeqP8dSEJC05Rgm7CQkxAmnF5Wj1IJ2OF83fBiBAfp5BpmvVmOMnF3TUqX0Y DXcuwdetjMGVRUN2aoqgPvkVJqE9wT88xnRb36OKVr/2EgYglMeUdo6qob8fYVIbCJZ3qtuoB 8zwv4bi++1PtDpFDy3fOYCw1GoO8AIh9cGY+KAhc7s6lIpqCMU= Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Markus Elfring Date: Thu, 26 Oct 2017 10:30:57 +0200 * 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. * Adjust condition checks. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring --- drivers/iio/light/max44000.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/iio/light/max44000.c b/drivers/iio/light/max44000.c index bcdb0eb9e537..8f4bc6a918d5 100644 --- a/drivers/iio/light/max44000.c +++ b/drivers/iio/light/max44000.c @@ -569,18 +569,14 @@ static int max44000_probe(struct i2c_client *client, * Set a middle value so that we get some sort of valid data by default. */ ret = max44000_write_led_current_raw(data, MAX44000_LED_CURRENT_DEFAULT); - if (ret < 0) { - dev_err(&client->dev, "failed to write init config: %d\n", ret); - return ret; - } + if (ret) + goto report_failure; /* Reset CFG bits to ALS_PRX mode which allows easy reading of both values. */ reg = MAX44000_CFG_TRIM | MAX44000_CFG_MODE_ALS_PRX; ret = regmap_write(data->regmap, MAX44000_REG_CFG_MAIN, reg); - if (ret < 0) { - dev_err(&client->dev, "failed to write init config: %d\n", ret); - return ret; - } + if (ret) + goto report_failure; /* Read status at least once to clear any stale interrupt bits. */ ret = regmap_read(data->regmap, MAX44000_REG_STATUS, ®); @@ -596,6 +592,10 @@ static int max44000_probe(struct i2c_client *client, } return iio_device_register(indio_dev); + +report_failure: + dev_err(&client->dev, "failed to write init config: %d\n", ret); + return ret; } static int max44000_remove(struct i2c_client *client)