From patchwork Tue Oct 24 20:10:13 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: 10025475 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 8FF2560245 for ; Tue, 24 Oct 2017 20:11:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7AC1B28A76 for ; Tue, 24 Oct 2017 20:11:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6E72728A78; Tue, 24 Oct 2017 20:11:09 +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 E953E28A76 for ; Tue, 24 Oct 2017 20:11:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751477AbdJXULI (ORCPT ); Tue, 24 Oct 2017 16:11:08 -0400 Received: from mout.web.de ([217.72.192.78]:49915 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751323AbdJXULH (ORCPT ); Tue, 24 Oct 2017 16:11:07 -0400 Received: from [192.168.1.2] ([92.227.117.134]) by smtp.web.de (mrweb101 [213.165.67.124]) with ESMTPSA (Nemesis) id 0LzsKN-1dB0zT42nj-0151H7; Tue, 24 Oct 2017 22:10:17 +0200 To: linux-hwmon@vger.kernel.org, =?UTF-8?B?R8O8bnRlciBSw7Zjaw==?= , Jean Delvare Cc: LKML , kernel-janitors@vger.kernel.org From: SF Markus Elfring Subject: [PATCH] hwmon/amc6821: Use common error handling code in amc6821_init_client() Message-ID: <8cc80503-aa2b-bb5e-ab40-fa31b401b6a2@users.sourceforge.net> Date: Tue, 24 Oct 2017 22:10:13 +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:0nYAtjz7F88/aURwU/hIQmYe1fXJuia/glSDUuwq4VjNWfbVgg1 SvaEHuyHIHmeu+ikisS4APD9JkKWOPEvelixRv96JHUmUW9lbfi7fQBc8ZryuAk3yFUCIJ4 XX0sWLxm+lI8KYO0LbaCBmXs6o8ec+gArNTsfho/OCQj66In4XywK+0IIAR0rg3gxYTYPOS 3Y/7X2cF+Z/2Z4yklT3BQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:FNWBpyEO7eA=:pYaNz30lz9pKDNhjM/2ZNH 8fhZSCNT/wJAMC7dvZjj8SZSB0hP3sYk9gxhVvOSwI1ZDHv1vLNZLE/g1Bc6xbwQuEK501K6E nAVhwm+mnzxbfxDfMWUi9LhUkIStARuverU8kQZ7UWEPYrgnnvmVSjdOXScmGXERN8k0OrH0P e51vn14ZYL3SULbpKL3AM3pJH+ryNwpH8L5HH6jxhKpldEMj8FqNFizXOFsRV53I8tGMl/1Nm 4YwdmdrYcFs9LS+R6CmtW/Xm7G1XG/UaZ1IWy06KHeBFUyiyJUPTeLCgf4iYI/pPe/CFhk3ZU wPVsRiaQmRhZYi0fTnJxbavVWdphba7fvPsTOCpY5cjWP7T26yhyshWgdDzMGBFZFNkmcu/Zv G34ZE3fPrTvw9aqV6IlPl/Y/BLk4kmuTnQhLwDOXzWgmSiLAh/9mn5EachTv4gCtEPyRLbVhf W9y84VdHTlxHCHSNJztps7bWEg4YOpqUXJSASGqkJEotYP2eV9uaAfDc0wRJboumy0jBa2+Ig RtYM9/VnorjPhSdelAJRIHMvGk7NMxOQ3EvV+7DkS1e2/NzyLmu5AT6myB1e7DjNJCPpWcptw 3T1xKh7ilZgia/HAzyBZmGEOH7Wy5vv7jXpwC6C/TrLpo2YqXbICC7SDCBuiaSc80anyCRLFO /FvorDF0eX2Ap79HDoBQyJFRv9wczlKL4zRrjsVcSkyI30smjayh4fm8tbApXCO6KlZ4zw+yL XLTH6tFcvw22CZlNBsCinsXIi3sDyn/AqoW5qoHyaDoYX6Jee93MA+B5EvEGlBiSvqdpuoHtJ kLBnmkplUb8WMMFZG550w5HCtnwOriBl86ulNJ61m6HHwD7Lyg= Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Markus Elfring Date: Tue, 24 Oct 2017 22:04:20 +0200 * Add two jump targets so that a bit of exception handling can be better reused at the end of this function. This issue was detected by using the Coccinelle software. * Delete the local variable "err" which became unnecessary with this refactoring. Signed-off-by: Markus Elfring --- drivers/hwmon/amc6821.c | 77 ++++++++++++++++++------------------------------- 1 file changed, 28 insertions(+), 49 deletions(-) diff --git a/drivers/hwmon/amc6821.c b/drivers/hwmon/amc6821.c index 46b4e35fd555..5c067de3fdcf 100644 --- a/drivers/hwmon/amc6821.c +++ b/drivers/hwmon/amc6821.c @@ -885,70 +885,42 @@ static int amc6821_detect( static int amc6821_init_client(struct i2c_client *client) { int config; - int err = -EIO; if (init) { config = i2c_smbus_read_byte_data(client, AMC6821_REG_CONF4); - - if (config < 0) { - dev_err(&client->dev, - "Error reading configuration register, aborting.\n"); - return err; - } + if (config < 0) + goto report_read_failure; config |= AMC6821_CONF4_MODE; - if (i2c_smbus_write_byte_data(client, AMC6821_REG_CONF4, - config)) { - dev_err(&client->dev, - "Configuration register write error, aborting.\n"); - return err; - } + config)) + goto report_write_failure; config = i2c_smbus_read_byte_data(client, AMC6821_REG_CONF3); - - if (config < 0) { - dev_err(&client->dev, - "Error reading configuration register, aborting.\n"); - return err; - } + if (config < 0) + goto report_read_failure; dev_info(&client->dev, "Revision %d\n", config & 0x0f); config &= ~AMC6821_CONF3_THERM_FAN_EN; - if (i2c_smbus_write_byte_data(client, AMC6821_REG_CONF3, - config)) { - dev_err(&client->dev, - "Configuration register write error, aborting.\n"); - return err; - } + config)) + goto report_write_failure; config = i2c_smbus_read_byte_data(client, AMC6821_REG_CONF2); - - if (config < 0) { - dev_err(&client->dev, - "Error reading configuration register, aborting.\n"); - return err; - } + if (config < 0) + goto report_read_failure; config &= ~AMC6821_CONF2_RTFIE; config &= ~AMC6821_CONF2_LTOIE; config &= ~AMC6821_CONF2_RTOIE; - if (i2c_smbus_write_byte_data(client, - AMC6821_REG_CONF2, config)) { - dev_err(&client->dev, - "Configuration register write error, aborting.\n"); - return err; - } + if (i2c_smbus_write_byte_data(client, AMC6821_REG_CONF2, + config)) + goto report_write_failure; config = i2c_smbus_read_byte_data(client, AMC6821_REG_CONF1); - - if (config < 0) { - dev_err(&client->dev, - "Error reading configuration register, aborting.\n"); - return err; - } + if (config < 0) + goto report_read_failure; config &= ~AMC6821_CONF1_THERMOVIE; config &= ~AMC6821_CONF1_FANIE; @@ -958,14 +930,21 @@ static int amc6821_init_client(struct i2c_client *client) else config &= ~AMC6821_CONF1_PWMINV; - if (i2c_smbus_write_byte_data( - client, AMC6821_REG_CONF1, config)) { - dev_err(&client->dev, - "Configuration register write error, aborting.\n"); - return err; - } + if (i2c_smbus_write_byte_data(client, AMC6821_REG_CONF1, + config)) + goto report_write_failure; } return 0; + +report_read_failure: + dev_err(&client->dev, + "Error reading configuration register, aborting.\n"); + return -EIO; + +report_write_failure: + dev_err(&client->dev, + "Configuration register write error, aborting.\n"); + return -EIO; } static int amc6821_probe(struct i2c_client *client,