Commit baff4311 authored by Rasmus Villemoes's avatar Rasmus Villemoes Committed by Jakub Kicinski

ethernet: ucc_geth: don't statically allocate eight ucc_geth_info

struct ucc_geth_info is somewhat large, and on systems with only one
or two UCC instances, that just wastes a few KB of memory. So
allocate and populate a chunk of memory at probe time instead of
initializing them all during driver init.

Note that the existing "ug_info == NULL" check was dead code, as the
address of some static array element can obviously never be NULL.
Signed-off-by: default avatarRasmus Villemoes <rasmus.villemoes@prevas.dk>
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent b0292e08
...@@ -157,8 +157,6 @@ static const struct ucc_geth_info ugeth_primary_info = { ...@@ -157,8 +157,6 @@ static const struct ucc_geth_info ugeth_primary_info = {
.riscRx = QE_RISC_ALLOCATION_RISC1_AND_RISC2, .riscRx = QE_RISC_ALLOCATION_RISC1_AND_RISC2,
}; };
static struct ucc_geth_info ugeth_info[8];
#ifdef DEBUG #ifdef DEBUG
static void mem_disp(u8 *addr, int size) static void mem_disp(u8 *addr, int size)
{ {
...@@ -3715,25 +3713,23 @@ static int ucc_geth_probe(struct platform_device* ofdev) ...@@ -3715,25 +3713,23 @@ static int ucc_geth_probe(struct platform_device* ofdev)
if ((ucc_num < 0) || (ucc_num > 7)) if ((ucc_num < 0) || (ucc_num > 7))
return -ENODEV; return -ENODEV;
ug_info = &ugeth_info[ucc_num]; ug_info = kmalloc(sizeof(*ug_info), GFP_KERNEL);
if (ug_info == NULL) { if (ug_info == NULL)
if (netif_msg_probe(&debug)) return -ENOMEM;
pr_err("[%d] Missing additional data!\n", ucc_num); memcpy(ug_info, &ugeth_primary_info, sizeof(*ug_info));
return -ENODEV;
}
ug_info->uf_info.ucc_num = ucc_num; ug_info->uf_info.ucc_num = ucc_num;
err = ucc_geth_parse_clock(np, "rx", &ug_info->uf_info.rx_clock); err = ucc_geth_parse_clock(np, "rx", &ug_info->uf_info.rx_clock);
if (err) if (err)
return err; goto err_free_info;
err = ucc_geth_parse_clock(np, "tx", &ug_info->uf_info.tx_clock); err = ucc_geth_parse_clock(np, "tx", &ug_info->uf_info.tx_clock);
if (err) if (err)
return err; goto err_free_info;
err = of_address_to_resource(np, 0, &res); err = of_address_to_resource(np, 0, &res);
if (err) if (err)
return -EINVAL; goto err_free_info;
ug_info->uf_info.regs = res.start; ug_info->uf_info.regs = res.start;
ug_info->uf_info.irq = irq_of_parse_and_map(np, 0); ug_info->uf_info.irq = irq_of_parse_and_map(np, 0);
...@@ -3746,7 +3742,7 @@ static int ucc_geth_probe(struct platform_device* ofdev) ...@@ -3746,7 +3742,7 @@ static int ucc_geth_probe(struct platform_device* ofdev)
*/ */
err = of_phy_register_fixed_link(np); err = of_phy_register_fixed_link(np);
if (err) if (err)
return err; goto err_free_info;
ug_info->phy_node = of_node_get(np); ug_info->phy_node = of_node_get(np);
} }
...@@ -3877,6 +3873,8 @@ static int ucc_geth_probe(struct platform_device* ofdev) ...@@ -3877,6 +3873,8 @@ static int ucc_geth_probe(struct platform_device* ofdev)
of_phy_deregister_fixed_link(np); of_phy_deregister_fixed_link(np);
of_node_put(ug_info->tbi_node); of_node_put(ug_info->tbi_node);
of_node_put(ug_info->phy_node); of_node_put(ug_info->phy_node);
err_free_info:
kfree(ug_info);
return err; return err;
} }
...@@ -3893,6 +3891,7 @@ static int ucc_geth_remove(struct platform_device* ofdev) ...@@ -3893,6 +3891,7 @@ static int ucc_geth_remove(struct platform_device* ofdev)
of_phy_deregister_fixed_link(np); of_phy_deregister_fixed_link(np);
of_node_put(ugeth->ug_info->tbi_node); of_node_put(ugeth->ug_info->tbi_node);
of_node_put(ugeth->ug_info->phy_node); of_node_put(ugeth->ug_info->phy_node);
kfree(ugeth->ug_info);
free_netdev(dev); free_netdev(dev);
return 0; return 0;
...@@ -3921,17 +3920,10 @@ static struct platform_driver ucc_geth_driver = { ...@@ -3921,17 +3920,10 @@ static struct platform_driver ucc_geth_driver = {
static int __init ucc_geth_init(void) static int __init ucc_geth_init(void)
{ {
int i, ret;
if (netif_msg_drv(&debug)) if (netif_msg_drv(&debug))
pr_info(DRV_DESC "\n"); pr_info(DRV_DESC "\n");
for (i = 0; i < 8; i++)
memcpy(&(ugeth_info[i]), &ugeth_primary_info,
sizeof(ugeth_primary_info));
ret = platform_driver_register(&ucc_geth_driver);
return ret; return platform_driver_register(&ucc_geth_driver);
} }
static void __exit ucc_geth_exit(void) static void __exit ucc_geth_exit(void)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment