From nobody Wed Apr 1 22:19:11 2026 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 7A9733F660E for ; Wed, 1 Apr 2026 16:39: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=1775061590; cv=none; b=bPiJGHWhh7WbNhM3nY1JDq99PDvfOCQqxHklxxWOjRCaYLhIwEllek7pMK834zt4Lw44e5yP78Q76HAaQiKO1qu+q8m8I8Le/W7fd0UE6GJiyGw9FtaGrWIuOpLW2Zop/rprGzYRssV0vGl0/CXbpqw74xYbMt/DoSTCbYT9gf8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775061590; c=relaxed/simple; bh=1TxIxSJZeqZjWcOwVC4IcbBr3BCcWEp/Z6WhRzxGW5g=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=LB1Rjg3p/flCYGoTOCfTghpieEqWxIJ7Z3k/Vk7LjBUxbJsbUVMfj6Bsg+dRi2e/ai54gNVdEhF+V4E7M+FPbuWDwDOLR7O9wo1tW4ovCj55FQXAglxy1d2lemYIKDc7wxV2YXD7lEMampjj5Sg9HnE6lYKxbJwCIXKv1aSFspg= 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=s7gwxAj2; 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="s7gwxAj2" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id 9491F4E42897; Wed, 1 Apr 2026 16:39:45 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 69C5C602BF; Wed, 1 Apr 2026 16:39:45 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 123AD104509F8; Wed, 1 Apr 2026 18:39:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1775061584; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=6h2z4t90Q2l0iiaHrS3n38ggV2dCoYzcBQFCJpIsf5E=; b=s7gwxAj2fn9qFawAK9XolF70B3r6TiZPy9am6rEgShK+JvjpAFWAw5sTRgyDyBF24tqhAB PJKgPkaoTyqZubK02mlE/fK3pU3+eEGi5T+m8uiCiMkvNNatde/IfDASHBSIB07IXoGDZw DaMwJvoaML5cSkPHdNZ2DTTf0NlHzLYIoC+qotC333V32k04PNir73hPyw5CoWIebPKi4n cMkStG3DuV3LTlNSspoOtzW729ni/bhObqeJQ79BrzOObdpwRqi3VtSuTFOuYglNGwB8Vy kQPl+XFchImOc2V3S/FF/Yb52SQ5MN8+whozPgvZxfFqG8LDFeXGpG/fauObVA== From: =?utf-8?q?Th=C3=A9o_Lebrun?= Date: Wed, 01 Apr 2026 18:39:12 +0200 Subject: [PATCH net-next 09/11] net: macb: introduce macb_context_alloc() helper Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260401-macb-context-v1-9-9590c5ab7272@bootlin.com> References: <20260401-macb-context-v1-0-9590c5ab7272@bootlin.com> In-Reply-To: <20260401-macb-context-v1-0-9590c5ab7272@bootlin.com> To: Nicolas Ferre , Claudiu Beznea , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Richard Cochran , Russell King Cc: Paolo Valerio , Conor Dooley , Nicolai Buchwitz , Vladimir Kondratiev , Gregory CLEMENT , =?utf-8?q?Beno=C3=AEt_Monin?= , Tawfik Bayouk , Thomas Petazzoni , Maxime Chevallier , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Th=C3=A9o_Lebrun?= X-Mailer: b4 0.15.0 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=C3=A9o Lebrun --- drivers/net/ethernet/cadence/macb_main.c | 55 +++++++++++++++++++++-------= ---- 1 file changed, 36 insertions(+), 19 deletions(-) diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/etherne= t/cadence/macb_main.c index 47f0d27cd979..42b19b969f3e 100644 --- a/drivers/net/ethernet/cadence/macb_main.c +++ b/drivers/net/ethernet/cadence/macb_main.c @@ -2875,6 +2875,36 @@ static int macb_alloc_consistent(struct macb_context= *ctx) return -ENOMEM; } =20 +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 =3D kzalloc_obj(*ctx); + if (!ctx) + return ERR_PTR(-ENOMEM); + + ctx->info =3D &bp->info; + ctx->rx_buffer_size =3D macb_rx_buffer_size(bp, mtu); + ctx->rx_ring_size =3D rx_ring_size; + ctx->tx_ring_size =3D tx_ring_size; + + err =3D macb_alloc_consistent(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 =3D &ctx->rxq[q]; @@ -3243,27 +3273,15 @@ static int macb_open(struct net_device *netdev) if (err < 0) return err; =20 - bp->ctx =3D kzalloc_obj(*bp->ctx); - if (!bp->ctx) { - err =3D -ENOMEM; + bp->ctx =3D macb_context_alloc(bp, netdev->mtu, + bp->configured_rx_ring_size, + bp->configured_tx_ring_size); + if (IS_ERR(bp->ctx)) { + err =3D PTR_ERR(bp->ctx); + bp->ctx =3D NULL; goto pm_exit; } =20 - bp->ctx->info =3D &bp->info; - - /* RX buffers initialization */ - bp->ctx->rx_buffer_size =3D macb_rx_buffer_size(bp, netdev->mtu); - bp->ctx->rx_ring_size =3D bp->configured_rx_ring_size; - bp->ctx->tx_ring_size =3D bp->configured_tx_ring_size; - - err =3D macb_alloc_consistent(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); =20 for (q =3D 0, queue =3D bp->queues; q < bp->num_queues; ++q, ++queue) { @@ -3302,7 +3320,6 @@ static int macb_open(struct net_device *netdev) napi_disable(&queue->napi_tx); } macb_free_consistent(bp->ctx); -free_ctx: kfree(bp->ctx); bp->ctx =3D NULL; pm_exit: --=20 2.53.0