Re: [PATCH 1/2] driver core:add device's platform_data set for faux device
From: Zongmin Zhou
Date: Thu May 08 2025 - 22:42:54 EST
On 2025/5/8 17:45, Greg KH wrote:
On Thu, May 08, 2025 at 05:11:47PM +0800, Zongmin Zhou wrote:
From: Zongmin Zhou <zhouzongmin@xxxxxxxxxx>
Most drivers based on platform bus may have specific data
for the device.And will get this specific data to use
after device added.
So keep the setting for device's platform_data is necessary
for converting platform device to faux device.
I do not understand, why not just use the platform_data field directly
in the faux device structure? Why change all callers to now have to
keep track of an additional pointer in these create functions? That
just adds complexity for everyone when almost no one will need it.
In fact, I have tried other approaches.
However, I found that it must be set after creating faux_dev and before
calling the device_add() function.
Because the execution of the driver init and the device probe function
is asynchronous,
and the actual test shows that the probe function is executed
before faux_device_create_with_groups () returns faux_device for the caller.
But the probe and related functions may need to get plat_data.If
plat_data is set after
faux_device_create_with_groups() is completed and fdev is returned, the
probe function will get NULL.
Take vhci-hcd as an example:
vhci_hcd_init() calls faux_device_create_with_groups(),
Once device_add() is called, vhci_hcd_probe() will be executed immediately.
Therefore, the probe function will attempt to obtain plat_data
before vhci_hcd_init() receives the return value of faux_device.
It's too late to set plat_data after get the return value of faux_device.
If there is anything not clearly or other good ways to handle this,
please let me know.
Thanks very much.
thanks,
greg k-h