Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Rasmus Villemoes and committed by
Jakub Kicinski
baff4311 b0292e08

+12 -20
+12 -20
drivers/net/ethernet/freescale/ucc_geth.c
··· 157 157 .riscRx = QE_RISC_ALLOCATION_RISC1_AND_RISC2, 158 158 }; 159 159 160 - static struct ucc_geth_info ugeth_info[8]; 161 - 162 160 #ifdef DEBUG 163 161 static void mem_disp(u8 *addr, int size) 164 162 { ··· 3713 3715 if ((ucc_num < 0) || (ucc_num > 7)) 3714 3716 return -ENODEV; 3715 3717 3716 - ug_info = &ugeth_info[ucc_num]; 3717 - if (ug_info == NULL) { 3718 - if (netif_msg_probe(&debug)) 3719 - pr_err("[%d] Missing additional data!\n", ucc_num); 3720 - return -ENODEV; 3721 - } 3718 + ug_info = kmalloc(sizeof(*ug_info), GFP_KERNEL); 3719 + if (ug_info == NULL) 3720 + return -ENOMEM; 3721 + memcpy(ug_info, &ugeth_primary_info, sizeof(*ug_info)); 3722 3722 3723 3723 ug_info->uf_info.ucc_num = ucc_num; 3724 3724 3725 3725 err = ucc_geth_parse_clock(np, "rx", &ug_info->uf_info.rx_clock); 3726 3726 if (err) 3727 - return err; 3727 + goto err_free_info; 3728 3728 err = ucc_geth_parse_clock(np, "tx", &ug_info->uf_info.tx_clock); 3729 3729 if (err) 3730 - return err; 3730 + goto err_free_info; 3731 3731 3732 3732 err = of_address_to_resource(np, 0, &res); 3733 3733 if (err) 3734 - return -EINVAL; 3734 + goto err_free_info; 3735 3735 3736 3736 ug_info->uf_info.regs = res.start; 3737 3737 ug_info->uf_info.irq = irq_of_parse_and_map(np, 0); ··· 3742 3746 */ 3743 3747 err = of_phy_register_fixed_link(np); 3744 3748 if (err) 3745 - return err; 3749 + goto err_free_info; 3746 3750 ug_info->phy_node = of_node_get(np); 3747 3751 } 3748 3752 ··· 3873 3877 of_phy_deregister_fixed_link(np); 3874 3878 of_node_put(ug_info->tbi_node); 3875 3879 of_node_put(ug_info->phy_node); 3880 + err_free_info: 3881 + kfree(ug_info); 3876 3882 3877 3883 return err; 3878 3884 } ··· 3891 3893 of_phy_deregister_fixed_link(np); 3892 3894 of_node_put(ugeth->ug_info->tbi_node); 3893 3895 of_node_put(ugeth->ug_info->phy_node); 3896 + kfree(ugeth->ug_info); 3894 3897 free_netdev(dev); 3895 3898 3896 3899 return 0; ··· 3920 3921 3921 3922 static int __init ucc_geth_init(void) 3922 3923 { 3923 - int i, ret; 3924 - 3925 3924 if (netif_msg_drv(&debug)) 3926 3925 pr_info(DRV_DESC "\n"); 3927 - for (i = 0; i < 8; i++) 3928 - memcpy(&(ugeth_info[i]), &ugeth_primary_info, 3929 - sizeof(ugeth_primary_info)); 3930 3926 3931 - ret = platform_driver_register(&ucc_geth_driver); 3932 - 3933 - return ret; 3927 + return platform_driver_register(&ucc_geth_driver); 3934 3928 } 3935 3929 3936 3930 static void __exit ucc_geth_exit(void)