Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1374784
| From | Jonathan Cameron <jic23@kernel.org> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH 1/3] iio: core: Add devm_ APIs for iio_channel_{get,release} |
| Date | 2016-04-10 16:10 +0200 |
| Message-ID | <rmodQ-6er-15@gated-at.bofh.it> (permalink) |
| References | <rkTc5-2vd-9@gated-at.bofh.it> <rkW0h-4AR-11@gated-at.bofh.it> <rkXpn-5RF-1@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
On 06/04/16 15:58, Laxman Dewangan wrote:
> Hi Daniel,
>
>
> On Wednesday 06 April 2016 07:19 PM, Daniel Baluta wrote:
>> On Wed, Apr 6, 2016 at 1:31 PM, Laxman Dewangan <ldewangan@nvidia.com> wrote:
>>> Some of kernel driver uses the IIO framework to get the sensor
>>> value via ADC or IIO HW driver. The client driver get iio channel
>>> by iio_channel_get() and release it by calling iio_channel_release().
>>>
>>> Add resource managed version (devm_*) of these APIs so that if client
>>> calls the devm_iio_channel_get() then it need not to release it explicitly,
>>> it can be done by managed device framework when driver get un-binded.
>>>
>>> This reduces the code in error path and also need of .remove callback in
>>> some cases.
>>>
>> Please provide at least one example of code that uses this API.
>
> Most of client for this APIs are in other subsystem.
> When I was working on the patch
> [PATCH 2/2] thermal: generic-adc: Add ADC based thermal sensor driver
>
> if I have devm_iio_channel_get() then I can get .remove callback at all.
>
> I did not use this new APIs in my patch because they are in different subsystem.
It's actually worse than that having taken a quick look at the generic-adc thermal patch
you reference above.
(perhaps worth cc'ing linux-iio for next version of that).
Without this devm function set you have a race in remove in which I think you can
get attempts to access the channels after they have been released...
> +
> + gti->tz_dev = devm_thermal_zone_of_sensor_register(&pdev->dev, 0,
> + gti, &gadc_thermal_ops);
> + if (IS_ERR(gti->tz_dev)) {
> + ret = PTR_ERR(gti->tz_dev);
> + dev_err(&pdev->dev, "Thermal zone sensor register failed: %d\n",
> + ret);
> + goto sensor_fail;
> + }
This will get cleaned up in remove 'after' the iio_channels are released.
Hence you have a race in which they can probably be accessed after release
(unless some magic is going on that I've missed).
> +
> + return 0;
> +
> +sensor_fail:
> + iio_channel_release(gti->channel);
> + return ret;
> +}
> +
> +static int gadc_thermal_remove(struct platform_device *pdev)
> +{
> + struct gadc_thermal_info *gti = platform_get_drvdata(pdev);
> +
> + iio_channel_release(gti->channel);
> +
> + return 0;
> +}
> +
>
>
>
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH 1/3] iio: core: Add devm_ APIs for iio_channel_{get,release} Laxman Dewangan <ldewangan@nvidia.com> - 2016-04-06 12:50 +0200
Re: [PATCH 1/3] iio: core: Add devm_ APIs for iio_channel_{get,release} Daniel Baluta <daniel.baluta@gmail.com> - 2016-04-06 15:50 +0200
Re: [PATCH 1/3] iio: core: Add devm_ APIs for iio_channel_{get,release} Laxman Dewangan <ldewangan@nvidia.com> - 2016-04-06 17:20 +0200
Re: [PATCH 1/3] iio: core: Add devm_ APIs for iio_channel_{get,release} Jonathan Cameron <jic23@kernel.org> - 2016-04-10 16:10 +0200
Re: [PATCH 1/3] iio: core: Add devm_ APIs for iio_channel_{get,release} Laxman Dewangan <ldewangan@nvidia.com> - 2016-04-10 19:50 +0200
Re: [PATCH 1/3] iio: core: Add devm_ APIs for iio_channel_{get,release} Jonathan Cameron <jic23@kernel.org> - 2016-04-10 16:10 +0200
csiph-web