From: Quentin Schulz <quentin.schulz@free-electrons.com>
To: Maxime Ripard <maxime.ripard@free-electrons.com>
Cc: jic23@kernel.org, knaack.h@gmx.de, lars@metafoo.de,
pmeerw@pmeerw.net, wens@csie.org, 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: Re: [PATCH] iio: adc: sun4i-gpadc-iio: fix parent device being used in devm function
Date: Mon, 15 May 2017 11:18:45 +0200 [thread overview]
Message-ID: <73eb7674-dba9-8bdf-c886-6ad8177f4c1b@free-electrons.com> (raw)
In-Reply-To: <20170515091148.gk2zvtjy5bdpbfzt@flea.home>
[-- Attachment #1.1: Type: text/plain, Size: 2743 bytes --]
Hi Maxime,
On 15/05/2017 11:11, Maxime Ripard wrote:
> On Mon, May 15, 2017 at 09:39:02AM +0200, Quentin Schulz wrote:
>> 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 <quentin.schulz@free-electrons.com>
>> Reported-by: Corentin Labbe <clabbe.montjoie@gmail.com>
>> ---
[...]
>> @@ -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);
>> +
>
> Can't we just store the device used to create the zone in the
> structure as well, that would avoid that non-trivial logic.
>
Yes we could.
I've that same condition in the probe function, if pdev->dev.of_node
then I continue in the probe dedicated to device probed from DT, or I
continue with the probe dedicated to device probed via MFD.
The thermal_zone_of_sensor_register is different in those two functions,
thus, I thought that it would make more sense to replicate the same
condition in the remove to make the relation between the device used in
thermal_zone_of_sensor_register and unregister clear.
That's just a matter of taste for me, so I'm definitely ok to write a v2
for this change.
Thanks,
Quentin
--
Quentin Schulz, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 801 bytes --]
next prev parent reply other threads:[~2017-05-15 9:18 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-15 7:39 Quentin Schulz
2017-05-15 9:11 ` Maxime Ripard
2017-05-15 9:18 ` Quentin Schulz [this message]
2017-05-16 9:30 ` Maxime Ripard
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=73eb7674-dba9-8bdf-c886-6ad8177f4c1b@free-electrons.com \
--to=quentin.schulz@free-electrons.com \
--cc=clabbe.montjoie@gmail.com \
--cc=jic23@kernel.org \
--cc=knaack.h@gmx.de \
--cc=lars@metafoo.de \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sunxi@googlegroups.com \
--cc=maxime.ripard@free-electrons.com \
--cc=pmeerw@pmeerw.net \
--cc=thomas.petazzoni@free-electrons.com \
--cc=wens@csie.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®