Thread (13 messages) 13 messages, 3 authors, 2018-05-23

[PATCH RFC V2 2/6] hwmon: Add support for RPi voltage sensor

From: linux@roeck-us.net (Guenter Roeck)
Date: 2018-05-23 18:12:21
Also in: linux-devicetree, linux-doc, linux-hwmon

On Wed, May 23, 2018 at 01:12:10PM +0100, Robin Murphy wrote:
On 22/05/18 20:31, Stefan Wahren wrote:
[...]
quoted
quoted
quoted
quoted
quoted
+static int rpi_hwmon_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct rpi_hwmon_data *data;
+	int ret;
+
+	data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
+	if (!data)
+		return -ENOMEM;
+
+	data->fw = platform_get_drvdata(to_platform_device(dev->parent));
+	if (!data->fw)
+		return -EPROBE_DEFER;
+
I am a bit at loss here (and sorry I didn't bring this up before).
How would this ever be possible, given that the driver is registered
from the firmware driver ?
Do you refer to the (wrong) return code, the assumption that the parent must be a platform driver or a possible race?
The return code is one thing. My question was how the driver would ever be instantiated
with platform_get_drvdata(to_platform_device(dev->parent)) == NULL (but dev->parent != NULL),
so I referred to the race. But, sure, a second question would be how that would indicate
that the parent is not instantiated yet (which by itself seems like an odd question).
This shouldn't happen and worth a log error. In patch #3 the registration is called after the complete private data of the firmware driver is initialized. Did i missed something?

But i must confess that i didn't test all builtin/module combinations.
The point is that, by construction, a "raspberrypi-hwmon" device will only
ever be created for this driver to bind to if the firmware device is both
fully initialised and known to support the GET_THROTTLED call already. Thus
trying to check those again from the hwmon driver is at best pointless, and
at worst misleading. If somebody *does* manage to bind this driver to some
random inappropriate device, you've still got no guarantee that dev->parent
is valid or that dev_get_drvdata(dev->parent)) won't return something
non-NULL that isn't a struct rpi_firmware pointer, at which point you're
liable to pass the paranoid check yet still crash anyway.

IOW, you can't reasonably defend against incorrect operation, and under
correct operation there's nothing to defend against, so either way it's
pretty futile to waste effort trying.
Well said.

Guenter
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help