spi: Add the flag indicate to registe new device as children of master or not.
PATCH 1/1 spi: Add the flag indicate to registe new device as children of master or not.
Because there are two aim when allocating the new device, one is for children of master, other is for master. So this patch add one flag to indicate different purpose.
--- drivers/spi/spi.c | 16 +++++++++++----- include/linux/spi/spi.h | 3 ++- 2 files changed, 13 insertions(+), 6 deletions(-)
drivers/spi/spi.c +11 -5
@@ -300,6 +300,8 @@ static DEFINE_MUTEX(board_lock);/** * spi_alloc_device - Allocate a new SPI device * @master: Controller to which device is connected +* device_was_children_of_master is flag which the device is registed +* as the children of the bus * Context: can sleep * * Allows a driver to allocate and initialize a spi_device without
@@ -314,7 +316,8 @@ static DEFINE_MUTEX(board_lock);* * Returns a pointer to the new device, or NULL. */ -struct spi_device *spi_alloc_device (struct spi_master *master) +struct spi_device *spi_alloc_device (struct spi_master *master, +bool device_was_children_of_master) {struct spi_device *spi;struct device *dev = master->dev.parent;
@@ -330,7 +333,10 @@ struct spi_device *spi_alloc_device(struct spi_master *master) } spi->master = master; - spi->dev.parent = &master->dev; +if (device_was_children_of_master == true) + spi->dev.parent = &master->dev; +else + spi->dev.parent = dev; spi->dev.bus = &spi_bus_type; spi->dev.release = spidev_release;device_initialize (&spi->dev);
@@ -434,7 +440,7 @@ struct spi_device *spi_new_device(struct spi_master *master,* suggests syslogged diagnostics are best here (ugh). */ - proxy =spi_alloc_device (master); + proxy =spi_alloc_device (master, false);if (!proxy)return NULL ;
@@ -827,7 +833,7 @@ static void of_register_spi_devices(struct spi_master *master)for_each_available_child_of_node (master->dev.of_node, nc) {/* Alloc an spi_device */ - spi =spi_alloc_device (master); + spi =spi_alloc_device (master, true);if (!spi) {dev_err (&master->dev,"spi_device alloc error for %s\n" , nc->full_name);
@@ -939,7 +945,7 @@ static acpi_status acpi_spi_add_device(acpi_handle handle, u32 level,if (acpi_bus_get_status (adev) || !adev->status.present)return AE_OK ; - spi =spi_alloc_device (master); + spi =spi_alloc_device (master, false);if (!spi) {dev_err (&master->dev,"failed to allocate SPI device for %s\n" ,dev_name (&adev->dev));
include/linux/spi/spi.h +2 -1
@@ -838,7 +838,8 @@ spi_register_board_info(struct spi_board_info const *info, unsigned n)* be defined using the board info. */ extern struct spi_device * -spi_alloc_device (struct spi_master *master); +spi_alloc_device (struct spi_master *master, +bool device_was_children_of_master);extern int spi_add_device (struct spi_device *spi);
Signature · 1 line
1.7.4.1
Quoted 3 lines · Jun Chen
* @master: Controller to which device is connected
+ *device_was_children_of_masteris flag which the device is registed
+ * as the children of the bus
This isn't a kerneldoc style comment (it needs the @XXX: format). The name is also extremely long, can't we think of something more concise?
drivers/spi/spi.c struct spi_device *spi_alloc_device(struct spi_master *master) · line 339
Quoted 5 lines
drivers/spi/spi.c +4
-1- spi->dev.parent = &master->dev; +if (device_was_children_of_master == true) + spi->dev.parent = &master->dev; +else + spi->dev.parent = dev;
Can you provide an example of where this is useful? Your changelog didn't make it clear and the code doesn't make it obvious either.
Quoted 9 lines · Mark Brown
Quoted 3 lines · Jun Chen
* @master: Controller to which device is connected
+ *device_was_children_of_masteris flag which the device is registed
+ * as the children of the busThis isn't a kerneldoc style comment (it needs the @XXX: format). The name is also extremely long, can't we think of something more concise?
Thank for your suggestion, I will correct this comment and use concise flag.
Quoted 8 lines
drivers/spi/spi.c struct spi_device *spi_alloc_device(struct spi_master *master) · line 339
Quoted 5 lines
drivers/spi/spi.c +4
-1- spi->dev.parent = &master->dev; +if (device_was_children_of_master == true) + spi->dev.parent = &master->dev; +else + spi->dev.parent = dev;Can you provide an example of where this is useful? Your changelog didn't make it clear and the code doesn't make it obvious either.
This spi_alloc_device function will be called in the spi_new_device function to alloc new device as the master. But other way, it is called by the of_register_spi_devices function to register new device as the children of the master. I will update changlog to add it.
@@ -434,7 +440,7 @@ struct spi_device *spi_new_device(struct spi_master *master,
* suggests syslogged diagnostics are best here (ugh). */
- proxy = spi_alloc_device(master);
+ proxy = spi_alloc_device(master, false);
if (!proxy)
return NULL;@@ -827,7 +833,7 @@ static void of_register_spi_devices(struct spi_master *master)
for_each_available_child_of_node(master->dev.of_node, nc) {
/* Alloc an spi_device */- spi = spi_alloc_device(master);
+ spi = spi_alloc_device(master, true);
If I have mistake, pls correct me, thanks!
Quoted 4 lines · Jun Chen
This
spi_alloc_devicefunction will be called in thespi_new_devicefunction to alloc new device as the master. But other way, it is called by theof_register_spi_devicesfunction to register new device as the children of the master. I will update changlog to add it.
But why is this a bad thing? You've said what's happening but not why it's a problem.
Quoted 9 lines · Mark Brown
Quoted 4 lines · Jun Chen
This
spi_alloc_devicefunction will be called in thespi_new_devicefunction to alloc new device as the master. But other way, it is called by theof_register_spi_devicesfunction to register new device as the children of the master. I will update changlog to add it.But why is this a bad thing? You've said what's happening but not why it's a problem.
spi_devices should always be children of the spi_master. If that is not the case then it is a bug to be fixed.
g.
Signature · 9 lines
Grant Likely, B.Sc, P.Eng. Secret Lab Technologies, Ltd. ------------------------------------------------------------------------------ LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial Remotely access PCs and mobile devices and provide instant support Improve your efficiency, and focus on delivering more value-add services Discover what IT Professionals Know. Rescue delivers http://p.sf.net/sfu/logmein_12329d2d
Quoted 8 lines · Grant Likely
Quoted 7 lines · Mark Brown
Quoted 4 lines · Jun Chen
This
spi_alloc_devicefunction will be called in thespi_new_devicefunction to alloc new device as the master. But other way, it is called by theof_register_spi_devicesfunction to register new device as the children of the master. I will update changlog to add it.
Quoted 6 lines
Quoted 2 lines
But why is this a bad thing? You've said what's happening but not why it's a problem.
spi_devicesshould always be children of thespi_master. If that is not the case then it is a bug to be fixed.
When many boards initializing, boards will call function spi_register_board_info to create bi->board_info,Then spi driver probe to call spi_register_master to register the driver and in the function spi_match_master_to_boardinfo To create new spi device, and this cases the spi_devices are not children of the spi_master.
Many drivers do these steps. If all spi_devices must be children of the spi_master, Do spi core have plan to delete this way?
Or spi core can hold this way for many drivers.
Thanks!
Quoted 16 lines · Jun Chen
Quoted 8 lines · Grant Likely
Quoted 7 lines · Mark Brown
Quoted 4 lines · Jun Chen
This
spi_alloc_devicefunction will be called in thespi_new_devicefunction to alloc new device as the master. But other way, it is called by theof_register_spi_devicesfunction to register new device as the children of the master. I will update changlog to add it.Quoted 6 lines
Quoted 2 lines
But why is this a bad thing? You've said what's happening but not why it's a problem.
spi_devicesshould always be children of thespi_master. If that is not the case then it is a bug to be fixed.
Quoted 8 lines
When many boards initializing, boards will call function
spi_register_board_infoto create bi->board_info,Then spi driver probe to callspi_register_masterto register the driver and in the functionspi_match_master_to_boardinfoTo create new spi device, and this cases thespi_devicesare not children of thespi_master.
Many drivers do these steps. If allspi_devicesmust be children of thespi_master, Do spi core have plan to delete this way?
Or spi core can hold this way for many drivers.
Let me make sure I understand what you're saying...
Right now, every spi_device object is registered as a child of an spi_master object.
With this proposed patch, spi_devices registered via spi_register_board_info will be siblings of the spi_master instead of children.
Do I understand correctly so far?
The problem is that I don't understand why this change is necessary. spi_devices should always be children of an spi_master, not siblings. What is the problem you're trying to solve with this change?
g.
Quoted 28 lines · Grant Likely
Quoted 16 lines · Jun Chen
Quoted 8 lines · Grant Likely
Quoted 7 lines · Mark Brown
Quoted 4 lines · Jun Chen
This
spi_alloc_devicefunction will be called in thespi_new_devicefunction to alloc new device as the master. But other way, it is called by theof_register_spi_devicesfunction to register new device as the children of the master. I will update changlog to add it.Quoted 6 lines
Quoted 2 lines
But why is this a bad thing? You've said what's happening but not why it's a problem.
spi_devicesshould always be children of thespi_master. If that is not the case then it is a bug to be fixed.Quoted 8 lines
When many boards initializing, boards will call function
spi_register_board_infoto create bi->board_info,Then spi driver probe to callspi_register_masterto register the driver and in the functionspi_match_master_to_boardinfoTo create new spi device, and this cases thespi_devicesare not children of thespi_master.
Many drivers do these steps. If allspi_devicesmust be children of thespi_master, Do spi core have plan to delete this way?
Or spi core can hold this way for many drivers.Let me make sure I understand what you're saying...
Quoted 8 lines
Right now, every
spi_deviceobject is registered as a child of anspi_masterobject.With this proposed patch,
spi_devicesregistered viaspi_register_board_infowill be siblings of thespi_masterinstead of children.Do I understand correctly so far?
Yes,
Quoted 4 lines
The problem is that I don't understand why this change is necessary.
spi_devicesshould always be children of anspi_master, not siblings. What is the problem you're trying to solve with this change?
When spi drivers try to use the core function(spi_register_master),it will trigger error,because they use the function spi_match_master_to_boardinfo to create new spi device as the children of the master.
In the old version of spi core, the new devices are registered as siblings of the spi_master. My spi driver based on the old version runs normal.
But after applying for this patch:
{
spi: Fix device unregistration when unregistering the bus master
Device are added as children of the bus master's parent device, but spi_unregister_master() looks for devices to unregister in the bus master's children. This results in the child devices not being unregistered.
Fix this by registering devices as direct children of the bus
master.
- spi->dev.parent = dev;
+ spi->dev.parent = &master->dev;
}
Then my driver will be crash.
Maybe I have mistake on this issue, thank for your more explanation and detail replay.
Quoted 2 lines
g.
Quoted 30 lines · Jun Chen
Quoted 4 lines · Grant Likely
The problem is that I don't understand why this change is necessary.
spi_devicesshould always be children of anspi_master, not siblings. What is the problem you're trying to solve with this change?When spi drivers try to use the core function(spi_register_master),it will trigger error,because they use the function
spi_match_master_to_boardinfoto create new spi device as the children of the master.
In the old version of spi core, the new devices are registered as siblings of thespi_master. My spi driver based on the old version runs normal.But after applying for this patch:
{
spi: Fix device unregistration when unregistering the bus masterDevice are added as children of the bus master's parent device, but
spi_unregister_master()looks for devices to unregister in the bus master's children. This results in the child devices not being unregistered.Fix this by registering devices as direct children of the bus
master.(quoted diff) +1
-1- spi->dev.parent = dev; + spi->dev.parent = &master->dev;}
Quoted 3 lines
Then my driver will be crash.
Maybe I have mistake on this issue, thank for your more explanation and detail replay.
Sounds like you've got a driver bug. Make sure it isn't trying to use the spi_client parent pointer to find the device instance.
g.