From patchwork Sat Mar 25 06:04:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 9644435 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 F125A60327 for ; Sat, 25 Mar 2017 06:04:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DF5F7269DA for ; Sat, 25 Mar 2017 06:04:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D285126E4E; Sat, 25 Mar 2017 06:04:34 +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.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID 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 662A4269DA for ; Sat, 25 Mar 2017 06:04:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S967287AbdCYGE3 (ORCPT ); Sat, 25 Mar 2017 02:04:29 -0400 Received: from mail-pg0-f67.google.com ([74.125.83.67]:33495 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S967189AbdCYGES (ORCPT ); Sat, 25 Mar 2017 02:04:18 -0400 Received: by mail-pg0-f67.google.com with SMTP id 79so1735554pgf.0; Fri, 24 Mar 2017 23:04:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=jnd0Z3NSoZHG/FE2C2agdk7IuwaRyVw6TgWkwaM2XgA=; b=pXLIxlh7UTYj3mq7KfSF8KxmQ66ug6J5Yl4nPHfFJAr/DBZV/Q2noVsdFUy5p7BMCI Xxk3PbTXcfnKVciguF5qEj/BSd75y3j8xJhAl7hNxh7ABYxtlDmtF46dUkeTSr4h+a+7 nu5aGDlRVZ9/x02TY7R1XMfA51YMJzPz8J0/4xsLeDAkzaDUlR2/QXntSg/C5Gu5qS6W o92EqMthn3dQjEUUZhHRRQq4iYgUfc4vEXHtsUlhSepVYQE7ADiHxxo/Xjr+yuU5KfCb nYtJobtI54elVbDsjN56zHCHMKBRPMX3GvrKYPNYcnqgI8Fcr/Qnex6T+X3rS8l5NXtF 17yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=jnd0Z3NSoZHG/FE2C2agdk7IuwaRyVw6TgWkwaM2XgA=; b=lIl8T7fLVFCDxbQ3rj9S3O8WRyT3ks3ZaTNY3TU81W6t90/qZaxKt9BbICSgA9kQZ9 kj0YgJ8YDgN5xzP2T3hw/uphx3Rb6VmmsGj7g0qURIjsiBa+zWcZHWD6TKyOUiQ8iRql 1Ed1BgKSut1s4KvjBUiiF5F+DAhdeeVAza8LuTvOfc7O4p7ngihOGJByBgVRznQXzMa/ z73NvWxbv2VpS1txsvF23wY0oZl2d84RQnFBfsVGpowFx90FOhYR7V29x3zh4g8qK+GF KZuHoMncSTb8KWptQ8YL1eS2lM421+yXPPse96Iv/Go63Erh6Skfu3PcSmQj3cY+YwWc jxOA== X-Gm-Message-State: AFeK/H2cV02FhMiP/hjCxUzEUUqrs8Mgx3saokPZivf3gD0jrWHhRIAgadSr65EFavbWPg== X-Received: by 10.84.136.135 with SMTP id 7mr15730015pll.149.1490421852160; Fri, 24 Mar 2017 23:04:12 -0700 (PDT) Received: from dtor-ws.mtv.corp.google.com ([172.22.152.34]) by smtp.gmail.com with ESMTPSA id f3sm7940346pga.34.2017.03.24.23.04.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 24 Mar 2017 23:04:11 -0700 (PDT) From: Dmitry Torokhov To: Benjamin Tissoires Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, Andrew Duggan Subject: [PATCH 3/4] Input: synaptics - do not abuse -1 as return value Date: Fri, 24 Mar 2017 23:04:08 -0700 Message-Id: <20170325060409.40558-3-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.12.1.578.ge9c3154ca4-goog In-Reply-To: <20170325060409.40558-1-dmitry.torokhov@gmail.com> References: <20170325060409.40558-1-dmitry.torokhov@gmail.com> 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 Let's stop using -1 as a universal return value and instead propagate errors from underlying calls up the stack. Signed-off-by: Dmitry Torokhov --- drivers/input/mouse/synaptics.c | 71 ++++++++++++++++++++++++++--------------- 1 file changed, 46 insertions(+), 25 deletions(-) diff --git a/drivers/input/mouse/synaptics.c b/drivers/input/mouse/synaptics.c index be2265bc386c..224269c849bb 100644 --- a/drivers/input/mouse/synaptics.c +++ b/drivers/input/mouse/synaptics.c @@ -82,12 +82,17 @@ static int synaptics_mode_cmd(struct psmouse *psmouse, unsigned char mode) { unsigned char param[1]; + int error; + + error = psmouse_sliced_command(psmouse, mode); + if (error) + return error; - if (psmouse_sliced_command(psmouse, mode)) - return -1; param[0] = SYN_PS_SET_MODE2; - if (ps2_command(&psmouse->ps2dev, param, PSMOUSE_CMD_SETRATE)) - return -1; + error = ps2_command(&psmouse->ps2dev, param, PSMOUSE_CMD_SETRATE); + if (error) + return error; + return 0; } @@ -534,16 +539,19 @@ static int synaptics_set_advanced_gesture_mode(struct psmouse *psmouse) { static unsigned char param = 0xc8; struct synaptics_data *priv = psmouse->private; + int error; if (!(SYN_CAP_ADV_GESTURE(priv->info.ext_cap_0c) || SYN_CAP_IMAGE_SENSOR(priv->info.ext_cap_0c))) return 0; - if (psmouse_sliced_command(psmouse, SYN_QUE_MODEL)) - return -1; + error = psmouse_sliced_command(psmouse, SYN_QUE_MODEL); + if (error) + return error; - if (ps2_command(&psmouse->ps2dev, ¶m, PSMOUSE_CMD_SETRATE)) - return -1; + error = ps2_command(&psmouse->ps2dev, ¶m, PSMOUSE_CMD_SETRATE); + if (error) + return error; /* Advanced gesture mode also sends multi finger data */ priv->info.capabilities |= BIT(1); @@ -554,6 +562,7 @@ static int synaptics_set_advanced_gesture_mode(struct psmouse *psmouse) static int synaptics_set_mode(struct psmouse *psmouse) { struct synaptics_data *priv = psmouse->private; + int error; priv->mode = 0; if (priv->absolute_mode) @@ -565,13 +574,18 @@ static int synaptics_set_mode(struct psmouse *psmouse) if (SYN_CAP_EXTENDED(priv->info.capabilities)) priv->mode |= SYN_BIT_W_MODE; - if (synaptics_mode_cmd(psmouse, priv->mode)) - return -1; + error = synaptics_mode_cmd(psmouse, priv->mode); + if (error) + return error; - if (priv->absolute_mode && - synaptics_set_advanced_gesture_mode(psmouse)) { - psmouse_err(psmouse, "Advanced gesture mode init failed.\n"); - return -1; + if (priv->absolute_mode) { + error = synaptics_set_advanced_gesture_mode(psmouse); + if (error) { + psmouse_err(psmouse, + "Advanced gesture mode init failed: %d\n", + error); + return error; + } } return 0; @@ -598,12 +612,17 @@ static void synaptics_set_rate(struct psmouse *psmouse, unsigned int rate) static int synaptics_pt_write(struct serio *serio, unsigned char c) { struct psmouse *parent = serio_get_drvdata(serio->parent); - char rate_param = SYN_PS_CLIENT_CMD; /* indicates that we want pass-through port */ + u8 rate_param = SYN_PS_CLIENT_CMD; /* indicates that we want pass-through port */ + int error; + + error = psmouse_sliced_command(parent, c); + if (error) + return error; + + error = ps2_command(&parent->ps2dev, &rate_param, PSMOUSE_CMD_SETRATE); + if (error) + return error; - if (psmouse_sliced_command(parent, c)) - return -1; - if (ps2_command(&parent->ps2dev, &rate_param, PSMOUSE_CMD_SETRATE)) - return -1; return 0; } @@ -1395,19 +1414,21 @@ static int synaptics_reconnect(struct psmouse *psmouse) } while (error && ++retry < 3); if (error) - return -1; + return error; if (retry > 1) psmouse_dbg(psmouse, "reconnected after %d tries\n", retry); - if (synaptics_query_hardware(psmouse, &info)) { + error = synaptics_query_hardware(psmouse, &info); + if (error) { psmouse_err(psmouse, "Unable to query device.\n"); - return -1; + return error; } - if (synaptics_set_mode(psmouse)) { + error = synaptics_set_mode(psmouse); + if (error) { psmouse_err(psmouse, "Unable to initialize device.\n"); - return -1; + return error; } if (info.identity != priv->info.identity || @@ -1420,7 +1441,7 @@ static int synaptics_reconnect(struct psmouse *psmouse) priv->info.model_id, info.model_id, priv->info.capabilities, info.capabilities, priv->info.ext_cap, info.ext_cap); - return -1; + return -ENXIO; } return 0;