From patchwork Sun Aug 21 13:33:02 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Silvan Jegen X-Patchwork-Id: 9292155 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 3B6A060574 for ; Sun, 21 Aug 2016 13:49:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1FD4428AAA for ; Sun, 21 Aug 2016 13:49:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1244228AAB; Sun, 21 Aug 2016 13:49:41 +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.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, 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 9DE3728AA1 for ; Sun, 21 Aug 2016 13:49:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752867AbcHUNt0 (ORCPT ); Sun, 21 Aug 2016 09:49:26 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:35169 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752809AbcHUNtZ (ORCPT ); Sun, 21 Aug 2016 09:49:25 -0400 Received: by mail-wm0-f68.google.com with SMTP id i5so9744202wmg.2; Sun, 21 Aug 2016 06:48:48 -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; bh=5M8OKxnv6bJSOFFV4bzsnLqy1nbmqLV/oT8mlUgXTZs=; b=vhgzhCikOIC7SCYADXdq83GSNZp8U9l2qqSpEBdDgQ7gJg3ZM7tbme52Ih24B466ec gtBd9lL+PLLNVujESrWWdcpFh7t37fc302MILTBSeIsWy1DLd9VAj1KA6D4xOOHFQXdz sM4aswxygPLuY38DZnyD9KLTSRFl7bbi7kgj3rB+B4qIVnPmDy5Ccx0UBjn6r52rzeW4 w3M/uhxbRYgT/8uIXJjdKIezY1ExpCbc+HnrXxnDV7Ig0c4hPLn+Dz8ztmG6QwDXD+0H BXESpYq+hpVG4p84PqkIuht60rVIRnEsrOd4/MepaeTft4mRbSuOwwzO6/FZMd+Pm8LY 1iYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=5M8OKxnv6bJSOFFV4bzsnLqy1nbmqLV/oT8mlUgXTZs=; b=NiKvXYWVPDWBNgmmLV3LxACyeSB/mcmu08g4Ksb2D4pruncwcIzRmT2kCcS/LHH5Nz USRj3QzLYP2ho7REJWBt9YqLfnoAwxVYx03Yn7v0Umi+7Yyo16uZHwNVKHzigeyor9Xz VI+C4HGFqUX0wmYPlLavhrgHS+PTXOa7p/aQ4XsTONX5J5qPlXit4RQVx/WtktOXhegh lKe0zi3JPXVzyLMVn6k7yCWalGSapvf13zqR4g/Qw/kKKHxrW79sBze4H/K+ClkayXjz CUxcpFiv06blcKip4RJ/zHlIyXhNNaASjoJFcvEZY2lCi8lnqjFepqpySwYgLXtPIkLK IYyA== X-Gm-Message-State: AEkoousR4TX0sLM7iR0xMuwh5JTay+w5CbMeYoGC2L6fMEWj+sEcu5OTJrOWos5HfJ+4IA== X-Received: by 10.28.74.221 with SMTP id n90mr10964977wmi.16.1471786410978; Sun, 21 Aug 2016 06:33:30 -0700 (PDT) Received: from localhost.localdomain (217-162-180-230.dynamic.hispeed.ch. [217.162.180.230]) by smtp.gmail.com with ESMTPSA id c8sm17850987wjm.19.2016.08.21.06.33.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 21 Aug 2016 06:33:29 -0700 (PDT) From: Silvan Jegen To: Stefan Achatz , Jiri Kosina , Benjamin Tissoires Cc: Silvan Jegen , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] HID: roccat: Remove use of the "exist" field Date: Sun, 21 Aug 2016 15:33:02 +0200 Message-Id: <20160821133302.16265-1-s.jegen@gmail.com> X-Mailer: git-send-email 2.9.3 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 The "exist" field is only checked when "roccat_open" has already been called or when we have made sure that the corresponding roccat_device is not NULL. Since the value of the "open" field has been increased by the "roccat_open" call, instead of checking "exist" we can just check if "open" is equal to zero to the same effect and remove the "exist" field as well as the code that touches it. Signed-off-by: Silvan Jegen --- I have tested this patch with the only Roccat hardware I own, a Roccat Kone Pure. Testing the patch with several pieces of Roccat hardware connected at the same time would be desirable. drivers/hid/hid-roccat.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/drivers/hid/hid-roccat.c b/drivers/hid/hid-roccat.c index 76d06cf..7552a1e 100644 --- a/drivers/hid/hid-roccat.c +++ b/drivers/hid/hid-roccat.c @@ -43,7 +43,6 @@ struct roccat_device { unsigned int minor; int report_size; int open; - int exist; wait_queue_head_t wait; struct device *dev; struct hid_device *hid; @@ -99,7 +98,7 @@ static ssize_t roccat_read(struct file *file, char __user *buffer, retval = -ERESTARTSYS; break; } - if (!device->exist) { + if (device->open == 0) { retval = -EIO; break; } @@ -143,7 +142,7 @@ static unsigned int roccat_poll(struct file *file, poll_table *wait) poll_wait(file, &reader->device->wait, wait); if (reader->cbuf_start != reader->device->cbuf_end) return POLLIN | POLLRDNORM; - if (!reader->device->exist) + if (reader->device->open == 0) return POLLERR | POLLHUP; return 0; } @@ -224,13 +223,11 @@ static int roccat_release(struct inode *inode, struct file *file) kfree(reader); if (!--device->open) { - /* removing last reader */ - if (device->exist) { - hid_hw_power(device->hid, PM_HINT_NORMAL); - hid_hw_close(device->hid); - } else { - kfree(device); - } + /* we have removed the last reader */ + kfree(device); + } else { + hid_hw_power(device->hid, PM_HINT_NORMAL); + hid_hw_close(device->hid); } mutex_unlock(&devices_lock); @@ -340,7 +337,6 @@ int roccat_connect(struct class *klass, struct hid_device *hid, int report_size) mutex_init(&device->cbuf_lock); device->minor = minor; device->hid = hid; - device->exist = 1; device->cbuf_end = 0; device->report_size = report_size; @@ -359,8 +355,6 @@ void roccat_disconnect(int minor) device = devices[minor]; mutex_unlock(&devices_lock); - device->exist = 0; /* TODO exist maybe not needed */ - device_destroy(device->dev->class, MKDEV(roccat_major, minor)); mutex_lock(&devices_lock);