summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2010-06-03 10:13:29 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2010-06-17 08:28:25 +0200
commitc3789cd49b43ec1c414ba1b0e9f48e8ccc19f8e1 (patch)
tree8df082be53b5f2538956daf5e3c0295eff58de23 /net
parent57e1fc33bda4f4f215bdaa7ebb2a79cc5aac3799 (diff)
downloadbarebox-c3789cd49b43ec1c414ba1b0e9f48e8ccc19f8e1.tar.gz
barebox-c3789cd49b43ec1c414ba1b0e9f48e8ccc19f8e1.tar.xz
rework device parameters
Change device parameters so that the memory management is in generic code. This also removes the need of storing statically initialized parameters as they are stored in a struct list_head for each device. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'net')
-rw-r--r--net/eth.c48
1 files changed, 14 insertions, 34 deletions
diff --git a/net/eth.c b/net/eth.c
index fc16233be3..4d58191214 100644
--- a/net/eth.c
+++ b/net/eth.c
@@ -102,11 +102,13 @@ static int eth_set_ethaddr(struct device_d *dev, struct param_d *param, const ch
struct eth_device *edev = dev->type_data;
char ethaddr[sizeof("xx:xx:xx:xx:xx:xx")];
+ if (!val)
+ return dev_param_set_generic(dev, param, NULL);
+
if (string_to_ethaddr(val, ethaddr) < 0)
return -EINVAL;
- free(param->value);
- param->value = strdup(val);
+ dev_param_set_generic(dev, param, val);
edev->set_ethaddr(edev, ethaddr);
@@ -121,11 +123,13 @@ static int eth_set_ipaddr(struct device_d *dev, struct param_d *param, const cha
struct eth_device *edev = dev->type_data;
IPaddr_t ip;
+ if (!val)
+ return dev_param_set_generic(dev, param, NULL);
+
if (string_to_ip(val, &ip))
return -EINVAL;
- free(param->value);
- param->value = strdup(val);
+ dev_param_set_generic(dev, param, val);
if (edev == eth_current)
net_update_env();
@@ -148,21 +152,11 @@ int eth_register(struct eth_device *edev)
register_device(&edev->dev);
dev->type_data = edev;
- edev->param_ip.name = "ipaddr";
- edev->param_ip.set = &eth_set_ipaddr;
- edev->param_ethaddr.name = "ethaddr";
- edev->param_ethaddr.set = &eth_set_ethaddr;
- edev->param_gateway.name = "gateway";
- edev->param_gateway.set = &eth_set_ipaddr;
- edev->param_netmask.name = "netmask";
- edev->param_netmask.set = &eth_set_ipaddr;
- edev->param_serverip.name = "serverip";
- edev->param_serverip.set = &eth_set_ipaddr;
- dev_add_param(dev, &edev->param_ip);
- dev_add_param(dev, &edev->param_ethaddr);
- dev_add_param(dev, &edev->param_gateway);
- dev_add_param(dev, &edev->param_netmask);
- dev_add_param(dev, &edev->param_serverip);
+ dev_add_param(dev, "ipaddr", eth_set_ipaddr, NULL, 0);
+ dev_add_param(dev, "ethaddr", eth_set_ethaddr, NULL, 0);
+ dev_add_param(dev, "gateway", eth_set_ipaddr, NULL, 0);
+ dev_add_param(dev, "netmask", eth_set_ipaddr, NULL, 0);
+ dev_add_param(dev, "serverip", eth_set_ipaddr, NULL, 0);
edev->init(edev);
@@ -182,21 +176,7 @@ int eth_register(struct eth_device *edev)
void eth_unregister(struct eth_device *edev)
{
- if (edev->param_ip.value)
- free(edev->param_ip.value);
- if (edev->param_ethaddr.value)
- free(edev->param_ethaddr.value);
- if (edev->param_gateway.value)
- free(edev->param_gateway.value);
- if (edev->param_netmask.value)
- free(edev->param_netmask.value);
- if (edev->param_serverip.value)
- free(edev->param_serverip.value);
-
- if (eth_current == edev) {
- eth_current->halt(eth_current);
- eth_current = NULL;
- }
+ dev_remove_parameters(&edev->dev);
list_del(&edev->list);
}