Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4431667imu; Tue, 29 Jan 2019 01:12:05 -0800 (PST) X-Google-Smtp-Source: ALg8bN4MxcehqNpDzBlTkTkVSNi0Ze4I8fMCHB5k2NqcBREQtEusoZKNdmVNWK295Hb5UqGDEome X-Received: by 2002:a62:b24a:: with SMTP id x71mr25930442pfe.148.1548753125668; Tue, 29 Jan 2019 01:12:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548753125; cv=none; d=google.com; s=arc-20160816; b=xdEMeQ1lJfzW/87necenUdZOitSOexUc7mkDTjUphYJWfpBaQSBV9fDeDEzup5x45G QHM03FiEhYdBoqnPnDsxAssPwKLkfJLoLXFID8dVzvzGEtkUn/INqSxxgLNJdUH/uKxQ a7T8Gm5md/zr/bmV+vPJuZTpn/9jSzMgFyqCvDS2au+/qgKOAU/POlFuTb+ZiBctibmk Jrx+dYTWtFZkJdgPVig7VAbjSJmr4eOOWdQyeEprf2sI0ws4eDGc+5Djl/kz0aidAh/J HS5YB3P1fcjM5OSd7f90Rw3yJ1Ku5i8pAsqFfh7xkCGvWQX01TsnqfSXIzZi93OnNV65 wnoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:to:from :dkim-signature:dkim-signature; bh=k+E40Tzc8px8cxD6PUEgzTs1U0d15EV2t5awtuJLmnk=; b=lh1KWObUCXZwEnBCTRVBzBq8pvoPBzO0Cf6eF8WE2QzfTS1xgulvsJ2MuNoVW6fH2X cwY3DX8mWDsHFyjTHQL9+OdoxGApiF8SinDydh+oubntL2zdBgEWNrhnu2yF37b6H0VW vMCza0G7ideor6reot8XHprdEgZm4ROrLIuoCBNTH/j6V7Tc1NmDGbNwl6PGkgAbI6WI Jd5XnUjqPMNmp3D9QlnTuWwxpqcNJX+uTdCnBvwKjR8tiH5U31mtW15JUFnYxKVcwrI3 wMWvEj1dkiTJBmOJ9tJBDl7LNpSdisPtVEZIhMOPA/DdyGOrpV6gYAXRsaR8ca8rtS+k OIKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@raspberrypi.org header.s=pp header.b=TFpy7ecx; dkim=pass header.i=@raspberrypi.org header.s=google header.b=LXSBpit2; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=raspberrypi.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u3si33224561pgj.300.2019.01.29.01.11.50; Tue, 29 Jan 2019 01:12:05 -0800 (PST) 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=@raspberrypi.org header.s=pp header.b=TFpy7ecx; dkim=pass header.i=@raspberrypi.org header.s=google header.b=LXSBpit2; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=raspberrypi.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727913AbfA2JLS (ORCPT + 99 others); Tue, 29 Jan 2019 04:11:18 -0500 Received: from mx08-00252a01.pphosted.com ([91.207.212.211]:35730 "EHLO mx08-00252a01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725846AbfA2JLS (ORCPT ); Tue, 29 Jan 2019 04:11:18 -0500 Received: from pps.filterd (m0102629.ppops.net [127.0.0.1]) by mx08-00252a01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x0T947iZ028931 for ; Tue, 29 Jan 2019 09:11:17 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.org; h=from : to : subject : date : message-id; s=pp; bh=k+E40Tzc8px8cxD6PUEgzTs1U0d15EV2t5awtuJLmnk=; b=TFpy7ecxszSfnsP2Igc6YS3diYf9H8xG0lTpPILCIX5el5mH6SISWeWYGG/dweALv+19 Sfbq77ojp/LB2c4KgzL/ncJIAX+9we8wFqUbeZVWt29+2lFd1C4NLLOiY4213vYh9V1L crVUIzhKvZ4Fd3nDOH3LVDCcVE76gMnsTzFw8N97NMNf/E5Pt4MIBCbshUkpdGoYLPd4 1+fGbxujT3+TM6ICzHpUF0zcBKSgKDi6KloKDrJNvD4wDN1nFXYngpiIN0dCxQlyqigk hnVRwMOQKVHE6MZaZKAZjMRBMYYlhfNcjEgeIC12ckMh/FJjiGb3vcrnAAGcfl1DE85H Yw== Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by mx08-00252a01.pphosted.com with ESMTP id 2q8cwk9efe-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=OK) for ; Tue, 29 Jan 2019 09:11:16 +0000 Received: by mail-wr1-f72.google.com with SMTP id z16so7697228wrt.5 for ; Tue, 29 Jan 2019 01:11:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.org; s=google; h=from:to:subject:date:message-id; bh=k+E40Tzc8px8cxD6PUEgzTs1U0d15EV2t5awtuJLmnk=; b=LXSBpit2684nUOXVcQL8YvdeNrw2m4gf2aaXN3Mf5lP2vbcIgWBIUho4LM0HCJ5q8s yO20Qg8u0Fp4kU5vxdubULpuriXy2UV0CmwAm2uyivDWHDDYgUhVdqe4xmAO2Iq8vWEb pRunYTYNADVz70oQY+CbR63h4gQl/QfjpNuct1kFN6jL9RPlDNmiwA3MGWX61Q0CLcYZ 3X4vcrUm59LO4krM6CMnCfJ0eoEUmMzk4q3OrjF6PNzzP9eDvtGpofgBdK3k0t5D2kyL ZbX2hZhxG/9Iv+59zQ1QjDMPShklQTTZ8veR3lC+djAS5Yjei+lQC0cBqYgT06bp4KER AsrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=k+E40Tzc8px8cxD6PUEgzTs1U0d15EV2t5awtuJLmnk=; b=RGwBgIKEdmO1liM68TSGdsMB5rxeRBbQdfKH/TR67+KpD52kb4hvhPg6vQhslv8csV l9fN6+aFrP9PVxtFGJtzF9pk6SfzvY+cMB+br5FEObdh67hfLcar5CG1ksx+m1Zwb+Lo DMnHRbxPIzZViO1TCwuCuxzjmMhhxs+OggpV7EGxLyxPihfYoJaApD+Sw0+hJOOerAuZ I/+0KOvm61sjeljDctStFp5DlxBYvR2joSjwSKPJGHDoq0NQcEEJl/MZxIeE/Kr4XDg1 c4QKum+tnjByyfJ2Oei2qigikPQ1iX85QjYryyJFJ9QXHBfEQG1Cjpc6W7OkiloM6Hzo Ndyw== X-Gm-Message-State: AJcUukcsIUtR6YFCBWNleTstx+vsLqjZDMbwG/UduMWkqhqf4KXK2YR2 U97469mWzcE6V3gCNFK/52dI8f1hUTB1fUBKTayWqyxhDJXHk51mopY0mBdRy1EtjKWDyaH7WMh 27o7onsk6tTLTYh0dvf6U4Kw7 X-Received: by 2002:a1c:4301:: with SMTP id q1mr20210608wma.44.1548753075621; Tue, 29 Jan 2019 01:11:15 -0800 (PST) X-Received: by 2002:a1c:4301:: with SMTP id q1mr20210579wma.44.1548753075335; Tue, 29 Jan 2019 01:11:15 -0800 (PST) Received: from localhost.localdomain (cust51-dsl50.idnet.net. [212.69.50.51]) by smtp.gmail.com with ESMTPSA id t18sm381114wmd.40.2019.01.29.01.11.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 29 Jan 2019 01:11:14 -0800 (PST) From: Phil Elwell To: Daniel Lezcano , Eric Anholt , Stefan Wahren , Florian Fainelli , bcm-kernel-feedback-list@broadcom.com, Geert Uytterhoeven , Phil Elwell , linux-pm@vger.kernel.org, linux-rpi-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] thermal: bcm2835: Fix crash in bcm2835_thermal_debugfs Date: Tue, 29 Jan 2019 09:10:48 +0000 Message-Id: <1548753048-78735-1-git-send-email-phil@raspberrypi.org> X-Mailer: git-send-email 2.7.4 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-01-29_07:,, signatures=0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org "cat /sys/kernel/debug/bcm2835_thermal/regset" causes a NULL pointer dereference in bcm2835_thermal_debugfs. The driver makes use of the implementation details of the thermal framework to retrieve a pointer to its private data from a struct thermal_zone_device, and gets it wrong - leading to the crash. Instead, store its private data as the drvdata and retrieve the thermal_zone_device pointer from it. Fixes: bcb7dd9ef206 ("thermal: bcm2835: add thermal driver for bcm2835 SoC") Signed-off-by: Phil Elwell --- drivers/thermal/broadcom/bcm2835_thermal.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/drivers/thermal/broadcom/bcm2835_thermal.c b/drivers/thermal/broadcom/bcm2835_thermal.c index 720760c..ba39647 100644 --- a/drivers/thermal/broadcom/bcm2835_thermal.c +++ b/drivers/thermal/broadcom/bcm2835_thermal.c @@ -119,8 +119,7 @@ static const struct debugfs_reg32 bcm2835_thermal_regs[] = { static void bcm2835_thermal_debugfs(struct platform_device *pdev) { - struct thermal_zone_device *tz = platform_get_drvdata(pdev); - struct bcm2835_thermal_data *data = tz->devdata; + struct bcm2835_thermal_data *data = platform_get_drvdata(pdev); struct debugfs_regset32 *regset; data->debugfsdir = debugfs_create_dir("bcm2835_thermal", NULL); @@ -266,7 +265,7 @@ static int bcm2835_thermal_probe(struct platform_device *pdev) data->tz = tz; - platform_set_drvdata(pdev, tz); + platform_set_drvdata(pdev, data); /* * Thermal_zone doesn't enable hwmon as default, @@ -290,8 +289,8 @@ static int bcm2835_thermal_probe(struct platform_device *pdev) static int bcm2835_thermal_remove(struct platform_device *pdev) { - struct thermal_zone_device *tz = platform_get_drvdata(pdev); - struct bcm2835_thermal_data *data = tz->devdata; + struct bcm2835_thermal_data *data = platform_get_drvdata(pdev); + struct thermal_zone_device *tz = data->tz; debugfs_remove_recursive(data->debugfsdir); thermal_zone_of_sensor_unregister(&pdev->dev, tz); -- 2.7.4