am7xxx: assign device_list next to its first use
[libam7xxx.git] / src / am7xxx.c
index 08858cd..47e04bb 100644 (file)
@@ -453,8 +453,6 @@ static am7xxx_device *add_new_device(am7xxx_context *ctx)
                return NULL;
        }
 
-       devices_list = &(ctx->devices_list);
-
        new_device = malloc(sizeof(*new_device));
        if (new_device == NULL) {
                fatal("cannot allocate a new device (%s)\n", strerror(errno));
@@ -464,6 +462,8 @@ static am7xxx_device *add_new_device(am7xxx_context *ctx)
 
        new_device->ctx = ctx;
 
+       devices_list = &(ctx->devices_list);
+
        if (*devices_list == NULL) {
                *devices_list = new_device;
        } else {