From patchwork Sat Oct 3 09:24:57 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudip Mukherjee X-Patchwork-Id: 7320531 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 19F309F302 for ; Sat, 3 Oct 2015 09:26:01 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 32DF12066C for ; Sat, 3 Oct 2015 09:26:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3C548207A2 for ; Sat, 3 Oct 2015 09:25:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752059AbbJCJZf (ORCPT ); Sat, 3 Oct 2015 05:25:35 -0400 Received: from mail-pa0-f44.google.com ([209.85.220.44]:35570 "EHLO mail-pa0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752007AbbJCJZM (ORCPT ); Sat, 3 Oct 2015 05:25:12 -0400 Received: by pacfv12 with SMTP id fv12so131088329pac.2; Sat, 03 Oct 2015 02:25:12 -0700 (PDT) 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=d5faHU1WvvMmSzLwbHLhDeELLoer4C5voYHPV3wK9Bo=; b=lGtcKm9msbHlUVAUMKm3ytlwYU2nZZk5us00TFV9PcPlSydBEvOiHPX+gMwBWcPtwL nW8nMAVrYEvFZcx9qahfy53IWWnls1IetXEiu/U79sNBXbhA7Zr0hS2bpyJf8JUusbc3 4JDAYc3PMqCWxcJZuD9vxURZTE7ZqZ1l43TCThQ8ReYr0roNIXce34eWmf7R2Ik03/Mx JajUx2/MvMgfobafIDPzo7WRx4JI/TY1SgOiBVyP3BvhxUmvTMCkw0P4QeF3ysQRrFwE WkDW9AWenXKdBpR1wjWYItnh/jBkdJ2G3ecJPy+/Z9nebmxdBjMX4XqJwGDX+HBq7tA8 BIMQ== X-Received: by 10.68.135.136 with SMTP id ps8mr25765601pbb.123.1443864312223; Sat, 03 Oct 2015 02:25:12 -0700 (PDT) Received: from localhost.localdomain ([122.175.61.48]) by smtp.gmail.com with ESMTPSA id ej3sm16386299pbd.13.2015.10.03.02.25.09 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 03 Oct 2015 02:25:11 -0700 (PDT) From: Sudip Mukherjee To: Dmitry Torokhov Cc: linux-kernel@vger.kernel.org, linux-input@vger.kernel.org, Sudip Mukherjee , Dan Carpenter Subject: [PATCH v2 2/3] Input: gamecon - store object at correct index Date: Sat, 3 Oct 2015 14:54:57 +0530 Message-Id: <1443864298-20950-2-git-send-email-sudipm.mukherjee@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1443864298-20950-1-git-send-email-sudipm.mukherjee@gmail.com> References: <1443864298-20950-1-git-send-email-sudipm.mukherjee@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=ham 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 The variable i is used to check the port to attach to and we are supposed to save the reference of struct gc in the location given by gc_base[i]. But after finding out the index, i is getting modified again so we saved in a wrong index. Reported-by: Dan Carpenter Fixes: a517e87c3dfc ("Input: gamecon - use parallel port device model") Signed-off-by: Sudip Mukherjee --- drivers/input/joystick/gamecon.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/drivers/input/joystick/gamecon.c b/drivers/input/joystick/gamecon.c index 394ccbe..5a672dc 100644 --- a/drivers/input/joystick/gamecon.c +++ b/drivers/input/joystick/gamecon.c @@ -931,29 +931,30 @@ static void gc_attach(struct parport *pp) { struct gc *gc; struct pardevice *pd; - int i; + int i, port_idx; int count = 0; int *pads, n_pads; struct pardev_cb gc_parport_cb; - for (i = 0; i < GC_MAX_PORTS; i++) { - if (gc_cfg[i].nargs == 0 || gc_cfg[i].args[0] < 0) + for (port_idx = 0; port_idx < GC_MAX_PORTS; port_idx++) { + if (gc_cfg[port_idx].nargs == 0 || gc_cfg[port_idx].args[0] < 0) continue; - if (gc_cfg[i].args[0] == pp->number) + if (gc_cfg[port_idx].args[0] == pp->number) break; } - if (i == GC_MAX_PORTS) { + if (port_idx == GC_MAX_PORTS) { pr_debug("Not using parport%d.\n", pp->number); return; } - pads = gc_cfg[i].args + 1; - n_pads = gc_cfg[i].nargs - 1; + pads = gc_cfg[port_idx].args + 1; + n_pads = gc_cfg[port_idx].nargs - 1; gc_parport_cb.flags = PARPORT_FLAG_EXCL; - pd = parport_register_dev_model(pp, "gamecon", &gc_parport_cb, i); + pd = parport_register_dev_model(pp, "gamecon", &gc_parport_cb, + port_idx); if (!pd) { pr_err("parport busy already - lp.o loaded?\n"); return; @@ -985,7 +986,7 @@ static void gc_attach(struct parport *pp) goto err_free_gc; } - gc_base[i] = gc; + gc_base[port_idx] = gc; return; err_unreg_devs: