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 566C43B42F1 for ; Wed, 12 Aug 2026 08:04:17 +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=1786521858; cv=none; b=K/AHSWQpa0Yma7Zt1HwOvYzCfkl9IphN2MY0k9KL4Bh0fIfSmpDVAVGplzC499f9UetJ3RwRu16b39I+hkM8zx/CfBr0Vka9fWPNv0Do8P7QnFeK5AOD636Xn2rb++DqlV6FOOLyIDE2MpZcBkvQFISBEaX1PkCeiq0I9dMrscA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786521858; c=relaxed/simple; bh=7AsXl8lJbBWdWWyo4O+DB9JFzUUrFqzhUNJAuLWiaKI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=LhGK2ktI2CsvaL5leeN9Jggr+kRebGA4Ur4zWd3nWuGiv+P/SxeYnv9XL1oGsU0gmIDbMav5+T1RfSu+PJshkKmiKcuE37G12td1K8cIi7eUTSL/X3tVTvjCPW04+m44FrgAITSLZy4vj1toiW3g6xQ5qZG9E/BBzV/7tpvow/U= 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=zjkd8wt6; 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="zjkd8wt6" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id E10234E411D1; Wed, 12 Aug 2026 08:04:15 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id B5F786045E; Wed, 12 Aug 2026 08:04:15 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id A035A11C4C93D; Wed, 12 Aug 2026 10:04:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1786521854; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=pnN0FpzhAapp0YqcypTgIGSwzpgSufOPcxH2pWEkLuQ=; b=zjkd8wt6/Se2J+AcXhYHv1E3ZR2Rm+6aoPO4TGzwh4x8ne/ZqMQe7bAJ1pcebdUnWa0X95 jXE/U3iYSA+eMckrlcIbdQOdAIgFfHP6h26NNVab6xFpMrXbD8Otk6bDud5zuALqyG+Byf TD/kMIVD+RKO9Im+38qNE3jBVmywnANyGTA2ue0g10xk7b2i2EVI6c2NGdvo9NBgJ701hG 4QcBZMxR+UK6RoVyOclGex0CeTsoN16se/R3puz6RLHtqj05frNAdtHe+gFeJB6IVC9RFC KMNyg/SEaGIL4HH34bV33IjIVaHg9VN4Dbmxh/VPHp2DWAFYQ2nc7AUQ+3ggCQ== From: =?utf-8?q?Th=C3=A9o_Lebrun?= Date: Wed, 12 Aug 2026 10:03:27 +0200 Subject: [PATCH net-next v9 13/17] 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: 8bit Message-Id: <20260812-macb-context-v9-13-7ddbf5f715e0@bootlin.com> References: <20260812-macb-context-v9-0-7ddbf5f715e0@bootlin.com> In-Reply-To: <20260812-macb-context-v9-0-7ddbf5f715e0@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. Reviewed-by: Nicolai Buchwitz Signed-off-by: Théo 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/ethernet/cadence/macb_main.c index f0a4a9dcc460..5a4eb87f5a97 100644 --- a/drivers/net/ethernet/cadence/macb_main.c +++ b/drivers/net/ethernet/cadence/macb_main.c @@ -2868,6 +2868,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]; @@ -3236,27 +3266,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) { @@ -3295,7 +3313,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: -- 2.55.0