From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 23DCDCA9EA9 for ; Fri, 18 Oct 2019 22:15:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DE4BB21925 for ; Fri, 18 Oct 2019 22:15:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1571436904; bh=A1dcWW0Dnd/tqqaFleDJNjiqHkFzOb00B6+TkPnp6Dc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=NYzdF9t599Qf4Uu+HvdFuLfImOwR3cBYEVYRpth1kquhWPTblcA220IpZivtEOmOe 3FYwMfZsYEvXy005W6MqpGmAqtrgLaS2BsgMHwm5rdePh0RxLqTKr1m+eMwEHMIZVi 1ur1UWUk788FjQdcWDvW+pa72yBTMD8ym0WdY18c= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404032AbfJRWPC (ORCPT ); Fri, 18 Oct 2019 18:15:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:41870 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388627AbfJRWJL (ORCPT ); Fri, 18 Oct 2019 18:09:11 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E27B52245D; Fri, 18 Oct 2019 22:09:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1571436550; bh=A1dcWW0Dnd/tqqaFleDJNjiqHkFzOb00B6+TkPnp6Dc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tIYT93or6ndjOD6tz9vVImOqsRkIy18vwjvX6sxkrP2gDfYFxKdtU/ahkBN12DlJa 3nLggBe/mhPH/p9cWOwe9K73J0N1mPZcKpEceAFMTLso87jvlswcQxYA8xxw0VSnJF mr0v/uDLIBtDZ4J51RdRbRnL0eb/NMpGk1bnUByw= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: David Frey , Andreas Dannenberg , Stable@vger.kernel.org, Jonathan Cameron , Sasha Levin , linux-iio@vger.kernel.org Subject: [PATCH AUTOSEL 4.14 49/56] iio: light: opt3001: fix mutex unlock race Date: Fri, 18 Oct 2019 18:07:46 -0400 Message-Id: <20191018220753.10002-49-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191018220753.10002-1-sashal@kernel.org> References: <20191018220753.10002-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore 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 [ Upstream commit 82f3015635249a8c8c45bac303fd84905066f04f ] 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: Sasha Levin --- drivers/iio/light/opt3001.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/iio/light/opt3001.c b/drivers/iio/light/opt3001.c index b91ebc3483cea..743fd2cfdd54e 100644 --- a/drivers/iio/light/opt3001.c +++ b/drivers/iio/light/opt3001.c @@ -695,6 +695,7 @@ static irqreturn_t opt3001_irq(int irq, void *_iio) 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, void *_iio) } 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; } -- 2.20.1