Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4463116imu; Tue, 29 Jan 2019 01:53:30 -0800 (PST) X-Google-Smtp-Source: ALg8bN58XZpmZp5gAAXwirnk4IlUKcjlPa2jnL4HCx3MuFMMSr/9+L2AQDD95+01eANW20yv0CIg X-Received: by 2002:a63:101:: with SMTP id 1mr23077898pgb.152.1548755610612; Tue, 29 Jan 2019 01:53:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548755610; cv=none; d=google.com; s=arc-20160816; b=u3ThUuUhLMNAoqOWNZA4PuPVsoa4CTcJbUhWFDgTTP7JO5lipkhnB14zAzuTLklC6a FGg++Q4iS48fXG2Gt1r84WjQJ4GtcdDaZ2O5wnpGkLlHImrIQ0DUuh6TlAY8xzJ8HHpf FDKGMGSXr+vQnwdbXqVgHrBYXsawZtZGk0anCetrHMZkXluQRR5BG8kNUYUBBFiUvd9q mzGc8ttVXnHhOZ2BNi4ce8fPB9hbbSv/ZfqLiRW8O9CH9DRyz6CU9MHQuwGuGzSdpJOz 8q3a7VHZ7XPWjGwohDhTJFbvGBJKCb1kw0ppyAPlFtw7xJV9cWBR+8XQg6b+NrBxZ2Up FA7g== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:to:subject:dkim-signature; bh=UTxLBj/MYU9MxfJEFlYDKK3fCMuYTOx/SGGih3Hwt2k=; b=MT0W+YljvL8B1ROGHVRuvd+qne8cMrwPIMaOhyvZ3iWgSsRwNvoGlmIzr7TmOEDxzW ZpTaxw9kIf2WmeTRaqWhKed73RKEZE9M3tBVQnXvMcAcg9nb+F5Sazb0RqDDy+ZcPO/+ krBOVQAVdWN9dKTUY30LD6i37gbgCO2C2EA4O7GC+REgyhAsTdp09I8/hxwtdprU5qbG I4mcHuB/tyrTnO9/zJ3oNnlZnDkl2DDapXH//ko8q2VCghCNavxrQamC7eLX4GV9PHBK RUbwe51jzaTNPY9MjWhb0hGKEtXI1W8KVe7wenHm7nxJ8ZOeGeQJSSaeb3hkskyQbO6C P0Qg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XgP9wfWy; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y18si33801409plp.269.2019.01.29.01.53.15; Tue, 29 Jan 2019 01:53:30 -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=@linaro.org header.s=google header.b=XgP9wfWy; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728265AbfA2JxB (ORCPT + 99 others); Tue, 29 Jan 2019 04:53:01 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:37504 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726531AbfA2JxA (ORCPT ); Tue, 29 Jan 2019 04:53:00 -0500 Received: by mail-wr1-f65.google.com with SMTP id s12so21260561wrt.4 for ; Tue, 29 Jan 2019 01:52:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=UTxLBj/MYU9MxfJEFlYDKK3fCMuYTOx/SGGih3Hwt2k=; b=XgP9wfWyd4KRcH1WQNHn4XVNvtZjwS/wTrf/8bKXR8gRdtnDQm8Cid9qXhNhKiJi++ tnqo7+w7G4d7dEUeZSBBzjtv4mCX0AvcKb6TXCTfPQoAnHqzJAHi9cTnfrzZgWNmqT6h YuHQGiD2lhJut8OMOoaur9mGG7GbIyM0B27wA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=UTxLBj/MYU9MxfJEFlYDKK3fCMuYTOx/SGGih3Hwt2k=; b=BkZWIoIDFydWl18FOEVqBMEHVQ9IEUDc6X8lSzfiIsyZv0s5Kj+NTl11VktOMKlCxL iIDSKJ5wk1tGRKng9aridq73cnMH4qGbWNKwq+N8B6UQ2NPgZqADkK3b1jM0QzEgzsRX 8UrMy+9nCItDVEr5LkO671ZrJmQq8jR5f9yWyGHwo0KY5T7Ue2dFqCVdt1yYmuuosIFk Al2+DODMNUtoc+iX4yG5iutd9ZxL3JoVKEBvLXPxOzb1S5gLKMiWcvhPKeB6KrjnZqiD /xjiuXGNCZBUD7h/jMtqp7K42qZae0bzfLN0g4w4L/VjR9glJ2KgymMnxCgV385Jnk0C q3ZQ== X-Gm-Message-State: AJcUukel5+jS23zuscqzAYwuRqXWDYbGv0RW5yOrOvWkCK68pFEPAy/C mKBojR32Sg23NEUW+YnaODUw6H2y0CY= X-Received: by 2002:adf:ee89:: with SMTP id b9mr26130032wro.246.1548755578216; Tue, 29 Jan 2019 01:52:58 -0800 (PST) Received: from [192.168.0.41] (sju31-1-78-210-255-2.fbx.proxad.net. [78.210.255.2]) by smtp.googlemail.com with ESMTPSA id 126sm1992494wmd.1.2019.01.29.01.52.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Jan 2019 01:52:57 -0800 (PST) Subject: Re: [PATCH] thermal: bcm2835: Fix crash in bcm2835_thermal_debugfs To: Phil Elwell , Eric Anholt , Stefan Wahren , Florian Fainelli , bcm-kernel-feedback-list@broadcom.com, Geert Uytterhoeven , linux-pm@vger.kernel.org, linux-rpi-kernel@lists.infradead.org, linux-kernel@vger.kernel.org References: <1548753048-78735-1-git-send-email-phil@raspberrypi.org> From: Daniel Lezcano Message-ID: Date: Tue, 29 Jan 2019 10:52:56 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <1548753048-78735-1-git-send-email-phil@raspberrypi.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 29/01/2019 10:10, Phil Elwell wrote: > "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 Reviewed-by: Daniel Lezcano One question: do you really want the thermal driver to be loaded as a module ? Don't you want to have it operational as soon as possible instead of waiting the OS to boot and load the kernel module? If a module format is not needed, then the thermal_zone field won't be needed anymore because the 'remove' ops can be removed and the need of the tz field to unregister it disappears. > --- > 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); > -- Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog