Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp234865ybg; Thu, 17 Oct 2019 22:06:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqzrYRuIRM6n2GWlGwTKlS67F00ssmuMzaaCCt9V6Jvve9ns5eFGH7sb9M8AB0d8zcvGRfO2 X-Received: by 2002:a17:906:160f:: with SMTP id m15mr6692184ejd.217.1571375173716; Thu, 17 Oct 2019 22:06:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571375173; cv=none; d=google.com; s=arc-20160816; b=eeIZYlFvB7yddrH242gBfJDbmL3nqgGTVdiRME4qJ2E8Tu3GJ6bant8vGlx3Rvfm45 qHMFwN/kpYboR0LFqICce+UXYHNb+HFQiweOusJ1xWTRmkew716MBRp9k9F10lQRa3nb EeJGiwx35ePajyDhxwaBXJygzQGfv5X9ZM3NenSdbhd+kXlomQ369KolhH0xu9oAUa45 prTqO5QLXuP+xa9QlmjcXN9KMZrXn5JfFsin9vQpeGe3A0dZOSriLGgP4UJ7hXL1rMa6 dEJ5KNgkmHEdq0YIrWRM2aWuXwOQa/7GHsfkU1zMiwrH/FITPcR8fBf0VTM9Yqh3c/8B tiZQ== 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=ja3GyAyiGNfn4N4EgRakw8TKg87/c8MKrJu1FB3A4i0=; b=VfhPm69qpp3/5PaFRPV7GzUiUk/6aZGwVL7pZRCxaI3WjaA8M1J2PxkmRWwW38jQ1Z TuxN7j/IZKlU7jIw3L0zv05CAS84FxUUmMjFcfb0WjIuLEGCyxi+H2pB/g+3//aefhdd OcmDv8Bh9sEfuUThwDDZGkIuzWe2/WSMu541pBfjG8kP11DWjUYywG7aCnitgC/C8Mfd Hf0BQNjjKJYUNNku5sxgpLBpnpXoyZ8ph9soJPwG31SqJVv2lbqpax35ztg6Y6Q3ybZ/ iAjyz/rEggU1ip/CGlP/7ZN1dVo2hd6ws5ofC051vVyb7XXDDvtZBY5lnmVzIRreR4I+ msRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=c4QK6at8; 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 i40si3031337eda.225.2019.10.17.22.05.50; Thu, 17 Oct 2019 22:06:13 -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=c4QK6at8; 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 S2404949AbfJPWUn (ORCPT + 99 others); Wed, 16 Oct 2019 18:20:43 -0400 Received: from mail.kernel.org ([198.145.29.99]:42882 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2437570AbfJPVxo (ORCPT ); Wed, 16 Oct 2019 17:53:44 -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 06FDD21928; Wed, 16 Oct 2019 21:53:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1571262823; bh=cTL+dBjDCxL6Y0uF6sd753LlF0axEe9XOYq7JAgM1hk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=c4QK6at8mdaXPkwPaqrJv4gWlaWDK+2e9+JWfTSjlsar3VBeeM8pcrPq4+dsXGRKm dinU6uR3WkkmmwWdeG20Nk1UP+S44Jt5GS85XlvkadhPIej4wOrtTfnXDtOgMfsHdR g2ydEza1GoXBY5Pqn7Szu1hus9eRfz3/Pp9IXt0k= 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.4 66/79] iio: light: opt3001: fix mutex unlock race Date: Wed, 16 Oct 2019 14:50:41 -0700 Message-Id: <20191016214826.651806493@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191016214729.758892904@linuxfoundation.org> References: <20191016214729.758892904@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 @@ -646,6 +646,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); @@ -680,13 +681,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; }