From patchwork Wed Jun 14 06:12:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Binoy Jayan X-Patchwork-Id: 9785505 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 BE62A60325 for ; Wed, 14 Jun 2017 06:12:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AF29A2853F for ; Wed, 14 Jun 2017 06:12:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A3BEA28585; Wed, 14 Jun 2017 06:12:29 +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_SIGNED, 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 118542853F for ; Wed, 14 Jun 2017 06:12:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750771AbdFNGM2 (ORCPT ); Wed, 14 Jun 2017 02:12:28 -0400 Received: from mail-pf0-f174.google.com ([209.85.192.174]:32799 "EHLO mail-pf0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750757AbdFNGM1 (ORCPT ); Wed, 14 Jun 2017 02:12:27 -0400 Received: by mail-pf0-f174.google.com with SMTP id 83so79070044pfr.0 for ; Tue, 13 Jun 2017 23:12:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=P5ALnik2YcmbtGPmtBSZQYrNsYpRWl6upc3+Ad1PMXs=; b=bUKTfuc90F++VViMPRDWBlVOByem5d8cI9xDq0J+KrEO9fHgGT5PTs1UDuV7WiJTZU oQSj00pHmeBHZHTOzrNFH+4Dokd8EwCkplez90U5A9jYzSw/UY1PQdSbwoHpOHvOP/fr t0+XARO3OxWvkEjqCe0748eAgTQrkeqcbWh/A= 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; bh=P5ALnik2YcmbtGPmtBSZQYrNsYpRWl6upc3+Ad1PMXs=; b=OVEDeRG5AxkENMhMTzL5QotniraZQnbwYoyDwQZgZV1Q2D7kAMGXWhAA9bKNBHWSC/ y8O51m5jvECfEVwtuVWTnWotiTc76zX18Sca9/p2n1Q92kQlKIqxeBE163blIvm1cC+p mx0DX8oWfRiOlMTTwQqmYpu6QUZ/ioQfYv8aOYMsGKFIYGintNsXu5SKxlCmhyujHXQo mrq4/61wcTSHSYknMPRFNTn5QMIPc5FE5BYRsjpg8YZqexeaQvLqcZTxJRFWSUC6zrbm IQwBGR2d5f/HaJIDc46peleMtufxLsoGw8oBfHzHXUzjnSzNjPZHRMOB+p2OxcaVxzgt hekg== X-Gm-Message-State: AKS2vOw7047xtvOqJzodyolquMplD60QtMUdh9sGTQieoCoBvx+gBOfM FNtbUaVBIJcdkWwU X-Received: by 10.98.155.18 with SMTP id r18mr2607697pfd.198.1497420746338; Tue, 13 Jun 2017 23:12:26 -0700 (PDT) Received: from blr-ubuntu-59.ap.qualcomm.com (blr-bdr-fw-01_globalnat_allzones-outside.qualcomm.com. [103.229.18.19]) by smtp.gmail.com with ESMTPSA id p8sm2602535pgd.23.2017.06.13.23.12.22 (version=TLS1_1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 13 Jun 2017 23:12:25 -0700 (PDT) From: Binoy Jayan To: Binoy Jayan Cc: linux-kernel@vger.kernel.org, linux-input@vger.kernel.org, Arnd Bergmann , Rajendra , Mark Brown , Jiri Kosina , Benjamin Tissoires , David Herrmann , Andrew de los Reyes Subject: [PATCH v3] HID: Replace semaphore driver_lock with mutex Date: Wed, 14 Jun 2017 11:42:20 +0530 Message-Id: <1497420740-5133-1-git-send-email-binoy.jayan@linaro.org> X-Mailer: git-send-email 1.9.1 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 semaphore 'driver_lock' is used as a simple mutex, and also unnecessary as suggested by Arnd. Hence removing it, as the concurrency between the probe and remove is already handled in the driver core. Suggested-by: Arnd Bergmann Signed-off-by: Binoy Jayan Acked-by: Benjamin Tissoires Reviewed-by: David Herrmann --- v2 --> v3: Removed reference to driver_lock in comments v1 --> v2: Removed driver_lock drivers/hid/hid-core.c | 15 ++++----------- include/linux/hid.h | 3 +-- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c index 04cee65..559533b 100644 --- a/drivers/hid/hid-core.c +++ b/drivers/hid/hid-core.c @@ -2225,11 +2225,9 @@ static int hid_device_probe(struct device *dev) const struct hid_device_id *id; int ret = 0; - if (down_interruptible(&hdev->driver_lock)) - return -EINTR; if (down_interruptible(&hdev->driver_input_lock)) { ret = -EINTR; - goto unlock_driver_lock; + goto end; } hdev->io_started = false; @@ -2256,8 +2254,7 @@ static int hid_device_probe(struct device *dev) unlock: if (!hdev->io_started) up(&hdev->driver_input_lock); -unlock_driver_lock: - up(&hdev->driver_lock); +end: return ret; } @@ -2267,11 +2264,9 @@ static int hid_device_remove(struct device *dev) struct hid_driver *hdrv; int ret = 0; - if (down_interruptible(&hdev->driver_lock)) - return -EINTR; if (down_interruptible(&hdev->driver_input_lock)) { ret = -EINTR; - goto unlock_driver_lock; + goto end; } hdev->io_started = false; @@ -2287,8 +2282,7 @@ static int hid_device_remove(struct device *dev) if (!hdev->io_started) up(&hdev->driver_input_lock); -unlock_driver_lock: - up(&hdev->driver_lock); +end: return ret; } @@ -2745,7 +2739,6 @@ struct hid_device *hid_allocate_device(void) init_waitqueue_head(&hdev->debug_wait); INIT_LIST_HEAD(&hdev->debug_list); spin_lock_init(&hdev->debug_list_lock); - sema_init(&hdev->driver_lock, 1); sema_init(&hdev->driver_input_lock, 1); return hdev; diff --git a/include/linux/hid.h b/include/linux/hid.h index 5be325d..a49203f 100644 --- a/include/linux/hid.h +++ b/include/linux/hid.h @@ -516,7 +516,6 @@ struct hid_device { /* device report descriptor */ struct hid_report_enum report_enum[HID_REPORT_TYPES]; struct work_struct led_work; /* delayed LED worker */ - struct semaphore driver_lock; /* protects the current driver, except during input */ struct semaphore driver_input_lock; /* protects the current driver */ struct device dev; /* device */ struct hid_driver *driver; @@ -538,7 +537,7 @@ struct hid_device { /* device report descriptor */ unsigned int status; /* see STAT flags above */ unsigned claimed; /* Claimed by hidinput, hiddev? */ unsigned quirks; /* Various quirks the device can pull on us */ - bool io_started; /* Protected by driver_lock. If IO has started */ + bool io_started; /* If IO has started */ struct list_head inputs; /* The list of inputs */ void *hiddev; /* The hiddev structure */