From patchwork Tue Jun 13 09:25:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Binoy Jayan X-Patchwork-Id: 104348 Delivered-To: patch@linaro.org Received: by 10.140.91.77 with SMTP id y71csp310868qgd; Tue, 13 Jun 2017 02:25:36 -0700 (PDT) X-Received: by 10.84.217.158 with SMTP id p30mr62210245pli.211.1497345936234; Tue, 13 Jun 2017 02:25:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1497345936; cv=none; d=google.com; s=arc-20160816; b=P0ubYBjh5qLnBDZFtWtnp9bZsEEL9Avghxa65SARzhj8U+vdEvKhkR9VXqWEPj0sSl p1o9Xxc+HaFBIKLPAotQTq4DTuzKSTs1fHV+e3Qb1Gmc3q5z8BFNrAlW2HVF8zhP2Kra lLWyy0TEhlBVGbwR8PD8qNQr859n94x2pY+280JUQOzp2kAkZlvZu+t8AgtTg2hKsouh ld8oWEZMA3c7G3J3UnkSwRAiOGnWNCZKLL9EghrRXuMkvWan3taQYIpyg1aKOqo77neX 8NgcRg2r6M5bzQznEiadDLj8YMjhpZ0Rzu3lxjKqGVHIYl56aisqPUK6IPSl2ZhbdvZ1 aT4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=HfN+8WpK0t+HElfkSbMvQKXza8WTIfJqF6faoW6B0K8=; b=IzpKR2sMGB7q7Gj57OiSr3W66Q7zvPxjotgIHRLlE8XsaY2IeexWi3HAl8WiIG0243 QsbJQdjXebftnjW0AjGfRk+QZZ2SSKUNK370fBq168zU1OVQiPWiwzEdqarxBSEgBBk4 dHMTZ1+PVn5Zvdrdf1bayWS3QtoWR3yZUZyAbFs2pFe4B2shgLK660YOc+ldX4F+PvRN gK2w+41GUTfegnP9NOxyj6uGL/1EBPjIqdoha7usEdhCjGfQzfCAHnpaKKchbz5SEboM QRAXAtjKtwXjYWDvsltW5khkQJIqSOlu+Qnw9yRUfW9FHb1Vu2MMBO5fHlhzt0Gt5gHC Uy1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e7si9070744plj.303.2017.06.13.02.25.35; Tue, 13 Jun 2017 02:25:36 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752643AbdFMJZd (ORCPT + 25 others); Tue, 13 Jun 2017 05:25:33 -0400 Received: from mail-pf0-f180.google.com ([209.85.192.180]:32768 "EHLO mail-pf0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752021AbdFMJZc (ORCPT ); Tue, 13 Jun 2017 05:25:32 -0400 Received: by mail-pf0-f180.google.com with SMTP id 83so64965400pfr.0 for ; Tue, 13 Jun 2017 02:25:31 -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=HfN+8WpK0t+HElfkSbMvQKXza8WTIfJqF6faoW6B0K8=; b=S0IHeXXZSnRtl1tfRFBwq0nqJDYDR423vNAu/F9dZ2wJ/l4zS81I8AvLlOBW6k7ZDb SgX+Ld/4NViQcbTuqaPst5WfwieOvOq3WAODswLAQJ58v0a1zxPi4pxSrjq2glnbejGN lOceIm4c5rbQhFTMdv4s3yY2sBYqm1Qoq70nI= 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=HfN+8WpK0t+HElfkSbMvQKXza8WTIfJqF6faoW6B0K8=; b=PzL1W7Ko+0iArxjjs75qDXCIBWiALVNUpMJrGrI0Nks2XOAKORKNaIYDcwaraUjMUt 81NnutTQmOlmHQJL/v7msgbcu7VeM9Rkon4ZvBDSz7J9T5EMLGQNKdkLbaF+cPousQ4F jlUGybKWJkeghK/uH23RCCtgqucZS7W7t2usxmCVK9FNL+IxP8M7dh0+RPMY0/57oKaF Mq/faUGTTSHlL+GruroHm5ktoQ/ifPchkzEVN2LO4t17L4C8hBrtocxSQ18BUsYi27eT t4LDecGAs1dzL46vOnWKKrOQi3orxS7QU4e96B3k0ZOrsqP9T8iZyECVGfSr8sO8kRvK EBcg== X-Gm-Message-State: AODbwcDkToOVbB650hBifpl8gnOO6eZdq3e/Ad8cxfR5btks8Xcja0dn fJ7TDBiyPhAuoNWk X-Received: by 10.98.42.7 with SMTP id q7mr59874072pfq.165.1497345931413; Tue, 13 Jun 2017 02:25:31 -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 204sm18720798pfu.23.2017.06.13.02.25.28 (version=TLS1_1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 13 Jun 2017 02:25:30 -0700 (PDT) From: Binoy Jayan To: Binoy Jayan Cc: linux-kernel@vger.kernel.org, Arnd Bergmann , Rajendra , Mark Brown , Jiri Kosina , Benjamin Tissoires Subject: [PATCH v2] HID: Replace semaphore driver_lock with mutex Date: Tue, 13 Jun 2017 14:55:26 +0530 Message-Id: <1497345926-3262-1-git-send-email-binoy.jayan@linaro.org> X-Mailer: git-send-email 1.9.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Signed-off-by: Binoy Jayan Suggested-by: Arnd Bergmann --- v1 --> v2 Removed driver_lock drivers/hid/hid-core.c | 15 ++++----------- include/linux/hid.h | 2 +- 2 files changed, 5 insertions(+), 12 deletions(-) -- Binoy Jayan 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..1add2b3 100644 --- a/include/linux/hid.h +++ b/include/linux/hid.h @@ -516,7 +516,7 @@ 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 mutex 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;