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: 105454 Delivered-To: patch@linaro.org Received: by 10.140.91.77 with SMTP id y71csp143072qgd; Tue, 13 Jun 2017 23:12:29 -0700 (PDT) X-Received: by 10.84.171.193 with SMTP id l59mr3382658plb.139.1497420749570; Tue, 13 Jun 2017 23:12:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1497420749; cv=none; d=google.com; s=arc-20160816; b=awEiImwFFt+zeeiTLq1sefWtG+YZQQ51CM2Px7tT4Irow7sN2S7+jJL1Mg9TQH5hRS 0oisWA0CCrIvs02n2O4dWeyzFwCrdvnjOXQeWu/lGbyIF6cBRNUcRv2Ffmp/k/h/gWQk M3a72Min2jDJsPw1JyLienSO8OH7Cq/gVO9ehQ6Rjt0YVJJjQw2Dbj1/uli7agUwDIWp 48Teh8Ja+HyPdW5uBQrgFKYdj9ocbcbhnIcwSE0xojLWowi/xnJqTEZ1xTGYDMYMi1iK 2+PB8Dc6lDsULM0YBpq3ifv5iKMymmnSNNEqIToWSNFEkbARTIJXx91iyqrBKrsiOyLy /2cw== 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=5cZO5QytBzC6RCYIzuloN7ICYaP3Hd5h+QJmgnEsJhE=; b=o2lTVVWtLa79FL06u7csWbx45949pVfdVo2d03gkgN9EjfQ8Vo8vRaXxyU1pizFUs+ ZksgrDihO3+po5+kktjI2E1R1MENMlyHI5GgzctgQXAycYD2Gqkq8cB4mboxREvvrmW2 6ec4hl3P8UDvwhiZGKqKPU58zNV2zs3krdKeLnFcMcYcBFR7dOPBwPPMw3jsiZeFkvrP u7AVDtqgrc4XwJ1NevOnetMm/oBnpK3IY4A6ZIvftptkFBP27oWc6Jex6sQJOG1n1HZX 35sG3vZ8n1Tx91sya8wAxptv9fUg6Wu7gzVya8qTvbW017JcZTLDMFMc84v99fE7Zske 0BLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-input-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-input-owner@vger.kernel.org; dmarc=fail (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 l2si1596114pfa.48.2017.06.13.23.12.29 for ; Tue, 13 Jun 2017 23:12:29 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-input-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-input-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-input-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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 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(-) -- Binoy Jayan -- To unsubscribe from this list: send the line "unsubscribe linux-input" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html 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 */