Browse Source

Merge pull request #1987 from enkiller/dev

[components][drivers][wlan] Modify wlan device registration interface
Bernard Xiong 6 years ago
parent
commit
2ca5995160
2 changed files with 7 additions and 12 deletions
  1. 5 11
      components/drivers/wlan/wlan_dev.c
  2. 2 1
      components/drivers/wlan/wlan_dev.h

+ 5 - 11
components/drivers/wlan/wlan_dev.c

@@ -733,22 +733,16 @@ static rt_err_t _rt_wlan_dev_control(rt_device_t dev, int cmd, void *args)
     return err;
 }
 
-struct rt_wlan_device *rt_wlan_dev_register(const char *name, const struct rt_wlan_dev_ops *ops, rt_uint32_t flag, void *user_data)
+rt_err_t rt_wlan_dev_register(struct rt_wlan_device *wlan, const char *name, const struct rt_wlan_dev_ops *ops, rt_uint32_t flag, void *user_data)
 {
-    struct rt_wlan_device *wlan;
+    rt_err_t err = RT_EOK;
 
-    if (name == RT_NULL || ops == RT_NULL)
+    if ((wlan == RT_NULL) || (name == RT_NULL) || (ops == RT_NULL))
     {
         LOG_E("F:%s L:%d parameter Wrongful", __FUNCTION__, __LINE__);
         return RT_NULL;
     }
 
-    wlan = rt_malloc(sizeof(struct rt_wlan_device));
-    if (wlan == RT_NULL)
-    {
-        LOG_E("F:%s L:%d", __FUNCTION__, __LINE__);
-        return RT_NULL;
-    }
     rt_memset(wlan, 0, sizeof(struct rt_wlan_device));
 
     wlan->device.init       = _rt_wlan_dev_init;
@@ -765,9 +759,9 @@ struct rt_wlan_device *rt_wlan_dev_register(const char *name, const struct rt_wl
     wlan->user_data  = user_data;
 
     wlan->flags = flag;
-    rt_device_register(&wlan->device, name, RT_DEVICE_FLAG_RDWR);
+    err = rt_device_register(&wlan->device, name, RT_DEVICE_FLAG_RDWR);
 
     LOG_D("F:%s L:%d run", __FUNCTION__, __LINE__);
 
-    return wlan;
+    return err;
 }

+ 2 - 1
components/drivers/wlan/wlan_dev.h

@@ -576,7 +576,8 @@ rt_err_t rt_wlan_dev_report_data(struct rt_wlan_device *device, void *buff, int
 /*
  * wlan device register interface
  */
-struct rt_wlan_device *rt_wlan_dev_register(const char *name, const struct rt_wlan_dev_ops *ops, rt_uint32_t flag, void *user_data);
+rt_err_t rt_wlan_dev_register(struct rt_wlan_device *wlan, const char *name, 
+    const struct rt_wlan_dev_ops *ops, rt_uint32_t flag, void *user_data);
 
 #ifdef __cplusplus
 }