From: Viresh Kumar Date: Thu, 4 Jun 2015 12:46:45 +0000 (+0530) Subject: greybus: Tear down devices in the reverse order X-Git-Tag: v4.9-rc1~119^2~378^2~21^2~1488 X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=928f2abd5ff12fa4851b762df7c32e749e846b7c;p=karo-tx-linux.git greybus: Tear down devices in the reverse order Normally, its a good practice to free resources in the reverse order in which they are allocated, so that all the dependencies can be sorted out properly. This is true while creating/destroying devices as well. For example consider this scenario (I faced a crash with control protocol due to this). For a new module, we will first create a bundle+connection for the control cport and then create other bundles/connections after parsing manifest. And while destroying interface on module hot unplug, we are removing the devices in the order they are added. And so the bundle/connection for the control cport are destroyed first. But, control cport was still required while destroying other bundles/connections. To solve this problem, lets destroy the resources in the reverse order in which they are added. Signed-off-by: Viresh Kumar Reviewed-by: Alex Elder Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/staging/greybus/bundle.c b/drivers/staging/greybus/bundle.c index 2047e173ebd9..a6b1b347097a 100644 --- a/drivers/staging/greybus/bundle.c +++ b/drivers/staging/greybus/bundle.c @@ -196,7 +196,7 @@ struct gb_bundle *gb_bundle_create(struct gb_interface *intf, u8 bundle_id, } spin_lock_irq(&gb_bundles_lock); - list_add_tail(&bundle->links, &intf->bundles); + list_add(&bundle->links, &intf->bundles); spin_unlock_irq(&gb_bundles_lock); return bundle; diff --git a/drivers/staging/greybus/connection.c b/drivers/staging/greybus/connection.c index a774f677279a..5ab744b14a0d 100644 --- a/drivers/staging/greybus/connection.c +++ b/drivers/staging/greybus/connection.c @@ -213,8 +213,8 @@ struct gb_connection *gb_connection_create(struct gb_bundle *bundle, "protocol 0x%02hhx handler not found\n", protocol_id); spin_lock_irq(&gb_connections_lock); - list_add_tail(&connection->hd_links, &hd->connections); - list_add_tail(&connection->bundle_links, &bundle->connections); + list_add(&connection->hd_links, &hd->connections); + list_add(&connection->bundle_links, &bundle->connections); spin_unlock_irq(&gb_connections_lock); atomic_set(&connection->op_cycle, 0); diff --git a/drivers/staging/greybus/interface.c b/drivers/staging/greybus/interface.c index 7a4c7dc2e941..3483f848240b 100644 --- a/drivers/staging/greybus/interface.c +++ b/drivers/staging/greybus/interface.c @@ -122,7 +122,7 @@ static struct gb_interface *gb_interface_create(struct greybus_host_device *hd, } spin_lock_irq(&gb_interfaces_lock); - list_add_tail(&intf->links, &hd->interfaces); + list_add(&intf->links, &hd->interfaces); spin_unlock_irq(&gb_interfaces_lock); return intf;