iio: at91-sama5d2: Fix incorrect cast to platform_device
authorLars-Peter Clausen <lars@metafoo.de>
Tue, 19 Oct 2021 08:29:28 +0000 (10:29 +0200)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Wed, 17 Nov 2021 17:51:39 +0000 (17:51 +0000)
commit907b2ad8c9acad39ac1f0ccdbbe66c63856055e3
tree144f453ce43060b689226be4cf7b188aff665812
parenteb0469894ba788ffdc81097b7dea822432e479d9
iio: at91-sama5d2: Fix incorrect cast to platform_device

The at91-sama5d2 driver calls `to_platform_device()` on a struct device
that is part of a IIO device. This is incorrect since
`to_platform_device()` must only be called on a struct device that is part
of a platform device.

The code still works by accident because non of the struct platform_device
specific fields are accessed.

Refactor the code a bit so that it behaves identically, but does not use
the incorrect cast. This avoids accidentally adding undefined behavior in
the future by assuming the `struct platform_device` is actually valid.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Tested-by: Eugen Hristev <eugen.hristev@microchip.com>
Link: https://lore.kernel.org/r/20211019082929.30503-1-lars@metafoo.de
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/adc/at91-sama5d2_adc.c