From patchwork Tue May 30 16:25:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 9754901 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 58154602B9 for ; Tue, 30 May 2017 16:30:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4A3BD26538 for ; Tue, 30 May 2017 16:30:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3EE9B27F8F; Tue, 30 May 2017 16:30:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C275026538 for ; Tue, 30 May 2017 16:30:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751075AbdE3Q3u (ORCPT ); Tue, 30 May 2017 12:29:50 -0400 Received: from mail-lf0-f68.google.com ([209.85.215.68]:36763 "EHLO mail-lf0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751153AbdE3Q0w (ORCPT ); Tue, 30 May 2017 12:26:52 -0400 Received: by mail-lf0-f68.google.com with SMTP id h4so9318489lfj.3; Tue, 30 May 2017 09:26:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=ldlmI310O1z0vka5o2XxX57bVJBBSBUoZiL+moUoZAo=; b=e95TcKfhQN399/XgFb9/ovq9VusKv+CNn4GW0opheuRtyB0oaJO0cvAFTlQfo/HolL 9DilrNLJcDl/mQA3f9xJuqwvFW2VFGvrdm7Dq5kM+R/WpLF/qLAQ1YRkULXUbEU5NalR 65lCXeHtSCiz7tyCm0TKJDTp2UszspokeYaNHoChiw7R2dx+GNPloXuvKFbMAfP9SfC4 JSr11BeOQTW62bF60m1xmwrznZO7oNRQjmKGgw7BHQ0uORcXhbiF3MarAnQGw8UFOGKC 4mxA2DPaXkoSahhzMzQ8wLKRe1rnl/NKhlyuM0THxgMrFptvEgaadJFcSvB+y5mtgazG 34Qg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=ldlmI310O1z0vka5o2XxX57bVJBBSBUoZiL+moUoZAo=; b=HWsD8pTBxRHi6Snt8uOdG2SRawC3kseFRt44h3wm0zDIyz46xAVu2XT/AQwG+67hf3 RinjhNjrV3QU2WaZ0GtrZs4skw/k466QijvvzHUU2zy22cOINqaXusJbvvl8BjO4d3kQ 8QyIMWqCA31TrxPjoHULnCVo7OlU75YFz6psuKAPSbtWjbpbNhPsIMlaLethPdbSSpoA ETiVLwDhon4DQ69CT2ksFSk1jaWg7woqdrja67xxttqf18vGF/J2eUTX0c5gQqiiJpPo De5ZVfBJk0ZoEJWIktmZizXdQkS8aI47KL4gOHkwOidHEbXcZE+Nu4iUvf78TBvk9gdA q6bw== X-Gm-Message-State: AODbwcCc3g7eIj6rNQPksnZKRJRNrPH53YgYyUhhckYnU0NsRUthVgZ2 JBJQjkX/e/aQyA== X-Received: by 10.25.235.20 with SMTP id j20mr6119517lfh.141.1496161609908; Tue, 30 May 2017 09:26:49 -0700 (PDT) Received: from xi.terra (c-42c8e255.07-184-6d6c6d4.cust.bredbandsbolaget.se. [85.226.200.66]) by smtp.gmail.com with ESMTPSA id q12sm2820484lfe.5.2017.05.30.09.26.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 30 May 2017 09:26:47 -0700 (PDT) Received: from johan by xi.terra with local (Exim 4.89) (envelope-from ) id 1dFjyr-0006pD-FM; Tue, 30 May 2017 18:26:49 +0200 From: Johan Hovold To: Greg Kroah-Hartman Cc: Linus Walleij , Peter Chen , Rob Herring , Arnd Bergmann , Sricharan R , Zhang Rui , Eduardo Valentin , linux-pm@vger.kernel.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold , stable , Laxman Dewangan Subject: [PATCH 6/7] thermal: max77620: fix device-node reference imbalance Date: Tue, 30 May 2017 18:25:53 +0200 Message-Id: <20170530162554.26159-7-johan@kernel.org> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170530162554.26159-1-johan@kernel.org> References: <20170530162554.26159-1-johan@kernel.org> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The thermal child device reuses the parent MFD-device device-tree node when registering a thermal zone, but did not take a reference to the node. This leads to a reference imbalance, and potential use-after-free, when the node reference is dropped by the platform-bus device destructor (once for the child and later again for the parent). Fix this by dropping any reference already held to a device-tree node and getting a reference to the parent's node which will be balanced on reprobe or on platform-device release, whichever comes first. Note that simply clearing the of_node pointer on probe errors and on driver unbind would not allow the use of device-managed resources as specifically thermal_zone_of_sensor_unregister() claims that a valid device-tree node pointer is needed during deregistration (even if it currently does not seem to use it). Fixes: ec4664b3fd6d ("thermal: max77620: Add thermal driver for reporting junction temp") Cc: stable # 4.9 Cc: Laxman Dewangan Signed-off-by: Johan Hovold --- drivers/thermal/max77620_thermal.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/thermal/max77620_thermal.c b/drivers/thermal/max77620_thermal.c index e9a1fe342760..71d35f3c9215 100644 --- a/drivers/thermal/max77620_thermal.c +++ b/drivers/thermal/max77620_thermal.c @@ -104,8 +104,6 @@ static int max77620_thermal_probe(struct platform_device *pdev) return -EINVAL; } - pdev->dev.of_node = pdev->dev.parent->of_node; - mtherm->dev = &pdev->dev; mtherm->rmap = dev_get_regmap(pdev->dev.parent, NULL); if (!mtherm->rmap) { @@ -113,6 +111,14 @@ static int max77620_thermal_probe(struct platform_device *pdev) return -ENODEV; } + /* + * Drop any current reference to a device-tree node and get a + * reference to the parent's node which will be balanced on reprobe or + * on platform-device release. + */ + of_node_put(pdev->dev.of_node); + pdev->dev.of_node = of_node_get(pdev->dev.parent->of_node); + mtherm->tz_device = devm_thermal_zone_of_sensor_register(&pdev->dev, 0, mtherm, &max77620_thermal_ops); if (IS_ERR(mtherm->tz_device)) {