From patchwork Tue Jul 29 15:14:20 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Herrmann X-Patchwork-Id: 4640801 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 679B69F32F for ; Tue, 29 Jul 2014 15:15:06 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 837B820115 for ; Tue, 29 Jul 2014 15:15:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3F87B2014A for ; Tue, 29 Jul 2014 15:15:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753989AbaG2PO4 (ORCPT ); Tue, 29 Jul 2014 11:14:56 -0400 Received: from mail-we0-f179.google.com ([74.125.82.179]:56890 "EHLO mail-we0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752764AbaG2PO4 (ORCPT ); Tue, 29 Jul 2014 11:14:56 -0400 Received: by mail-we0-f179.google.com with SMTP id u57so9285873wes.10 for ; Tue, 29 Jul 2014 08:14:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=7ovBWDzKQak9RB6oQy3rFFbjJMeJJ0LM76BvyO5lQvE=; b=SuGI8pQ1O7HOXpj5N9mY26prZBByXwCaSh+HJg7OyCwvACRixAzWawA11aVKNc+hs1 o/sBsNwqkI5esCWU856P89a01VE/0KsHqdugrm7sF0Uci86d440/TzdUnMlpuxy1ffR0 Pfj+pZze0HF5gmjVqNtrooPsh+Erb4SFBjxluR8eDSJz7uJOiqr6oGnELy1uVBFosUla wq5H0O2azVZ8HFb6a16Pruv/hIpKQPKGRXQdNGruxuvcwqF35xOoxa8MS11XFCeWZ6wG d+n5zg2HSlME/aHSWhgQD3gZtjk/XlmATR01cjRGiWcpDH1w263jLfkxfJ7uEGEvPCXd pVsA== X-Received: by 10.180.14.5 with SMTP id l5mr7374116wic.50.1406646894951; Tue, 29 Jul 2014 08:14:54 -0700 (PDT) Received: from david-tp.localdomain (stgt-4d0247ad.pool.mediaWays.net. [77.2.71.173]) by mx.google.com with ESMTPSA id fs3sm44361822wic.20.2014.07.29.08.14.53 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 29 Jul 2014 08:14:54 -0700 (PDT) From: David Herrmann To: linux-input@vger.kernel.org Cc: Jiri Kosina , Benjamin Tissoires , David Herrmann Subject: [PATCH 06/12] HID: uhid: invert report_done and make non-atomic Date: Tue, 29 Jul 2014 17:14:20 +0200 Message-Id: <1406646866-999-7-git-send-email-dh.herrmann@gmail.com> X-Mailer: git-send-email 2.0.3 In-Reply-To: <1406646866-999-1-git-send-email-dh.herrmann@gmail.com> References: <1406646866-999-1-git-send-email-dh.herrmann@gmail.com> Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Spam-Status: No, score=-7.5 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=ham 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 All accesses to @report_done are protected by qlock (or report-contexts). No need to use an atomic. While at it, invert the logic and call it "report_running". This is similar to the uhid->running field and easier to read. Signed-off-by: David Herrmann --- drivers/hid/uhid.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c index db4e119..2d2025a 100644 --- a/drivers/hid/uhid.c +++ b/drivers/hid/uhid.c @@ -47,7 +47,7 @@ struct uhid_device { /* blocking GET_REPORT support; state changes protected by qlock */ struct mutex report_lock; wait_queue_head_t report_wait; - atomic_t report_done; + bool report_running; u32 report_id; struct uhid_event report_buf; }; @@ -168,13 +168,13 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum, ev->u.feature.rnum = rnum; ev->u.feature.rtype = report_type; - atomic_set(&uhid->report_done, 0); + uhid->report_running = true; uhid_queue(uhid, ev); spin_unlock_irqrestore(&uhid->qlock, flags); ret = wait_event_interruptible_timeout(uhid->report_wait, - atomic_read(&uhid->report_done) || !uhid->running, - 5 * HZ); + !uhid->report_running || !uhid->running, + 5 * HZ); if (!ret || !uhid->running) { ret = -EIO; @@ -196,7 +196,7 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum, spin_unlock_irqrestore(&uhid->qlock, flags); } - atomic_set(&uhid->report_done, 1); + uhid->report_running = false; unlock: mutex_unlock(&uhid->report_lock); @@ -500,11 +500,11 @@ static int uhid_dev_feature_answer(struct uhid_device *uhid, /* id for old report; drop it silently */ if (uhid->report_id != ev->u.feature_answer.id) goto unlock; - if (atomic_read(&uhid->report_done)) + if (!uhid->report_running) goto unlock; memcpy(&uhid->report_buf, ev, sizeof(*ev)); - atomic_set(&uhid->report_done, 1); + uhid->report_running = false; wake_up_interruptible(&uhid->report_wait); unlock: @@ -526,7 +526,6 @@ static int uhid_char_open(struct inode *inode, struct file *file) init_waitqueue_head(&uhid->waitq); init_waitqueue_head(&uhid->report_wait); uhid->running = false; - atomic_set(&uhid->report_done, 1); file->private_data = uhid; nonseekable_open(inode, file);