Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp1351939ybp; Thu, 17 Oct 2019 11:28:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqz2scFhBgk07TcrMU40+h3dEU9k8+0yst88Z9B1qStpoIOh8X2tNjAOs8n4qmefGdN8g/mZ X-Received: by 2002:a17:906:f75a:: with SMTP id jp26mr4832098ejb.191.1571336912515; Thu, 17 Oct 2019 11:28:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571336912; cv=none; d=google.com; s=arc-20160816; b=VyvZIHhGZcB0Ku7qi7C6djpKT0TM+Fk0wKa6LAblEMDMOqE5yIBGJ9pm0y+JlsVwj7 JPBS6CEjadxsP5YwT8cOexVP+ElL/7S/p/+LCkHP4OMWGSjsPG/p8LbkCK3z00dBekxt citX3IdjqhR53bNF/Wz7Uy4UvQGDzkiOUFrcJisQWY0mADgU23jAO5O6W8nUmPkLuLL7 ggqclQOFEZ84pFa9JVSdu9vN+2SgH9bMFox8yET/RGFrdHgNA3cbSErZlvkbpqmhqSVZ 6Z51spdsLz8ZlCNVi8oxCSnSZd0MdOBSf8QZ4WXMFdFFpSfN9TNwfBNbdhGWNy9MmMxd vNjA== 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=Py3DuLLOZnlbKCIa/G/0+UyxpQ6wsq72DH/St1JMg24=; b=KI6aAhRZD+xIRZHYxIdTd53zTGhUFnOfl3Pmz4UxvA0qdtoEkTqazJBSp7yZ0vFPn4 ScyPC9uavM21JMkTZWkWFfVCVb2bzCV/qWwuJCIIsztJIP3ANGpTt//PMJpMhRxXzQgP shmxKNcrinDXSRjNF0rwBpZ4Amer3BGzA98VhxMtbeSx51C2wQI8BmHCd1YIYjHDOvvM E2pYUket64noJhcbFNhWKnZQZ3kOWPHL+ZrG09vaBCzFEkTnCPzvg+kHjTPf7BU+bqEB gcWhcZdiGXhZow10uOqpumFOxOojCUqW6dTopGQ+x9XU6Ukcg/C50ohFg3emdtZ2Xj8s Z58Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=PgndQ1df; 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 b27si2020085ede.233.2019.10.17.11.28.07; Thu, 17 Oct 2019 11:28:32 -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=PgndQ1df; 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 S2404508AbfJPWFP (ORCPT + 99 others); Wed, 16 Oct 2019 18:05:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:52910 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2438312AbfJPV6y (ORCPT ); Wed, 16 Oct 2019 17:58:54 -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 A7A1C21925; Wed, 16 Oct 2019 21:58:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1571263133; bh=C30LIA4zxBrlR+4FaEQFknN7Iq8Y10iVG/GYZVZn4zI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PgndQ1df8RGzCKYtA7MWvxVSk8zLeMKje6XbUzMjfYz1X2hANXM7Gwy7u6xCKCCNM QK/dISwHZS00+RlNazDJoNBEyZY/gZbayMPQ91hCyGHnExIQZY7zBXa8JHoXvSdoW2 5OBdJClKUt8+W3aJWf7WO8z7wCWT6/iJ1JUPkXiw= 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 5.3 057/112] iio: light: opt3001: fix mutex unlock race Date: Wed, 16 Oct 2019 14:50:49 -0700 Message-Id: <20191016214859.675094894@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191016214844.038848564@linuxfoundation.org> References: <20191016214844.038848564@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 @@ -686,6 +686,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); @@ -720,13 +721,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; }