devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Robin Murphy <robin.murphy@arm.com>
To: Stefan Wahren <stefan.wahren@i2se.com>,
	Rob Herring <robh+dt@kernel.org>,
	Guenter Roeck <linux@roeck-us.net>, Eric Anholt <eric@anholt.net>,
	Mark Rutland <mark.rutland@arm.com>,
	Jonathan Corbet <corbet@lwn.net>,
	Jean Delvare <jdelvare@suse.com>
Cc: linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org,
	"Florian Fainelli" <f.fainelli@gmail.com>,
	"Scott Branden" <sbranden@broadcom.com>,
	linux-doc@vger.kernel.org, "Ray Jui" <rjui@broadcom.com>,
	"Phil Elwell" <phil@raspberrypi.org>,
	"Noralf Trønnes" <noralf@tronnes.org>,
	bcm-kernel-feedback-list@broadcom.com,
	linux-rpi-kernel@lists.infradead.org,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH RFC V2 2/6] hwmon: Add support for RPi voltage sensor
Date: Wed, 23 May 2018 13:12:10 +0100	[thread overview]
Message-ID: <cbbdab47-cde3-7a7c-c797-c00d546e00d5@arm.com> (raw)
In-Reply-To: <723014352.17580.1527017480381@email.1und1.de>

On 22/05/18 20:31, Stefan Wahren wrote:
[...]
>>>>> +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.

Robin.

  reply	other threads:[~2018-05-23 12:12 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-22 11:21 [PATCH RFC V2 0/6] hwmon: Add support for Raspberry Pi voltage sensor Stefan Wahren
2018-05-22 11:21 ` [PATCH RFC V2 1/6] ARM: bcm2835: Add GET_THROTTLED firmware property Stefan Wahren
2018-05-22 11:21 ` [PATCH RFC V2 2/6] hwmon: Add support for RPi voltage sensor Stefan Wahren
2018-05-22 13:41   ` Guenter Roeck
2018-05-22 13:51     ` Stefan Wahren
2018-05-22 14:10       ` Guenter Roeck
2018-05-22 19:31         ` Stefan Wahren
2018-05-23 12:12           ` Robin Murphy [this message]
2018-05-23 18:12             ` Guenter Roeck
2018-05-22 11:21 ` [PATCH RFC V2 3/6] firmware: raspberrypi: Register hwmon driver Stefan Wahren
2018-05-22 11:21 ` [PATCH RFC V2 4/6] ARM: bcm2835_defconfig: Enable RPi voltage sensor Stefan Wahren
2018-05-22 11:21 ` [PATCH RFC V2 5/6] ARM: multi_v7_defconfig: " Stefan Wahren
2018-05-22 11:21 ` [PATCH RFC V2 6/6] arm64: defconfig: " Stefan Wahren

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=cbbdab47-cde3-7a7c-c797-c00d546e00d5@arm.com \
    --to=robin.murphy@arm.com \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=corbet@lwn.net \
    --cc=devicetree@vger.kernel.org \
    --cc=eric@anholt.net \
    --cc=f.fainelli@gmail.com \
    --cc=jdelvare@suse.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-rpi-kernel@lists.infradead.org \
    --cc=linux@roeck-us.net \
    --cc=mark.rutland@arm.com \
    --cc=noralf@tronnes.org \
    --cc=phil@raspberrypi.org \
    --cc=rjui@broadcom.com \
    --cc=robh+dt@kernel.org \
    --cc=sbranden@broadcom.com \
    --cc=stefan.wahren@i2se.com \
    /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;
as well as URLs for NNTP newsgroup(s).