Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp1051387ybp; Thu, 17 Oct 2019 07:22:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqwHHsqueEnYJwmaTGMnpnzNjNFz6/WGBlxMvDat6mxK7rAxJkixyUN08x9bO9JX0FCmHM+F X-Received: by 2002:a05:6402:327:: with SMTP id q7mr4112034edw.30.1571322149291; Thu, 17 Oct 2019 07:22:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571322149; cv=none; d=google.com; s=arc-20160816; b=loI+Qgy3+silNLKWp85qNlU+/iPM6Zn60444+SnXdtxDdwSpsEOdIvstlUbBiJOxr+ 86yUZlcPaaoxB9qxNtWon+j+P92DZkVJiUPp2EMz/aywTO0FQDZwTig9h0aWTGRUPSkc OIuwueScSK4co4Bq7EbXwgi1FndsnFlsiWmvE05VdI3kBgxWW3zY1zOGCNevx4Az1Wbh zjsNq/DphzdGhgpnb68o1rHendxaBnD75vEugXIgLLeBGeUg+rWZn7UmsNgPlJmb/JGO K286BGWLrgv/1+fe+ImR8mNV4L8RzwCoks6QQPqoYrCRSc2jlU+eGyZvVo9MIzBPSV50 H0Jw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=o69ytVA7xaIYaK8gXQRv6PeeU5Kn9GxF+by3tfEV3+Q=; b=x4OHq4lOWoCS5SOoYusJSbyTo+CMAFqaNBSst8dKt266tNDP1VVvG32Wd3TlObJsjl pOD73og5Uv3L46COCJJs8P7d0xbZQE81JqptAbKGKVFMHA6Yi5UVBT+s2duxh3svZU5H xpDkhkkUQ3GaTOv+4LiMIAu5ltkoiNlOVDpQBcjodTMCvF251C+SJMF0EGxW1J0dQUL8 jtnw2udBcHrtYg/JxrX4lgp0HPi7bnDiLQ0XbL+mzvV/8QQjK7a/12nnkHnfobBfiTYw zSZQq0ZQxo71DElWongEaMJXx4zO6zd9IJcwCT9OqAGTG76qJRxY9pVYevXLdOEC5HSE N5pA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=JWjoGo6w; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g13si1467360ejf.133.2019.10.17.07.22.06; Thu, 17 Oct 2019 07:22:29 -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=@kernel.org header.s=default header.b=JWjoGo6w; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732894AbfJPVzW (ORCPT + 99 others); Wed, 16 Oct 2019 17:55:22 -0400 Received: from mail.kernel.org ([198.145.29.99]:45740 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2437741AbfJPVzQ (ORCPT ); Wed, 16 Oct 2019 17:55:16 -0400 Received: from localhost (unknown [192.55.54.58]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 81A8E20872; Wed, 16 Oct 2019 21:55:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1571262915; bh=AyP47DE0aOW3YdRHBv28szmli6vQ7mQ8OQ0KpvCpmzI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JWjoGo6w9S6bD0hWlToJfuq3v5pKMEfKo8LrpV+j8IcqotZzk7H2fMGRSjQVXE4oz QrXXB2Im5dMIhOVLElqKUOWvglwrstebDhKc/WxAfgR5KKOuG77aViBcTfR7IN+lK3 vCqPFPSh8/FisV8p3E08hil4XlxbHMHFAGEG12xw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, David Frey , Andreas Dannenberg , Stable@vger.kernel.org, Jonathan Cameron Subject: [PATCH 4.9 75/92] iio: light: opt3001: fix mutex unlock race Date: Wed, 16 Oct 2019 14:50:48 -0700 Message-Id: <20191016214845.595508924@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191016214759.600329427@linuxfoundation.org> References: <20191016214759.600329427@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: David Frey commit 82f3015635249a8c8c45bac303fd84905066f04f upstream. When an end-of-conversion interrupt is received after performing a single-shot reading of the light sensor, the driver was waking up the result ready queue before checking opt->ok_to_ignore_lock to determine if it should unlock the mutex. The problem occurred in the case where the other thread woke up and changed the value of opt->ok_to_ignore_lock to false prior to the interrupt thread performing its read of the variable. In this case, the mutex would be unlocked twice. Signed-off-by: David Frey Reviewed-by: Andreas Dannenberg Fixes: 94a9b7b1809f ("iio: light: add support for TI's opt3001 light sensor") Cc: Signed-off-by: Jonathan Cameron Signed-off-by: Greg Kroah-Hartman --- drivers/iio/light/opt3001.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) --- a/drivers/iio/light/opt3001.c +++ b/drivers/iio/light/opt3001.c @@ -695,6 +695,7 @@ static irqreturn_t opt3001_irq(int irq, struct iio_dev *iio = _iio; struct opt3001 *opt = iio_priv(iio); int ret; + bool wake_result_ready_queue = false; if (!opt->ok_to_ignore_lock) mutex_lock(&opt->lock); @@ -729,13 +730,16 @@ static irqreturn_t opt3001_irq(int irq, } opt->result = ret; opt->result_ready = true; - wake_up(&opt->result_ready_queue); + wake_result_ready_queue = true; } out: if (!opt->ok_to_ignore_lock) mutex_unlock(&opt->lock); + if (wake_result_ready_queue) + wake_up(&opt->result_ready_queue); + return IRQ_HANDLED; }