device: make device_register() clone the device
authorJean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Mon, 1 Sep 2008 15:11:26 +0000 (17:11 +0200)
committerWolfgang Denk <wd@denx.de>
Mon, 1 Sep 2008 23:28:18 +0000 (01:28 +0200)
This is expected by the callers, but this fact was hidden well within
the old list implementation.

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
common/devices.c
include/devices.h

index 2977436420bc9d2a1fa5899994f271f33c494cb4..8beebe255f0bc088fee32412bef0d2bcf2a4078c 100644 (file)
@@ -130,10 +130,32 @@ device_t* device_get_by_name(char* name)
        return NULL;
 }
 
+device_t* device_clone(device_t *dev)
+{
+       device_t *_dev;
+
+       if(!dev)
+               return NULL;
+
+       _dev = calloc(1, sizeof(device_t));
+
+       if(!_dev)
+               return NULL;
+
+       memcpy(_dev, dev, sizeof(device_t));
+       strncpy(_dev->name, dev->name, 16);
+
+       return _dev;
+}
 
 int device_register (device_t * dev)
 {
-       list_add(&(dev->list), &(devs.list));
+       device_t *_dev;
+
+       _dev = device_clone(dev);
+       if(!_dev)
+               return -1;
+       list_add(&(_dev->list), &(devs.list));
        return 0;
 }
 
index 490016b694e9a92010cd28cdaa7ef0f0b53ddf1c..6b78d5888942faccf2c511fbd6724bcb60e9df27 100644 (file)
@@ -94,6 +94,7 @@ int   devices_init (void);
 int    device_deregister(char *devname);
 struct list_head* device_get_list(void);
 device_t* device_get_by_name(char* name);
+device_t* device_clone(device_t *dev);
 
 #ifdef CONFIG_LCD
 int    drv_lcd_init (void);