[PATCH] adjust the order of some statements for better check

Li Jian jian.li at tieto.com
Mon Jan 10 18:26:48 PST 2011


device: adjust the orders of some statements for better check

In order to fastly find the crash reason, DBG() should be in the front of functions to prevent NULL points. 

---
 src/device.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/device.c b/src/device.c
index 6eef940..6f01a34 100644
--- a/src/device.c
+++ b/src/device.c
@@ -1009,11 +1009,12 @@ void __connman_device_decrease_connections(struct connman_device *device)
 int connman_device_add_network(struct connman_device *device,
 					struct connman_network *network)
 {
-	const char *identifier = connman_network_get_identifier(network);
+	const char *identifier;
 	int err;
 
 	DBG("device %p network %p", device, network);
 
+	identifier = connman_network_get_identifier(network);
 	if (identifier == NULL)
 		return -EINVAL;
 
@@ -1173,11 +1174,12 @@ static gboolean match_driver(struct connman_device *device,
 
 static int device_probe(struct connman_element *element)
 {
-	struct connman_device *device = element->device;
+	struct connman_device *device;
 	GSList *list;
 
 	DBG("element %p name %s", element, element->name);
 
+	device = element->device;
 	if (device == NULL)
 		return -ENODEV;
 
@@ -1206,10 +1208,11 @@ static int device_probe(struct connman_element *element)
 
 static void device_remove(struct connman_element *element)
 {
-	struct connman_device *device = element->device;
+	struct connman_device *device;
 
 	DBG("element %p name %s", element, element->name);
 
+	device = element->device;
 	if (device == NULL)
 		return;
 
-- 
1.6.3.3




More information about the connman mailing list