From patchwork Mon Feb 29 20:38:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 8458001 Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 708DDC0553 for ; Mon, 29 Feb 2016 20:38:56 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9E5B3201B4 for ; Mon, 29 Feb 2016 20:38:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BAD622021A for ; Mon, 29 Feb 2016 20:38:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752722AbcB2Uiy (ORCPT ); Mon, 29 Feb 2016 15:38:54 -0500 Received: from mail-wm0-f65.google.com ([74.125.82.65]:35609 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751052AbcB2Uix (ORCPT ); Mon, 29 Feb 2016 15:38:53 -0500 Received: by mail-wm0-f65.google.com with SMTP id 1so738109wmg.2; Mon, 29 Feb 2016 12:38:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:subject:to:cc:message-id:date:user-agent:mime-version :content-transfer-encoding; bh=l5Unux/K3tGQFqv7Ke6EXuK9B5XiNCEY55QD7xXnmwo=; b=d1Ggczbi5kYGQJn7F/Fjj6cZTwwhkz/94yb7E9WK0U5UsHCp/2N6FQxzWROB2lDZCc lbcmm+rPExWYaCKcjz+WO+uQRXOO7S2F4J34U96WmKf1wvn19QjIC3InSKjjv4VaK3/E +EnzgWjUc2RP/n3SP1ZX4P3knKHmsNOYt4AidjOjIKxxwwn9FZpzEwV7zo53ClGNEI7C sWQR7PyPJliE7TcIO+K1ds4oVbQuE/MGeBi3TyTskqn4IM5b6ozsm1qg7ccDLtr5TZPM XbqMcX0BcGKfWsZjo92xf9sOKTDadPyn/OemPM99KCE7zyIFCU9BQG/3ii0qEp1W8yyv EaqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:subject:to:cc:message-id:date:user-agent :mime-version:content-transfer-encoding; bh=l5Unux/K3tGQFqv7Ke6EXuK9B5XiNCEY55QD7xXnmwo=; b=VOCYq1dADDr7e+YplR60at+TPA90htWyc5VND/5C+JAjv6MNheQ3G5EtUYtyp85OnM DSqbA17EADMM+B5nGA1OmTqGcX9pzQR4D9FJi7u1nG/FotPfU+HutQOmJAaYAJsPkQDD imItJSooj0QA8rzT5N5ofbhoI/ZqXuxqrqEp4W1YVAcCAGxLyE3sPqQa1e2yMd6Fwhhl KdcuFhVS861e4ZehtwVWjnmH6FzSjde9y9MTzTlqwL+3jYLwG2qgZybBIvckIyupO8gS de7iPmIvvO2Pva53jEeXoTdVQarXiYqNt6wGyRReM56r4AvvjZpAzbNff/ShZYxVWSqP 4QeA== X-Gm-Message-State: AD7BkJKvOiYIqRW8haXGvGuQnQp9O+gIXcWsNd6+TSIH2pKb/I1uP/atcH10IIuAwU9/rA== X-Received: by 10.194.223.104 with SMTP id qt8mr6185580wjc.11.1456778331716; Mon, 29 Feb 2016 12:38:51 -0800 (PST) Received: from ?IPv6:2003:62:5f55:ba00:d868:2516:4122:61c1? (p200300625F55BA00D8682516412261C1.dip0.t-ipconnect.de. [2003:62:5f55:ba00:d868:2516:4122:61c1]) by smtp.googlemail.com with ESMTPSA id t3sm27639128wjz.11.2016.02.29.12.38.50 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 29 Feb 2016 12:38:50 -0800 (PST) From: Heiner Kallweit Subject: [PATCH 3/3] hid: thingm: improve locking To: Jiri Kosina Cc: Jacek Anaszewski , Benjamin Tissoires , linux-input@vger.kernel.org, linux-leds@vger.kernel.org Message-ID: <56D4AC4C.3050707@gmail.com> Date: Mon, 29 Feb 2016 21:38:36 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 MIME-Version: 1.0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When reading from the device the full operation including sending the read command and the actual read should be protected by the mutex. Facilitate this by changing the semantics of thingm_recv to include sending the read command. Signed-off-by: Heiner Kallweit --- drivers/hid/hid-thingm.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/drivers/hid/hid-thingm.c b/drivers/hid/hid-thingm.c index 5e35ec1..0e4b50c 100644 --- a/drivers/hid/hid-thingm.c +++ b/drivers/hid/hid-thingm.c @@ -77,9 +77,13 @@ static int thingm_send(struct thingm_device *tdev, u8 buf[REPORT_SIZE]) buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7], buf[8]); + mutex_lock(&tdev->lock); + ret = hid_hw_raw_request(tdev->hdev, buf[0], buf, REPORT_SIZE, HID_FEATURE_REPORT, HID_REQ_SET_REPORT); + mutex_unlock(&tdev->lock); + return ret < 0 ? ret : 0; } @@ -87,16 +91,26 @@ static int thingm_recv(struct thingm_device *tdev, u8 buf[REPORT_SIZE]) { int ret; + mutex_lock(&tdev->lock); + + ret = hid_hw_raw_request(tdev->hdev, buf[0], buf, REPORT_SIZE, + HID_FEATURE_REPORT, HID_REQ_SET_REPORT); + if (ret < 0) + goto err; + ret = hid_hw_raw_request(tdev->hdev, buf[0], buf, REPORT_SIZE, HID_FEATURE_REPORT, HID_REQ_GET_REPORT); if (ret < 0) - return ret; + goto err; + + ret = 0; hid_dbg(tdev->hdev, "<- %d %c %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx\n", buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7], buf[8]); - - return 0; +err: + mutex_unlock(&tdev->lock); + return ret; } static int thingm_version(struct thingm_device *tdev) @@ -104,10 +118,6 @@ static int thingm_version(struct thingm_device *tdev) u8 buf[REPORT_SIZE] = { REPORT_ID, 'v', 0, 0, 0, 0, 0, 0, 0 }; int err; - err = thingm_send(tdev, buf); - if (err) - return err; - err = thingm_recv(tdev, buf); if (err) return err; @@ -135,14 +145,10 @@ static int thingm_led_set(struct led_classdev *ldev, struct thingm_led *led = container_of(ldev, struct thingm_led, ldev); int ret; - mutex_lock(&led->rgb->tdev->lock); - ret = thingm_write_color(led->rgb); if (ret) hid_err(led->rgb->tdev->hdev, "failed to write color\n"); - mutex_unlock(&led->rgb->tdev->lock); - return ret; }