From patchwork Thu Oct 26 18:55:54 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: 10028697 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 89E886022E for ; Thu, 26 Oct 2017 18:56:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7C53428DDE for ; Thu, 26 Oct 2017 18:56:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 701BA28E4F; Thu, 26 Oct 2017 18:56:07 +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 0C6D028DDE for ; Thu, 26 Oct 2017 18:56:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932410AbdJZS4F (ORCPT ); Thu, 26 Oct 2017 14:56:05 -0400 Received: from mout.web.de ([217.72.192.78]:63069 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932334AbdJZS4E (ORCPT ); Thu, 26 Oct 2017 14:56:04 -0400 Received: from [192.168.1.2] ([78.48.35.118]) by smtp.web.de (mrweb102 [213.165.67.124]) with ESMTPSA (Nemesis) id 0LbrUu-1dQznI1rvA-00jMW5; Thu, 26 Oct 2017 20:56:00 +0200 To: linux-input@vger.kernel.org, Dmitry Torokhov , Fabien Marteau Cc: LKML , kernel-janitors@vger.kernel.org From: SF Markus Elfring Subject: [PATCH] Input-as5011: Use common error handling code in as5011_configure_chip() Message-ID: <18c826ed-c587-927b-87a7-9180215e60d9@users.sourceforge.net> Date: Thu, 26 Oct 2017 20:55:54 +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:/wKD2TPUZ5W9LYULfEOPv7uyHAEKZSklb4G1sWy5r7bQ5nI8ZPa W/M+SnoMdE1PoLHAf5E4JJI4plQ1AhgS4cfKH2XZew5ezJYU5OjjWFzyNEdZmRZmbdr9M3R 01dyoeEe/wDwpdJxjc0rR57xOZnIgTMt3OWM9N6LiTvwNPpzfF4/tyT3BT3s+fq0OgpfHt8 LDXjJDDhO47vdvB6jKIeA== X-UI-Out-Filterresults: notjunk:1; V01:K0:KZiy8MYf9Zg=:40ZvoFKwhdNXthisdpdstr 7VAab6YDaSiaV2dWny2GoSsheXvWAL5iiiJxgajWGycJ1qeTkmQ/xUrOD/WKjthuogp8177sC xK9hnsOnNzFXSFj9o5QBTOfRYobtc1eE1m3DeNuCEQVqxrBTJVvoi9Y1EtcmTaIf/B/Z2Oy/Y QcednZxQoO5FsjilAtS4dVUAQqT2Ogx4pZmzgTQ+UCh8T5qc2/sPGU62f8Zgo1vbJ6aZ3LY7g gDbuSRC6l0bim/TKfmFg7qZ1HJcHKb5yHyLuu5stlxp7NrHQMJhqJgiHVCaZi7M6TFIJjDol0 V1QL9dE1420ut504xbFR1yNt17uuualIULJt8pu50a/VliSyYdFau/Z/v5K5q2flHKZJ9TV3d 1rvSgbtRH/6//5kjTM47RAxaZKpqW/Mli2//TXGI/Lyoq3GYxXVQTgHGgDaiRZPl/N/vGI9SD OGPauYmyfk2lgbtnvlybMy0RvcOsiTOBiiYToRW9qwsWSrHAYqRynSQbmcX50c3SLGS4qUHY5 eM4ZBH9+ZUON69qxtdUCmTPSczN0zy1rtrD3yvFFI7ZrT3afztDvGGTbdxcSaO4LUeptNfzdJ ZhlwWXERkPJENV6+AGH2jE3WWoiQsPTLhgZ0K5FJLDcXHKi9iNAequPBI56Xnj71+9LXJHkLy tlSng0AwZnFzoehH7rSiQWzjerR9cslh0nqD87atGD5tjx4iDcadTJXUyBeWOdcvqv+WS7Dl4 HlSd0xOaUrKNUNjRyah/LoBbdtmffT+oDQoMBtAfM1gZtzeWJGPTWko1gqaZ3n8TlZ6qa1hqT 2ZVKw4FzusmyjwQIWXTuFe8np4LaKTo2NRDfTIL0I8pI2HEpqg= Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Markus Elfring Date: Thu, 26 Oct 2017 20:48:49 +0200 Add a jump target so that a specific error message is stored only once at the end of this function implementation. Replace four calls of the function "dev_err" by goto statements. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring --- drivers/input/joystick/as5011.c | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/drivers/input/joystick/as5011.c b/drivers/input/joystick/as5011.c index 005d852a06e9..1858ebec020a 100644 --- a/drivers/input/joystick/as5011.c +++ b/drivers/input/joystick/as5011.c @@ -192,28 +192,20 @@ static int as5011_configure_chip(struct as5011_device *as5011, /* write threshold */ error = as5011_i2c_write(client, AS5011_XP, plat_dat->xp); - if (error < 0) { - dev_err(&client->dev, "Can't write threshold\n"); - return error; - } + if (error < 0) + goto report_write_failure; error = as5011_i2c_write(client, AS5011_XN, plat_dat->xn); - if (error < 0) { - dev_err(&client->dev, "Can't write threshold\n"); - return error; - } + if (error < 0) + goto report_write_failure; error = as5011_i2c_write(client, AS5011_YP, plat_dat->yp); - if (error < 0) { - dev_err(&client->dev, "Can't write threshold\n"); - return error; - } + if (error < 0) + goto report_write_failure; error = as5011_i2c_write(client, AS5011_YN, plat_dat->yn); - if (error < 0) { - dev_err(&client->dev, "Can't write threshold\n"); - return error; - } + if (error < 0) + goto report_write_failure; /* to free irq gpio in chip */ error = as5011_i2c_read(client, AS5011_X_RES_INT, &value); @@ -223,6 +215,10 @@ static int as5011_configure_chip(struct as5011_device *as5011, } return 0; + +report_write_failure: + dev_err(&client->dev, "Can't write threshold\n"); + return error; } static int as5011_probe(struct i2c_client *client,