From patchwork Sun Nov 29 05:13:51 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 7717961 Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id CAE449F3CD for ; Sun, 29 Nov 2015 05:16:04 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E7F872055C for ; Sun, 29 Nov 2015 05:16:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 01FD52055B for ; Sun, 29 Nov 2015 05:16:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752045AbbK2FO6 (ORCPT ); Sun, 29 Nov 2015 00:14:58 -0500 Received: from mail-pa0-f42.google.com ([209.85.220.42]:34022 "EHLO mail-pa0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750728AbbK2FOB (ORCPT ); Sun, 29 Nov 2015 00:14:01 -0500 Received: by padhx2 with SMTP id hx2so150267574pad.1; Sat, 28 Nov 2015 21:14:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=d6bKcT2zO4nzEmSSdsjvkF1dg00xIC7P3AA5o5oWeWo=; b=PKHIRA9UqNvGehakJUvgfD3RsJa6sm8hi9CJIs2/RM4Jx6Q+zXXFk5/ZYJ41tEqKRE aUhji6/Dum5gL6uMBUizDasslWpwfm/GzaYVXnUbDCPX2vioRYw5YPgFI585YpAOFkpu owWS8U20CNpWTSQA/27E/UpsCAXiGqQd725anHF6WCbUFKt2e1c5a3yjWK4WkQUtW2X6 a8dujStwv6rbHwd5ObOUIcfZo2yUK+464Sb2mxplCXBywOjr+EV1KobVErqCzrKq8sPT 7Z/jfIJ8XfRREO72sbsE7UqevC7SxYTh5k/Tj7MzR0lHSyAt/GD48WWYl9RsYNL+izjY N2yQ== X-Received: by 10.66.55.105 with SMTP id r9mr80460079pap.137.1448774040707; Sat, 28 Nov 2015 21:14:00 -0800 (PST) Received: from dtor-ws.mtv.corp.google.com ([172.22.64.149]) by smtp.gmail.com with ESMTPSA id pb9sm43616340pac.38.2015.11.28.21.13.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 28 Nov 2015 21:13:59 -0800 (PST) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: Hans de Goede , Benjamin Tissoires , Thomas Hellstrom , pali.rohar@gmail.com, jckeerthan@gmail.com, till2.schaefer@uni-dortmund.de, linux-kernel@vger.kernel.org Subject: [PATCH 1/6] Input: psmouse - use switch statement in psmouse_process_byte() Date: Sat, 28 Nov 2015 21:13:51 -0800 Message-Id: <1448774036-39040-2-git-send-email-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.6.0.rc2.230.g3dd15c0 In-Reply-To: <1448774036-39040-1-git-send-email-dmitry.torokhov@gmail.com> References: <1448774036-39040-1-git-send-email-dmitry.torokhov@gmail.com> Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Instead of a series mostly exclusive "if" statements testing protocol type of the mouse let's use "switch" statement. Signed-off-by: Dmitry Torokhov Reviewed-by: Pali Rohár --- drivers/input/mouse/psmouse-base.c | 65 ++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 34 deletions(-) diff --git a/drivers/input/mouse/psmouse-base.c b/drivers/input/mouse/psmouse-base.c index ad18dab..4e43e7e 100644 --- a/drivers/input/mouse/psmouse-base.c +++ b/drivers/input/mouse/psmouse-base.c @@ -138,22 +138,16 @@ psmouse_ret_t psmouse_process_byte(struct psmouse *psmouse) if (psmouse->pktcnt < psmouse->pktsize) return PSMOUSE_GOOD_DATA; -/* - * Full packet accumulated, process it - */ - -/* - * Scroll wheel on IntelliMice, scroll buttons on NetMice - */ + /* Full packet accumulated, process it */ - if (psmouse->type == PSMOUSE_IMPS || psmouse->type == PSMOUSE_GENPS) + switch (psmouse->type) { + case PSMOUSE_IMPS: + /* IntelliMouse has scroll wheel */ input_report_rel(dev, REL_WHEEL, -(signed char) packet[3]); + break; -/* - * Scroll wheel and buttons on IntelliMouse Explorer - */ - - if (psmouse->type == PSMOUSE_IMEX) { + case PSMOUSE_IMEX: + /* Scroll wheel and buttons on IntelliMouse Explorer */ switch (packet[3] & 0xC0) { case 0x80: /* vertical scroll on IntelliMouse Explorer 4.0 */ input_report_rel(dev, REL_WHEEL, (int) (packet[3] & 32) - (int) (packet[3] & 31)); @@ -168,39 +162,42 @@ psmouse_ret_t psmouse_process_byte(struct psmouse *psmouse) input_report_key(dev, BTN_EXTRA, (packet[3] >> 5) & 1); break; } - } + break; -/* - * Extra buttons on Genius NewNet 3D - */ + case PSMOUSE_GENPS: + /* Report scroll buttons on NetMice */ + input_report_rel(dev, REL_WHEEL, -(signed char) packet[3]); - if (psmouse->type == PSMOUSE_GENPS) { + /* Extra buttons on Genius NewNet 3D */ input_report_key(dev, BTN_SIDE, (packet[0] >> 6) & 1); input_report_key(dev, BTN_EXTRA, (packet[0] >> 7) & 1); - } + break; -/* - * Extra button on ThinkingMouse - */ - if (psmouse->type == PSMOUSE_THINKPS) { + case PSMOUSE_THINKPS: + /* Extra button on ThinkingMouse */ input_report_key(dev, BTN_EXTRA, (packet[0] >> 3) & 1); - /* Without this bit of weirdness moving up gives wildly high Y changes. */ + + /* + * Without this bit of weirdness moving up gives wildly + * high Y changes. + */ packet[1] |= (packet[0] & 0x40) << 1; - } + break; -/* - * Cortron PS2 Trackball reports SIDE button on the 4th bit of the first - * byte. - */ - if (psmouse->type == PSMOUSE_CORTRON) { + case PSMOUSE_CORTRON: + /* + * Cortron PS2 Trackball reports SIDE button in the + * 4th bit of the first byte. + */ input_report_key(dev, BTN_SIDE, (packet[0] >> 3) & 1); packet[0] |= 0x08; - } + break; -/* - * Generic PS/2 Mouse - */ + default: + break; + } + /* Generic PS/2 Mouse */ input_report_key(dev, BTN_LEFT, packet[0] & 1); input_report_key(dev, BTN_MIDDLE, (packet[0] >> 2) & 1); input_report_key(dev, BTN_RIGHT, (packet[0] >> 1) & 1);