From: Felix Fietkau Date: Tue, 18 Oct 2011 16:18:24 +0000 (+0200) Subject: directly pass the device name to the device create function X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=39b97d17479a1767fefdf693bb41141260d9740c;p=oweals%2Fnetifd.git directly pass the device name to the device create function --- diff --git a/bridge.c b/bridge.c index 5ac5cfe..fe4b477 100644 --- a/bridge.c +++ b/bridge.c @@ -41,7 +41,7 @@ static const struct config_param_list bridge_attr_list = { .next = { &device_attr_list }, }; -static struct device *bridge_create(struct blob_attr *attr); +static struct device *bridge_create(const char *name, struct blob_attr *attr); static void bridge_config_init(struct device *dev); static void bridge_free(struct device *dev); static void bridge_dump_info(struct device *dev, struct blob_buf *b); @@ -364,27 +364,21 @@ bridge_apply_settings(struct bridge_state *bst, struct blob_attr **tb) } static struct device * -bridge_create(struct blob_attr *attr) +bridge_create(const char *name, struct blob_attr *attr) { struct blob_attr *tb_dev[__DEV_ATTR_MAX]; struct blob_attr *tb_br[__BRIDGE_ATTR_MAX]; struct bridge_state *bst; struct device *dev = NULL; - const char *name; blobmsg_parse(device_attr_list.params, __DEV_ATTR_MAX, tb_dev, blob_data(attr), blob_len(attr)); blobmsg_parse(bridge_attrs, __BRIDGE_ATTR_MAX, tb_br, blob_data(attr), blob_len(attr)); - if (!tb_dev[DEV_ATTR_NAME]) - return NULL; - if (!tb_br[BRIDGE_ATTR_IFNAME]) return NULL; - name = blobmsg_data(tb_dev[DEV_ATTR_NAME]); - bst = calloc(1, sizeof(*bst)); if (!bst) return NULL; diff --git a/device.c b/device.c index 092a8ed..4d0de67 100644 --- a/device.c +++ b/device.c @@ -19,7 +19,6 @@ static struct avl_tree devices; static const struct blobmsg_policy dev_attrs[__DEV_ATTR_MAX] = { [DEV_ATTR_TYPE] = { "type", BLOBMSG_TYPE_STRING }, - [DEV_ATTR_NAME] = { "name", BLOBMSG_TYPE_STRING }, [DEV_ATTR_IFNAME] = { "ifname", BLOBMSG_TYPE_ARRAY }, [DEV_ATTR_MTU] = { "mtu", BLOBMSG_TYPE_INT32 }, [DEV_ATTR_MACADDR] = { "macaddr", BLOBMSG_TYPE_STRING }, @@ -32,20 +31,12 @@ const struct config_param_list device_attr_list = { }; static struct device * -simple_device_create(struct blob_attr *attr) +simple_device_create(const char *name, struct blob_attr *attr) { struct blob_attr *tb[__DEV_ATTR_MAX]; struct device *dev = NULL; - const char *name; blobmsg_parse(dev_attrs, __DEV_ATTR_MAX, tb, blob_data(attr), blob_len(attr)); - if (!tb[DEV_ATTR_NAME]) - return NULL; - - name = blobmsg_data(tb[DEV_ATTR_NAME]); - if (!name) - return NULL; - dev = device_get(name, true); if (!dev) return NULL; @@ -455,7 +446,7 @@ device_create(const char *name, const struct device_type *type, } else D(DEVICE, "Create new device '%s' (%s)\n", name, type->name); - dev = type->create(config); + dev = type->create(name, config); if (!dev) return NULL; diff --git a/device.h b/device.h index 659bcf1..8d610c9 100644 --- a/device.h +++ b/device.h @@ -11,7 +11,6 @@ typedef int (*device_state_cb)(struct device *, bool up); enum { DEV_ATTR_TYPE, - DEV_ATTR_NAME, DEV_ATTR_IFNAME, DEV_ATTR_MTU, DEV_ATTR_MACADDR, @@ -31,7 +30,7 @@ struct device_type { const struct config_param_list *config_params; - struct device *(*create)(struct blob_attr *attr); + struct device *(*create)(const char *name, struct blob_attr *attr); void (*config_init)(struct device *); enum dev_change_type (*reload)(struct device *, struct blob_attr *); void (*dump_info)(struct device *, struct blob_buf *buf);