From patchwork Mon May 15 07:39:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Schulz X-Patchwork-Id: 99777 Delivered-To: patch@linaro.org Received: by 10.140.96.100 with SMTP id j91csp1424284qge; Mon, 15 May 2017 00:41:00 -0700 (PDT) X-Received: by 10.99.50.66 with SMTP id y63mr4695946pgy.41.1494834060647; Mon, 15 May 2017 00:41:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1494834060; cv=none; d=google.com; s=arc-20160816; b=0KGwNxTz1I9KTaKDi06ee2prB9pd0ZAKvnxi4cc16sugRUiohOdxFVUzerMdscGk5M eI2pWv05m3InqvaCO9+60UyEzn5lXHLTPPGotXmp/upnQ3SAJiWWSCIGakByrEtWiO2r g8beRoot+zwecs/kVOGinok0K0Tm4MHEVh8qEHByJAcMmSGGf/0FDCLTu757fv4Lrhgl k396P0MuBSApC/GniKLX/7Wh3KrN8VlVRWA1VkkKv4o2w4c992Pax9xoPwBlKO1MNhLH qM9GYvCUOf2OXEYvkzBl0mneKwBtokibQqIzJhWDbpVA3ZM+EKwS77NPeDkNPLdjgIbS xO2w== 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:cc:to:from :arc-authentication-results; bh=NR+DEDN8T+cfzjXitNJBZ4fYfl7VmOeypW8VDbfPUG0=; b=dEIl4BbWMuDHtoGLjihoyjy1jBqOQu5bl8wPQOWgkdfsG4hXZzR4sADhFqUisO8avI uGFgtlV519x3MkD54GYNCmXXy40g8mTRXgdWGvJPX6hYsjONolIiuLgDutAolAkzatJd WgclfBvw0pRSljtwybH3VcNGPD1ECwl9MqexTsqagHuzaTaFN46IPmpidYHIPgTxOPcx Bdhg9ySnQyztrnSLEzJdvXRZtWdqhtpA5hiw43ZUEbLgmduuJ+cUO+Idh9KNOyoxRO4N ESZ43g4W9CAGMm05L3PCt8+44Um0WWmcDGseGB06BkijiMN8XTRHBdyeet3RD5J4zlLp VM8A== 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 y15si10011222pfk.125.2017.05.15.00.41.00; Mon, 15 May 2017 00:41:00 -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 S1753960AbdEOHkl (ORCPT + 25 others); Mon, 15 May 2017 03:40:41 -0400 Received: from mail.free-electrons.com ([62.4.15.54]:38684 "EHLO mail.free-electrons.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751365AbdEOHkk (ORCPT ); Mon, 15 May 2017 03:40:40 -0400 Received: by mail.free-electrons.com (Postfix, from userid 110) id 72F7822139; Mon, 15 May 2017 09:40:37 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.free-electrons.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT shortcircuit=ham autolearn=disabled version=3.4.0 Received: from localhost.localdomain (LStLambert-657-1-97-87.w90-63.abo.wanadoo.fr [90.63.216.87]) by mail.free-electrons.com (Postfix) with ESMTPSA id 20F25220F3; Mon, 15 May 2017 09:40:27 +0200 (CEST) From: Quentin Schulz To: jic23@kernel.org, knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net, maxime.ripard@free-electrons.com, wens@csie.org Cc: Quentin Schulz , clabbe.montjoie@gmail.com, linux-iio@vger.kernel.org, thomas.petazzoni@free-electrons.com, linux-sunxi@googlegroups.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] iio: adc: sun4i-gpadc-iio: fix parent device being used in devm function Date: Mon, 15 May 2017 09:39:02 +0200 Message-Id: <20170515073902.25994-1-quentin.schulz@free-electrons.com> X-Mailer: git-send-email 2.11.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org For the sake of DT binding stability, this IIO driver is a child of an MFD driver for Allwinner A10, A13 and A31 because there already exists a DT binding for this IP. The MFD driver has a DT node but the IIO driver does not. The IIO device registers the temperature sensor in the thermal framework using the DT node of the parent, the MFD device, so the thermal framework could match the phandle to the MFD device in the DT and the struct device used to register in the thermal framework. devm_thermal_zone_of_sensor_register was previously used to register the thermal sensor with the parent struct device of the IIO device, representing the MFD device. By doing so, we registered actually the parent in the devm routine and not the actual IIO device. This lead to the devm unregister function not being called when the IIO module driver is removed. It resulted in the thermal framework still polling the get_temp function of the IIO module while the device doesn't exist anymore, thus generated a kernel panic. Use the non-devm function instead and do the unregister manually in the remove function. Fixes: d1caa9905538 ("iio: adc: add support for Allwinner SoCs ADC") Signed-off-by: Quentin Schulz Reported-by: Corentin Labbe --- drivers/iio/adc/sun4i-gpadc-iio.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) -- 2.11.0 diff --git a/drivers/iio/adc/sun4i-gpadc-iio.c b/drivers/iio/adc/sun4i-gpadc-iio.c index b23527309088..0d3df17be405 100644 --- a/drivers/iio/adc/sun4i-gpadc-iio.c +++ b/drivers/iio/adc/sun4i-gpadc-iio.c @@ -105,6 +105,7 @@ struct sun4i_gpadc_iio { bool no_irq; /* prevents concurrent reads of temperature and ADC */ struct mutex mutex; + struct thermal_zone_device *tzd; }; #define SUN4I_GPADC_ADC_CHANNEL(_channel, _name) { \ @@ -502,7 +503,6 @@ static int sun4i_gpadc_probe_dt(struct platform_device *pdev, { struct sun4i_gpadc_iio *info = iio_priv(indio_dev); const struct of_device_id *of_dev; - struct thermal_zone_device *tzd; struct resource *mem; void __iomem *base; int ret; @@ -532,13 +532,13 @@ static int sun4i_gpadc_probe_dt(struct platform_device *pdev, if (!IS_ENABLED(CONFIG_THERMAL_OF)) return 0; - tzd = devm_thermal_zone_of_sensor_register(&pdev->dev, 0, info, - &sun4i_ts_tz_ops); - if (IS_ERR(tzd)) + info->tzd = thermal_zone_of_sensor_register(&pdev->dev, 0, info, + &sun4i_ts_tz_ops); + if (IS_ERR(info->tzd)) dev_err(&pdev->dev, "could not register thermal sensor: %ld\n", - PTR_ERR(tzd)); + PTR_ERR(info->tzd)); - return PTR_ERR_OR_ZERO(tzd); + return PTR_ERR_OR_ZERO(info->tzd); } static int sun4i_gpadc_probe_mfd(struct platform_device *pdev, @@ -584,15 +584,14 @@ static int sun4i_gpadc_probe_mfd(struct platform_device *pdev, * of_node, and the device from this driver as third argument to * return the temperature. */ - struct thermal_zone_device *tzd; - tzd = devm_thermal_zone_of_sensor_register(pdev->dev.parent, 0, - info, - &sun4i_ts_tz_ops); - if (IS_ERR(tzd)) { + info->tzd = thermal_zone_of_sensor_register(pdev->dev.parent, 0, + info, + &sun4i_ts_tz_ops); + if (IS_ERR(info->tzd)) { dev_err(&pdev->dev, "could not register thermal sensor: %ld\n", - PTR_ERR(tzd)); - return PTR_ERR(tzd); + PTR_ERR(info->tzd)); + return PTR_ERR(info->tzd); } } else { indio_dev->num_channels = @@ -688,6 +687,12 @@ static int sun4i_gpadc_remove(struct platform_device *pdev) pm_runtime_put(&pdev->dev); pm_runtime_disable(&pdev->dev); + + if (pdev->dev.of_node) + thermal_zone_of_sensor_unregister(&pdev->dev, info->tzd); + else + thermal_zone_of_sensor_unregister(pdev->dev.parent, info->tzd); + if (!info->no_irq && IS_ENABLED(CONFIG_THERMAL_OF)) iio_map_array_unregister(indio_dev);