From patchwork Mon Mar 12 21:23:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SF Markus Elfring X-Patchwork-Id: 10277507 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 C561C601A0 for ; Mon, 12 Mar 2018 21:24:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B507628E58 for ; Mon, 12 Mar 2018 21:24:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A74B628E6F; Mon, 12 Mar 2018 21:24:28 +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 3331428E58 for ; Mon, 12 Mar 2018 21:24:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932282AbeCLVY1 (ORCPT ); Mon, 12 Mar 2018 17:24:27 -0400 Received: from mout.web.de ([212.227.15.14]:58991 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932242AbeCLVY0 (ORCPT ); Mon, 12 Mar 2018 17:24:26 -0400 Received: from [192.168.1.2] ([92.228.18.148]) by smtp.web.de (mrweb004 [213.165.67.108]) with ESMTPSA (Nemesis) id 0MWNHW-1fAFYT0vN4-00XeZD; Mon, 12 Mar 2018 22:23:27 +0100 To: linux-hwmon@vger.kernel.org, =?UTF-8?B?R8O8bnRlciBSw7Zjaw==?= , Hans de Goede , Jean Delvare Cc: LKML , kernel-janitors@vger.kernel.org From: SF Markus Elfring Subject: [PATCH] hwmon/sch5627: Use common error handling code in sch5627_probe() Message-ID: Date: Mon, 12 Mar 2018 22:23:24 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 Content-Language: en-GB X-Provags-ID: V03:K0:eKzn5tQ3ENssiGqYxr9iLnZDYcuahNmJdEyZrKaGGfK7IMLIxei eYnYHh+fLYdvvyIUsLpv/4Y5LtEjjakkAJDFF9NnTNOPNZ2VwpNIpgiFFAnQeKvJZo2LyvN 7X5Yp2HEdGO8KmPEBQroGUO17v+9MalfJ/O7Uvpj++GcDjfwklvHgBYNMPWg87g7VxAvvGQ hE19FKkDalaWt39PYLRDg== X-UI-Out-Filterresults: notjunk:1; V01:K0:Bs2zJmmVUBs=:uSbtVXX9vOA43ZhUsyXHzL 7O4+XQCaPUAxiEALeU3gAaB1kqNJtpdYKf+1ogN+S76gCrx2jXR0HMeOPXJFbXifPWx/LmW4Y dnjP1sVpMbTeAzywIRMO9ogVN/ThJuCy0vSLkLwLYdpfCa8Z00fA57csaRBIvvK0Eokv4Pmko lAlg/cyekZ2QhwPRnVRvuiKP7aAd7p+/wOlkEvajrf9Gh2+fo0dkGxzSgyAZuN5dCFWewe5H6 OXNiRM1gLZNecKSQrkliLd5CW1cy+ZHx8THL8PU2SbckxoEnUQLLXhBMa2/r75l/VDTSl6xD9 C7Q0hKO/9AgEg1fy+b2iGghZrSI67mWvpLBaEm5DoAiLh1Hw24DrrHsyqQcR6V2heqH+gKDko BXlXdas00tcFA0KuIkxll645C7Fd7Us3j9ww87NZtzzLYk9sYAiobokfmskQOlMXlDRXlc2zH 7APZ4F+HR87GZqTHNMr5skKQnATLVvldF1HLDZkxXVmndxm+buTxUz56AeNlY1v6q8Ixf20iE ieD8TzEZwTcl4lRp3Sa/iQ3tzrfQGI2t/TlfG5Zea7Q34iqKhpzMc/veEzryFP5Xj3GbnngLJ /RWl6xB9XccIE74UNMy6/mVB9nwyVOMV+kr5QIvnWV7QeN9ZXm6gpi1VkhTGX8z5lGUq6cPmq ioh01ps/f3i/5Pm3UzsB8noR5JoxSQKFyNksOIZPOjIH8Csymnc5oCP4x6kbPL1zqADA2Vl3R tCgk/g27BeU9VOLeWopy1XzhdJP0d2OJIRABt0qo4HxBpxycoAR4zDyJoK4+WAtHD+ipjEbL4 nW5jeuRYXbUA8DSkln/9F42yc0WGx5STuj8NNlTo33MeMYUPTk= 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: Mon, 12 Mar 2018 22:15:59 +0100 Adjust 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. Signed-off-by: Markus Elfring --- drivers/hwmon/sch5627.c | 60 ++++++++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 31 deletions(-) diff --git a/drivers/hwmon/sch5627.c b/drivers/hwmon/sch5627.c index 91544f2312e6..e7a2a974ab74 100644 --- a/drivers/hwmon/sch5627.c +++ b/drivers/hwmon/sch5627.c @@ -480,72 +480,64 @@ static int sch5627_probe(struct platform_device *pdev) platform_set_drvdata(pdev, data); val = sch56xx_read_virtual_reg(data->addr, SCH5627_REG_HWMON_ID); - if (val < 0) { - err = val; - goto error; - } + if (val < 0) + goto set_error_code; + if (val != SCH5627_HWMON_ID) { pr_err("invalid %s id: 0x%02X (expected 0x%02X)\n", "hwmon", val, SCH5627_HWMON_ID); - err = -ENODEV; - goto error; + goto e_nodev; } val = sch56xx_read_virtual_reg(data->addr, SCH5627_REG_COMPANY_ID); - if (val < 0) { - err = val; - goto error; - } + if (val < 0) + goto set_error_code; + if (val != SCH5627_COMPANY_ID) { pr_err("invalid %s id: 0x%02X (expected 0x%02X)\n", "company", val, SCH5627_COMPANY_ID); - err = -ENODEV; - goto error; + goto e_nodev; } val = sch56xx_read_virtual_reg(data->addr, SCH5627_REG_PRIMARY_ID); - if (val < 0) { - err = val; - goto error; - } + if (val < 0) + goto set_error_code; + if (val != SCH5627_PRIMARY_ID) { pr_err("invalid %s id: 0x%02X (expected 0x%02X)\n", "primary", val, SCH5627_PRIMARY_ID); - err = -ENODEV; - goto error; + goto e_nodev; } build_code = sch56xx_read_virtual_reg(data->addr, SCH5627_REG_BUILD_CODE); if (build_code < 0) { err = build_code; - goto error; + goto remove_device; } build_id = sch56xx_read_virtual_reg16(data->addr, SCH5627_REG_BUILD_ID); if (build_id < 0) { err = build_id; - goto error; + goto remove_device; } hwmon_rev = sch56xx_read_virtual_reg(data->addr, SCH5627_REG_HWMON_REV); if (hwmon_rev < 0) { err = hwmon_rev; - goto error; + goto remove_device; } val = sch56xx_read_virtual_reg(data->addr, SCH5627_REG_CTRL); - if (val < 0) { - err = val; - goto error; - } + if (val < 0) + goto set_error_code; + data->control = val; if (!(data->control & 0x01)) { pr_err("hardware monitoring not enabled\n"); - err = -ENODEV; - goto error; + goto e_nodev; } /* Trigger a Vbat voltage measurement, so that we get a valid reading the first time we read Vbat */ @@ -559,7 +551,7 @@ static int sch5627_probe(struct platform_device *pdev) */ err = sch5627_read_limits(data); if (err) - goto error; + goto remove_device; pr_info("found %s chip at %#hx\n", DEVNAME, data->addr); pr_info("firmware build: code 0x%02X, id 0x%04X, hwmon: rev 0x%02X\n", @@ -568,13 +560,13 @@ static int sch5627_probe(struct platform_device *pdev) /* Register sysfs interface files */ err = sysfs_create_group(&pdev->dev.kobj, &sch5627_group); if (err) - goto error; + goto remove_device; data->hwmon_dev = hwmon_device_register(&pdev->dev); if (IS_ERR(data->hwmon_dev)) { err = PTR_ERR(data->hwmon_dev); data->hwmon_dev = NULL; - goto error; + goto remove_device; } /* Note failing to register the watchdog is not a fatal error */ @@ -584,7 +576,13 @@ static int sch5627_probe(struct platform_device *pdev) return 0; -error: +set_error_code: + err = val; + goto remove_device; + +e_nodev: + err = -ENODEV; +remove_device: sch5627_remove(pdev); return err; }