linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christophe Leroy <christophe.leroy@csgroup.eu>
To: Rasmus Villemoes <rasmus.villemoes@prevas.dk>,
	Li Yang <leoyang.li@nxp.com>,
	"David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>
Cc: Vladimir Oltean <vladimir.oltean@nxp.com>,
	linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
	linuxppc-dev@lists.ozlabs.org, Zhao Qiang <qiang.zhao@nxp.com>
Subject: Re: [PATCH 14/20] ethernet: ucc_geth: don't statically allocate eight ucc_geth_info
Date: Tue, 8 Dec 2020 16:13:15 +0100	[thread overview]
Message-ID: <8259bec3-9343-82e3-a420-a8170cf922a4@csgroup.eu> (raw)
In-Reply-To: <20201205191744.7847-15-rasmus.villemoes@prevas.dk>



Le 05/12/2020 à 20:17, Rasmus Villemoes a écrit :
> 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>
> ---
>   drivers/net/ethernet/freescale/ucc_geth.c | 32 +++++++++--------------
>   1 file changed, 12 insertions(+), 20 deletions(-)
> 
> diff --git a/drivers/net/ethernet/freescale/ucc_geth.c b/drivers/net/ethernet/freescale/ucc_geth.c
> index a06744d8b4af..273342233bba 100644
> --- a/drivers/net/ethernet/freescale/ucc_geth.c
> +++ b/drivers/net/ethernet/freescale/ucc_geth.c
> @@ -157,8 +157,6 @@ static const struct ucc_geth_info ugeth_primary_info = {
>   	.riscRx = QE_RISC_ALLOCATION_RISC1_AND_RISC2,
>   };
>   
> -static struct ucc_geth_info ugeth_info[8];
> -
>   #ifdef DEBUG
>   static void mem_disp(u8 *addr, int size)
>   {
> @@ -3714,25 +3712,23 @@ static int ucc_geth_probe(struct platform_device* ofdev)
>   	if ((ucc_num < 0) || (ucc_num > 7))
>   		return -ENODEV;
>   
> -	ug_info = &ugeth_info[ucc_num];
> -	if (ug_info == NULL) {
> -		if (netif_msg_probe(&debug))
> -			pr_err("[%d] Missing additional data!\n", ucc_num);
> -		return -ENODEV;
> -	}
> +	ug_info = kmalloc(sizeof(*ug_info), GFP_KERNEL);

Could we use dev_kmalloc() instead, to avoid the freeing on the wait out and the err_free_info: path ?

> +	if (ug_info == NULL)
> +		return -ENOMEM;
> +	memcpy(ug_info, &ugeth_primary_info, sizeof(*ug_info));
>   
>   	ug_info->uf_info.ucc_num = ucc_num;
>   
>   	err = ucc_geth_parse_clock(np, "rx", &ug_info->uf_info.rx_clock);
>   	if (err)
> -		return err;
> +		goto err_free_info;
>   	err = ucc_geth_parse_clock(np, "tx", &ug_info->uf_info.tx_clock);
>   	if (err)
> -		return err;
> +		goto err_free_info;
>   
>   	err = of_address_to_resource(np, 0, &res);
>   	if (err)
> -		return -EINVAL;
> +		goto err_free_info;
>   
>   	ug_info->uf_info.regs = res.start;
>   	ug_info->uf_info.irq = irq_of_parse_and_map(np, 0);
> @@ -3745,7 +3741,7 @@ static int ucc_geth_probe(struct platform_device* ofdev)
>   		 */
>   		err = of_phy_register_fixed_link(np);
>   		if (err)
> -			return err;
> +			goto err_free_info;
>   		ug_info->phy_node = of_node_get(np);
>   	}
>   
> @@ -3876,6 +3872,8 @@ static int ucc_geth_probe(struct platform_device* ofdev)
>   		of_phy_deregister_fixed_link(np);
>   	of_node_put(ug_info->tbi_node);
>   	of_node_put(ug_info->phy_node);
> +err_free_info:
> +	kfree(ug_info);
>   
>   	return err;
>   }
> @@ -3886,6 +3884,7 @@ static int ucc_geth_remove(struct platform_device* ofdev)
>   	struct ucc_geth_private *ugeth = netdev_priv(dev);
>   	struct device_node *np = ofdev->dev.of_node;
>   
> +	kfree(ugeth->ug_info);
>   	ucc_geth_memclean(ugeth);
>   	if (of_phy_is_fixed_link(np))
>   		of_phy_deregister_fixed_link(np);
> @@ -3920,17 +3919,10 @@ static struct platform_driver ucc_geth_driver = {
>   
>   static int __init ucc_geth_init(void)
>   {
> -	int i, ret;
> -
>   	if (netif_msg_drv(&debug))
>   		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)
> 

  reply	other threads:[~2020-12-08 15:14 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-05 19:17 [PATCH 00/20] ethernet: ucc_geth: assorted fixes and simplifications Rasmus Villemoes
2020-12-05 19:17 ` [PATCH 01/20] ethernet: ucc_geth: set dev->max_mtu to 1518 Rasmus Villemoes
2020-12-10  1:25   ` Andrew Lunn
2021-01-05 14:17     ` Joakim Tjernlund
2021-01-05 14:33       ` Andrew Lunn
2021-01-05 14:44         ` Joakim Tjernlund
2021-01-05 14:54           ` Andrew Lunn
2020-12-05 19:17 ` [PATCH 02/20] ethernet: ucc_geth: fix definition and size of ucc_geth_tx_global_pram Rasmus Villemoes
2020-12-08 19:14   ` Li Yang
2020-12-08 20:12     ` Rasmus Villemoes
2020-12-05 19:17 ` [PATCH 03/20] ethernet: ucc_geth: remove unused read of temoder field Rasmus Villemoes
2020-12-05 19:17 ` [PATCH 04/20] soc: fsl: qe: make cpm_muram_offset take a const void* argument Rasmus Villemoes
2020-12-05 19:17 ` [PATCH 05/20] soc: fsl: qe: store muram_vbase as a void pointer instead of u8 Rasmus Villemoes
2020-12-05 19:17 ` [PATCH 06/20] soc: fsl: qe: add cpm_muram_free_addr() helper Rasmus Villemoes
2020-12-05 19:17 ` [PATCH 07/20] ethernet: ucc_geth: use qe_muram_free_addr() Rasmus Villemoes
2020-12-10  1:36   ` Andrew Lunn
2020-12-05 19:17 ` [PATCH 08/20] ethernet: ucc_geth: remove unnecessary memset_io() calls Rasmus Villemoes
2020-12-05 19:17 ` [PATCH 09/20] ethernet: ucc_geth: replace kmalloc+memset by kzalloc Rasmus Villemoes
2020-12-05 19:17 ` [PATCH 10/20] ethernet: ucc_geth: remove {rx,tx}_glbl_pram_offset from struct ucc_geth_private Rasmus Villemoes
2020-12-05 19:17 ` [PATCH 11/20] ethernet: ucc_geth: fix use-after-free in ucc_geth_remove() Rasmus Villemoes
2020-12-05 20:48   ` Jakub Kicinski
2020-12-05 21:04     ` Rasmus Villemoes
2020-12-05 21:19       ` Jakub Kicinski
2020-12-05 21:35         ` Rasmus Villemoes
2020-12-05 21:50       ` Rasmus Villemoes
2020-12-05 19:17 ` [PATCH 12/20] ethernet: ucc_geth: factor out parsing of {rx,tx}-clock{,-name} properties Rasmus Villemoes
2020-12-05 19:17 ` [PATCH 13/20] ethernet: ucc_geth: constify ugeth_primary_info Rasmus Villemoes
2020-12-05 19:17 ` [PATCH 14/20] ethernet: ucc_geth: don't statically allocate eight ucc_geth_info Rasmus Villemoes
2020-12-08 15:13   ` Christophe Leroy [this message]
2020-12-08 21:17     ` Rasmus Villemoes
2020-12-05 19:17 ` [PATCH 15/20] ethernet: ucc_geth: use UCC_GETH_{RX,TX}_BD_RING_ALIGNMENT macros directly Rasmus Villemoes
2020-12-08 15:14   ` [PATCH 15/20] ethernet: ucc_geth: use UCC_GETH_{RX, TX}_BD_RING_ALIGNMENT " Christophe Leroy
2020-12-05 19:17 ` [PATCH 16/20] ethernet: ucc_geth: remove bd_mem_part and all associated code Rasmus Villemoes
2020-12-05 19:17 ` [PATCH 17/20] ethernet: ucc_geth: replace kmalloc_array()+for loop by kcalloc() Rasmus Villemoes
2020-12-05 19:17 ` [PATCH 18/20] ethernet: ucc_geth: add helper to replace repeated switch statements Rasmus Villemoes
2020-12-08 15:21   ` Christophe Leroy
2020-12-08 20:55     ` Rasmus Villemoes
2020-12-05 19:17 ` [PATCH 19/20] ethernet: ucc_geth: inform the compiler that numQueues is always 1 Rasmus Villemoes
2020-12-05 19:17 ` [PATCH 20/20] ethernet: ucc_geth: simplify rx/tx allocations Rasmus Villemoes
2020-12-05 20:53 ` [PATCH 00/20] ethernet: ucc_geth: assorted fixes and simplifications Jakub Kicinski
2020-12-05 21:11   ` Rasmus Villemoes
2020-12-05 21:27     ` Jakub Kicinski
2020-12-05 21:36       ` Rasmus Villemoes
2020-12-10  7:52       ` Rasmus Villemoes
2020-12-08  3:07     ` Qiang Zhao
2020-12-08  8:13       ` Rasmus Villemoes

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8259bec3-9343-82e3-a420-a8170cf922a4@csgroup.eu \
    --to=christophe.leroy@csgroup.eu \
    --cc=davem@davemloft.net \
    --cc=kuba@kernel.org \
    --cc=leoyang.li@nxp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=netdev@vger.kernel.org \
    --cc=qiang.zhao@nxp.com \
    --cc=rasmus.villemoes@prevas.dk \
    --cc=vladimir.oltean@nxp.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).