From patchwork Tue Nov 3 21:55:13 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergei Shtylyov X-Patchwork-Id: 7547291 Return-Path: X-Original-To: patchwork-linux-sh@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 34E2C9F2F7 for ; Tue, 3 Nov 2015 21:55:21 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 233D320796 for ; Tue, 3 Nov 2015 21:55:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0EC2720794 for ; Tue, 3 Nov 2015 21:55:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755390AbbKCVzS (ORCPT ); Tue, 3 Nov 2015 16:55:18 -0500 Received: from mail-lf0-f41.google.com ([209.85.215.41]:36153 "EHLO mail-lf0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752062AbbKCVzR (ORCPT ); Tue, 3 Nov 2015 16:55:17 -0500 Received: by lfs39 with SMTP id 39so2059731lfs.3 for ; Tue, 03 Nov 2015 13:55:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cogentembedded_com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:organization:user-agent :mime-version:content-transfer-encoding:content-type; bh=4sZGstOYpGI8/3BQ3dYqaixLBkvK81h4DCpm9fgvKY4=; b=P1xjw78niKZDSQnSP9WswYCQnfJ96JYg+1y2nKYNA7rEJGlLwPsQ1QtWYwCbsIXJfr esHnB1lFU3hwPiit90hc0y8rPQp7qdCFxyqO7qKpfbynMgDBeVVNcQFazp4PVLFZB6sR ZUMEzi+0vUJ+AiW7bZj/eaCxYiHuPdDzmb8FgKSZIMZ60OCwdF93sdaMNB8LJDEb1YZN UKtfqjlBV6dpzeO8te83chf9lmTQFsoTozQCXFbnG8SVEmVR63hH6xgCIgfx/+MqenLy fc2Mm6WujI0XnaiOkW/ZbMG+Iueuho8R5YKPnGybFneF4MmMyZyvYnklSkVyf63ZAXy0 BVLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:organization :user-agent:mime-version:content-transfer-encoding:content-type; bh=4sZGstOYpGI8/3BQ3dYqaixLBkvK81h4DCpm9fgvKY4=; b=Fx4W8b7P/Yk0IrHl0hqfjh100BKcfmWn54XVjQ42h6hy+VKgV5uKSM/NrvxzimOD3w AoVZfKDRLjBWKTQG5DAiFAb78bVbdK7Yhj3bqR0FKW1ltfJSYbSaQAmYzPgxuh7TqnZ8 gkwcFawUx1NAu8NxMqXcrVnj/46RQ0culPBco2xi3Qe4cUpVu2zYH0Ocm6GXSuE5RlW2 iLC/K9AdLhpJwrAdaEy1wAFwk3cIhGuWTv7OltqDnH0KxbvqYtoF/gqD9OisooCjjCsw +XWDQl5Nea6996CAcQqVxfyueqFwMc1NHqAN1Xc6QvVFfsfAX4qNq9aP/7zOED2BkGp4 Eu8g== X-Gm-Message-State: ALoCoQmdBoF2N+oYXniPvm0BFiSzCwk8iHnBPOAANFDUd9N54p/a6R/yp5siJm7UEQyjOnkCekf3 X-Received: by 10.25.137.214 with SMTP id l205mr9414932lfd.69.1446587715190; Tue, 03 Nov 2015 13:55:15 -0800 (PST) Received: from wasted.cogentembedded.com ([31.173.80.192]) by smtp.gmail.com with ESMTPSA id l8sm5119673lbj.7.2015.11.03.13.55.14 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 03 Nov 2015 13:55:14 -0800 (PST) From: Sergei Shtylyov To: netdev@vger.kernel.org Cc: linux-sh@vger.kernel.org Subject: [PATCH] sh_eth: merge sh_eth_free_dma_buffer() into sh_eth_ring_free() Date: Wed, 04 Nov 2015 00:55:13 +0300 Message-ID: <6672379.kyQ5eFYq8y@wasted.cogentembedded.com> Organization: Cogent Embedded Inc. User-Agent: KMail/4.14.9 (Linux/4.2.3-200.fc22.x86_64; KDE/4.14.11; x86_64; ; ) MIME-Version: 1.0 Sender: linux-sh-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID,T_RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP While the ring allocation is done by a single function, sh_eth_ring_init(), the ring deallocation was split into two functions (almost always called one after the other) for no good reason. Merge sh_eth_free_dma_buffer() into sh_eth_ring_free() which allows us to save space not only on the direct calls of the former function but also on the sh_eth_ring_init()'s simplified error path... Signed-off-by: Sergei Shtylyov --- The patch is against DaveM's 'net-next.git' repo plus the patch just posted. drivers/net/ethernet/renesas/sh_eth.c | 60 ++++++++++++---------------------- 1 file changed, 22 insertions(+), 38 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-sh" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Index: net-next/drivers/net/ethernet/renesas/sh_eth.c =================================================================== --- net-next.orig/drivers/net/ethernet/renesas/sh_eth.c +++ net-next/drivers/net/ethernet/renesas/sh_eth.c @@ -1098,7 +1098,7 @@ static struct mdiobb_ops bb_ops = { static void sh_eth_ring_free(struct net_device *ndev) { struct sh_eth_private *mdp = netdev_priv(ndev); - int i; + int ringsize, i; /* Free Rx skb ringbuffer */ if (mdp->rx_skbuff) { @@ -1115,6 +1115,20 @@ static void sh_eth_ring_free(struct net_ } kfree(mdp->tx_skbuff); mdp->tx_skbuff = NULL; + + if (mdp->rx_ring) { + ringsize = sizeof(struct sh_eth_rxdesc) * mdp->num_rx_ring; + dma_free_coherent(NULL, ringsize, mdp->rx_ring, + mdp->rx_desc_dma); + mdp->rx_ring = NULL; + } + + if (mdp->tx_ring) { + ringsize = sizeof(struct sh_eth_txdesc) * mdp->num_tx_ring; + dma_free_coherent(NULL, ringsize, mdp->tx_ring, + mdp->tx_desc_dma); + mdp->tx_ring = NULL; + } } /* format skb and descriptor buffer */ @@ -1220,14 +1234,14 @@ static int sh_eth_ring_init(struct net_d mdp->tx_skbuff = kcalloc(mdp->num_tx_ring, sizeof(*mdp->tx_skbuff), GFP_KERNEL); if (!mdp->tx_skbuff) - goto skb_ring_free; + goto ring_free; /* Allocate all Rx descriptors. */ rx_ringsize = sizeof(struct sh_eth_rxdesc) * mdp->num_rx_ring; mdp->rx_ring = dma_alloc_coherent(NULL, rx_ringsize, &mdp->rx_desc_dma, GFP_KERNEL); if (!mdp->rx_ring) - goto skb_ring_free; + goto ring_free; mdp->dirty_rx = 0; @@ -1236,41 +1250,16 @@ static int sh_eth_ring_init(struct net_d mdp->tx_ring = dma_alloc_coherent(NULL, tx_ringsize, &mdp->tx_desc_dma, GFP_KERNEL); if (!mdp->tx_ring) - goto desc_ring_free; + goto ring_free; return 0; -desc_ring_free: - /* free DMA buffer */ - dma_free_coherent(NULL, rx_ringsize, mdp->rx_ring, mdp->rx_desc_dma); - -skb_ring_free: - /* Free Rx and Tx skb ring buffer */ +ring_free: + /* Free Rx and Tx skb ring buffer and DMA buffer */ sh_eth_ring_free(ndev); - mdp->tx_ring = NULL; - mdp->rx_ring = NULL; return -ENOMEM; } -static void sh_eth_free_dma_buffer(struct sh_eth_private *mdp) -{ - int ringsize; - - if (mdp->rx_ring) { - ringsize = sizeof(struct sh_eth_rxdesc) * mdp->num_rx_ring; - dma_free_coherent(NULL, ringsize, mdp->rx_ring, - mdp->rx_desc_dma); - mdp->rx_ring = NULL; - } - - if (mdp->tx_ring) { - ringsize = sizeof(struct sh_eth_txdesc) * mdp->num_tx_ring; - dma_free_coherent(NULL, ringsize, mdp->tx_ring, - mdp->tx_desc_dma); - mdp->tx_ring = NULL; - } -} - static int sh_eth_dev_init(struct net_device *ndev, bool start) { int ret = 0; @@ -2231,10 +2220,8 @@ static int sh_eth_set_ringparam(struct n sh_eth_dev_exit(ndev); - /* Free all the skbuffs in the Rx queue. */ + /* Free all the skbuffs in the Rx queue and the DMA buffers. */ sh_eth_ring_free(ndev); - /* Free DMA buffer */ - sh_eth_free_dma_buffer(mdp); } /* Set new parameters */ @@ -2479,12 +2466,9 @@ static int sh_eth_close(struct net_devic free_irq(ndev->irq, ndev); - /* Free all the skbuffs in the Rx queue. */ + /* Free all the skbuffs in the Rx queue and the DMA buffer. */ sh_eth_ring_free(ndev); - /* free DMA buffer */ - sh_eth_free_dma_buffer(mdp); - pm_runtime_put_sync(&mdp->pdev->dev); mdp->is_opened = 0;