From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A22EE4921B2; Wed, 1 Jul 2026 15:59:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.85.4 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782921589; cv=none; b=Ickh3DRPC7TZZgW/o9bSzqH+/xEna6LJ3laY/iZSfjZCUHf0TFbO+a/Guv1HfdPcrytzvpRKgQAniW5Zae9Qp33BeESdC+nGOGjdhBV8AeVI1WS9NOXc+u0Csb1V3ZwdIqmfG+WYHbzBUXJr5av1XllOcTsKwNNmqLgMn/Bj170= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782921589; c=relaxed/simple; bh=/tosRwyljAFm0dVI7ttz96XN6e4tMrMz/YEez7DL39g=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Agle6SfiImYEIWhmHGBfY7xajx5W49+jmuUQaTFuu5Dnq+EdzDmBzpf64OzL9FFEPjgpE7UeIsMYRiuqR+tb+ZO4rgccYGCzjQkUO7ZcQX7SpgGI8tpR9hsDpYX7NYRvA+MpNUvXev8P+Vyu/Kzg0Q5Ad9ExjdKz1B/i+9ySJ9g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=iFhoTTiD; arc=none smtp.client-ip=185.246.85.4 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="iFhoTTiD" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id 809B14E40BF7; Wed, 1 Jul 2026 15:59:46 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 51E7F60288; Wed, 1 Jul 2026 15:59:46 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id AABEA104C967F; Wed, 1 Jul 2026 17:59:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1782921584; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=ZK0SBCPOmMsy53Y1bHnVws/BlPpbIuDko15goBEzumc=; b=iFhoTTiDGZpWvZSvLJhFYyya3vH8DVp5HkgWiR1R5yzqtlGvnVG840vjStA4tlpW/vXj1g aW5Iou0Z+hqkskVee+rq41pkytdmq/NlNfny4TgwC6S2tgHKEvDCacXXlo3r/ViRu9fTbX HAANqq0m11unbGh0vmh/7Vjk0odfpmBsrGhmDIFxFGwvzjSdul9tP8Pe7ZVcdr+usgKQeK tympAGRmHxtdiR3rytdyLx+93kWDxIhdhZ47rp0nALnWwaLKi5Fy8Udpy7K39eImxoH08c 7s+kYY/MAw/LBqM1drCH1tNoY9LZPCoMw/WtBlq0/h+wPpTt0Iy6mR/z5Q5RLw== From: =?utf-8?q?Th=C3=A9o_Lebrun?= Date: Wed, 01 Jul 2026 17:59:15 +0200 Subject: [PATCH net-next v3 12/15] net: macb: introduce macb_context_alloc() helper Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Message-Id: <20260701-macb-context-v3-12-00268d5b1502@bootlin.com> References: <20260701-macb-context-v3-0-00268d5b1502@bootlin.com> In-Reply-To: <20260701-macb-context-v3-0-00268d5b1502@bootlin.com> To: =?utf-8?q?Th=C3=A9o_Lebrun?= , Conor Dooley , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Richard Cochran , Russell King Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Nicolas Ferre , Claudiu Beznea , Paolo Valerio , Nicolai Buchwitz , Vladimir Kondratiev , Gregory CLEMENT , =?utf-8?q?Beno=C3=AEt_Monin?= , Tawfik Bayouk , Thomas Petazzoni , Maxime Chevallier X-Mailer: b4 0.15.2 X-Last-TLS-Session-Version: TLSv1.3 Move the context allocation sequence from inline macb_open() to its own helper function called macb_context_alloc(). All ops doing context swapping (set_ringparam, change_mtu, etc) will use this helper. Signed-off-by: Théo Lebrun --- drivers/net/ethernet/cadence/macb_main.c | 56 +++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 19 deletions(-) diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c index 8163df4719b2..7245c345c78f 100644 --- a/drivers/net/ethernet/cadence/macb_main.c +++ b/drivers/net/ethernet/cadence/macb_main.c @@ -2849,6 +2849,36 @@ static int macb_alloc(struct macb_context *ctx) return -ENOMEM; } +static struct macb_context *macb_context_alloc(struct macb *bp, + unsigned int mtu, + unsigned int rx_ring_size, + unsigned int tx_ring_size) +{ + struct macb_context *ctx; + int err; + + ctx = kzalloc_obj(*ctx); + if (!ctx) + return ERR_PTR(-ENOMEM); + + ctx->info = &bp->info; + ctx->rx_buffer_size = macb_rx_buffer_size(bp, mtu); + ctx->rx_ring_size = rx_ring_size; + ctx->tx_ring_size = tx_ring_size; + + err = macb_alloc(ctx); + if (err) { + netdev_err(bp->netdev, + "Unable to allocate DMA memory (error %d)\n", err); + kfree(ctx); + return ERR_PTR(err); + } + + bp->macbgem_ops.mog_init_rings(ctx); + + return ctx; +} + static void gem_init_rx_ring(struct macb_context *ctx, unsigned int q) { struct macb_rxq *rxq = &ctx->rxq[q]; @@ -3216,27 +3246,15 @@ static int macb_open(struct net_device *netdev) if (err < 0) return err; - bp->ctx = kzalloc_obj(*bp->ctx); - if (!bp->ctx) { - err = -ENOMEM; + bp->ctx = macb_context_alloc(bp, netdev->mtu, + bp->configured_rx_ring_size, + bp->configured_tx_ring_size); + if (IS_ERR(bp->ctx)) { + err = PTR_ERR(bp->ctx); + bp->ctx = NULL; goto pm_exit; } - bp->ctx->info = &bp->info; - - /* RX buffers initialization */ - bp->ctx->rx_buffer_size = macb_rx_buffer_size(bp, netdev->mtu); - bp->ctx->rx_ring_size = bp->configured_rx_ring_size; - bp->ctx->tx_ring_size = bp->configured_tx_ring_size; - - err = macb_alloc(bp->ctx); - if (err) { - netdev_err(netdev, "Unable to allocate DMA memory (error %d)\n", - err); - goto free_ctx; - } - - bp->macbgem_ops.mog_init_rings(bp->ctx); macb_init_buffers(bp); for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) { @@ -3275,7 +3293,6 @@ static int macb_open(struct net_device *netdev) napi_disable(&queue->napi_tx); } macb_free(bp->ctx); -free_ctx: kfree(bp->ctx); bp->ctx = NULL; pm_exit: @@ -5158,6 +5175,7 @@ static int at91ether_open(struct net_device *netdev) ret = -ENOMEM; goto pm_exit; } + bp->ctx->info = &bp->info; /* Clear internal statistics */ ctl = macb_readl(bp, NCR); -- 2.55.0