Received: by 10.192.165.148 with SMTP id m20csp2482653imm; Sun, 22 Apr 2018 07:59:51 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+gVD1xWHiPpn4jCGjt0fNXZjJayg/JioewmJAgJYtgXOmM97dig1UdTgnQrEl1S0tWWOQT X-Received: by 10.99.120.138 with SMTP id t132mr14428528pgc.280.1524409191335; Sun, 22 Apr 2018 07:59:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524409191; cv=none; d=google.com; s=arc-20160816; b=PGC56QHXGCTuuuL+IgbzWT0ZwI2v23dRgK7JgbUqvV8eYJjv2HFMIddR4z5TsPSC8v ubDbiwX8HK6EED3noMfpw4d0Hs+2700KlNXyDlozoq9b7hZ73pceNlGrbFBku5kPpiki lfzrQIKw4ww+V1JirJbPnCs1ztNzbcOGUc3Df7JwvI9wzCZfl8f0wOtsE3hWmGmQIWZz gI5qW6xJxdoQ/dcbIE5RwTvcXXMttxXy25QHkkCg7GCZxqdgL+9xrKh9EZ7aT1FdUbFS DvZL1DgDYjotDkOD9yxiwCZcVZOtxqTTiae5Y/aVe29gl4XwB0tF6ZFU+zGGabpEUvFn JIwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=Wwtzag7sYylI3sTCRkIrq14NnMfyr6W7sIunGQFBR8k=; b=zvaizUWLjAYNJBUqxHfqzoT9t1FM4lOMHuPpgUwxfoD7dlp1A53QM47PPq3beUv5/9 wskvt6XhWRWXu7KDRd/gDe1yqk/fdFF/HRWx1NzLDFYz0nC9catO7sfwKWjEz7upHQOy zwO6sdtKYTT1MkX7HV1/pkvYMdTPu3qhxcjlx4dyf/R6V1IA1bx5RZutteKuTpSY9FRF ShPIw0ua+JyFGCVKI7IC5Qoqd5Jt3dKivpdLpIPoo8XCucmdr3d6Gdz32uSdI3qI4x+L 0PbrXOGBuvKiyalvhNGNZ8QBqljfcKf2vz4M8VQsl5t+zvUV3WNaqQq8VqwOePghw0mN b0dw== ARC-Authentication-Results: i=1; mx.google.com; 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 y2si8456406pgb.422.2018.04.22.07.59.37; Sun, 22 Apr 2018 07:59:51 -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; 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 S1754709AbeDVO6e (ORCPT + 99 others); Sun, 22 Apr 2018 10:58:34 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:55652 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756831AbeDVONU (ORCPT ); Sun, 22 Apr 2018 10:13:20 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id C5691CE9; Sun, 22 Apr 2018 14:13:19 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mikhail Lappo , Fabio Estevam , Philipp Zabel , Dong Aisheng , Zhang Rui Subject: [PATCH 4.9 56/95] thermal: imx: Fix race condition in imx_thermal_probe() Date: Sun, 22 Apr 2018 15:53:25 +0200 Message-Id: <20180422135212.710583834@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180422135210.432103639@linuxfoundation.org> References: <20180422135210.432103639@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Mikhail Lappo commit cf1ba1d73a33944d8c1a75370a35434bf146b8a7 upstream. When device boots with T > T_trip_1 and requests interrupt, the race condition takes place. The interrupt comes before THERMAL_DEVICE_ENABLED is set. This leads to an attempt to reading sensor value from irq and disabling the sensor, based on the data->mode field, which expected to be THERMAL_DEVICE_ENABLED, but still stays as THERMAL_DEVICE_DISABLED. Afher this issue sensor is never re-enabled, as the driver state is wrong. Fix this problem by setting the 'data' members prior to requesting the interrupts. Fixes: 37713a1e8e4c ("thermal: imx: implement thermal alarm interrupt handling") Cc: Signed-off-by: Mikhail Lappo Signed-off-by: Fabio Estevam Reviewed-by: Philipp Zabel Acked-by: Dong Aisheng Signed-off-by: Zhang Rui Signed-off-by: Greg Kroah-Hartman --- drivers/thermal/imx_thermal.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- a/drivers/thermal/imx_thermal.c +++ b/drivers/thermal/imx_thermal.c @@ -587,6 +587,9 @@ static int imx_thermal_probe(struct plat regmap_write(map, TEMPSENSE0 + REG_CLR, TEMPSENSE0_POWER_DOWN); regmap_write(map, TEMPSENSE0 + REG_SET, TEMPSENSE0_MEASURE_TEMP); + data->irq_enabled = true; + data->mode = THERMAL_DEVICE_ENABLED; + ret = devm_request_threaded_irq(&pdev->dev, data->irq, imx_thermal_alarm_irq, imx_thermal_alarm_irq_thread, 0, "imx_thermal", data); @@ -598,9 +601,6 @@ static int imx_thermal_probe(struct plat return ret; } - data->irq_enabled = true; - data->mode = THERMAL_DEVICE_ENABLED; - return 0; }