From patchwork Wed Jun 14 07:29:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Binoy Jayan X-Patchwork-Id: 9785555 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 7713C602C9 for ; Wed, 14 Jun 2017 07:30:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6530C285C8 for ; Wed, 14 Jun 2017 07:30:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 59493285E0; Wed, 14 Jun 2017 07:30:22 +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 A24BD285C8 for ; Wed, 14 Jun 2017 07:30:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754122AbdFNHaU (ORCPT ); Wed, 14 Jun 2017 03:30:20 -0400 Received: from mail-pg0-f51.google.com ([74.125.83.51]:34703 "EHLO mail-pg0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751324AbdFNHaU (ORCPT ); Wed, 14 Jun 2017 03:30:20 -0400 Received: by mail-pg0-f51.google.com with SMTP id v18so71919417pgb.1 for ; Wed, 14 Jun 2017 00:30:19 -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=qeOany88zUFXRo8EMMTOGQJNqFIsXQhrdA/jHYSOwJI=; b=Gco7hum6hvTMs2Cv6ahZnmGppLHO17lNCwbBxG2mZlGMWvb0YyYU2s/MoxBAqeOpv+ Ak6oD0AvXFT1e7MD+0m7FZslPVv62wJ6o+0GgCib9wzXkDJjRs+CNi7mwQmncs2eBgyx bD5pO6fRiL8VfYitVUc6l+0HOkqp5ekWmaXrg= 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=qeOany88zUFXRo8EMMTOGQJNqFIsXQhrdA/jHYSOwJI=; b=mLlBzOEpYy/5stdIEvO+aNUO3lTr5sGi7UDKA68M8YCjuBvo6OiJ1+2fpErnyhGrHs lroRfLs/L14VDmXwZS3MrDWdWvfy+NKXaMQA7PjtO4hsLvK1AMg7GEUz1VHOdYGmPHOj qxYrfLA4c1FLjiPz2qyx5IlNtbU59dIm8SJaAKt0Hu1RSGEyyGGVSV8V2bUDPVbntK6M sD8BDsQCb8L5Wh6MhtWerPFnMxj/6BlUEL5XFe6gZIp4bg9bH3dTPHufQPdYDAuU1VLP NRVYFLsdzwfBlXdk1N2YmCiMlwxBh4RPDdY7ExbzRhcw4VlkcsyufMbwq+H1Q6s98G5Q pZ1g== X-Gm-Message-State: AKS2vOwv/+rpmmxwHRqIvghXIRbwvADVSGRrRPyzGZo7h8Xno9uJXPJZ H8UGp2BmsKrUgzny X-Received: by 10.98.59.92 with SMTP id i89mr2910862pfa.122.1497425419275; Wed, 14 Jun 2017 00:30:19 -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 204sm374712pfu.23.2017.06.14.00.30.16 (version=TLS1_1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 14 Jun 2017 00:30:18 -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 v4] HID: Remove the semaphore driver_lock Date: Wed, 14 Jun 2017 12:59:51 +0530 Message-Id: <1497425391-7188-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 --- v3 --> v4: Changed title 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 */