Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp1075132ybp; Thu, 17 Oct 2019 07:38:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqxph1dD9e4KmUVKncuiC3d64masfY20x1dMRst/h6c/C38h8FwPrFlAC4Fx1AHsB+/JxjQ6 X-Received: by 2002:aa7:c6d0:: with SMTP id b16mr4220186eds.108.1571323087437; Thu, 17 Oct 2019 07:38:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571323087; cv=none; d=google.com; s=arc-20160816; b=UDl1q6E87xlOGKXBg/CbyVik7/0lKFrk6d4WUEqWKw5Co+WfWZNBdxYk074z++BJat Dh9uK6WrvBk4XYhE1OwLc/y+SejK0OvllnHnA7EqhhQWHa/+D4T+4ALEUQ8/Ld0ODecM Qnt993rzvNolEYkJ+5IKZ2CdV8abp8Y+AuUUNQU/3d6ofKBZV7CYkfjBOPdAbuZY4IPB BRy3iN0CIPDg87oAvAuOadKjDWDMlyjxSpHQY1ng6ubJV/ht/KDGN1obKNNgikOr7Zja rtrLyfZb09TlnNZAoapq4qbf4T4aE1ldJq0PkHY0hlFDhE7qA6LqPu38AvGCGiZHT4GB ma/w== 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=nY5jDwJZa8CJsaiVM04s21JxoE4RhTcj+c+lBW3S1m4rf4nV6Syt2hhpwHGJD40vRD aTq5QDzX9jStFADwePUT7Wea/fH0oTr8x4xRKXQif4pY6UpDiW47/rerjf6GzcLXVeEY AmO+lIlykFD7Na35RLV9tLBNf6s6t7BaoDUsxB4vLNW8N4xLf7t0kBIgH+ZZlrnXVky9 QEfDM0PKL6mTO1p1u5G+Xq0658OqQLHv7XIuR5CLK0Vw5veWMuqU9onS7ZrYzDq5+hRY lgjJTvrn42xnrfnfepINB7MIhb3ISnUjkJRsRsCOxStV20389jusYVzXmySmvyvodSEt A5tg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=XgnpMCiZ; 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 d26si1574917edq.91.2019.10.17.07.37.44; Thu, 17 Oct 2019 07:38:07 -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=XgnpMCiZ; 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 S2437982AbfJPV5R (ORCPT + 99 others); Wed, 16 Oct 2019 17:57:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:48642 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390510AbfJPV4m (ORCPT ); Wed, 16 Oct 2019 17:56:42 -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 744D621D7A; Wed, 16 Oct 2019 21:56:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1571263001; bh=AyP47DE0aOW3YdRHBv28szmli6vQ7mQ8OQ0KpvCpmzI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XgnpMCiZsrQXwmpmYnXjhUluIYGv9F1z8EhJpjT9GT6DqMcHNibDZFxqu7BbnDrYp S5wbKAg/STipsMW80bmPHMCZep69AU5uEGTOmdzldsDruJoFvFI/PfSPRZVLhBp2SS U9OfNolwCpu827wWyqHnVgo2xmjcn3ZZh2ta7GrU= 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.14 42/65] iio: light: opt3001: fix mutex unlock race Date: Wed, 16 Oct 2019 14:50:56 -0700 Message-Id: <20191016214832.459532926@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191016214756.457746573@linuxfoundation.org> References: <20191016214756.457746573@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; }