From patchwork Sat May 23 13:27:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 200120 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.7 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1203CC433E0 for ; Sat, 23 May 2020 13:27:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E337620727 for ; Sat, 23 May 2020 13:27:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="mp9fRUIz" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387875AbgEWN11 (ORCPT ); Sat, 23 May 2020 09:27:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387866AbgEWN10 (ORCPT ); Sat, 23 May 2020 09:27:26 -0400 Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 039B9C08C5C1 for ; Sat, 23 May 2020 06:27:25 -0700 (PDT) Received: by mail-wm1-x343.google.com with SMTP id u1so11273971wmn.3 for ; Sat, 23 May 2020 06:27:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=85LArQ1FkfasqQwvTGBUsmFOdZ74xT3FAzPREvSXT3E=; b=mp9fRUIz3f7zzigyw8CU4tWQdJuD/cNnqmRAvK/VRG+g0juXIdGy1ACtv8QzDSAVvX zZTtdlmptVqzrDUoGctCNcVv+sp+kvHHQLKobjmUSABO5WlVbnS7ZjDu5eL8ghHSECVm K66u1sz1Vvr9cojS1puCVm7MHqwqSP+KeNpcs0Ikin3L/OSp6a6ja1mHMqLhXZ7QSF33 cmQ40C5Sb89UJ4E1ZZShWVrrBxftRA6RfclHz/BjVeWTuoRi2J+VvqnLv5AlUcR7mc7l F0zaODP7z0PlC5yJ+Y5QhZw5HjxWCqux45s0hgaopOwzgqaGcyNlp2dO1XJ/1y0vfKmZ FmJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=85LArQ1FkfasqQwvTGBUsmFOdZ74xT3FAzPREvSXT3E=; b=rrDaa4Xgo1LTFjG6gTSlvGEuAyxz/ZLygcI5aTMGQVfi1p5za/YS5C+M+bMcPZTIxG Ewv7ZDwnM54JvnxU5+AQ/0COF53I9EXaCK0Odztbqz3fR/aKB+toKHhVHOoULD3Y9oud RckxC+P0ZYwA5Anry2GsyFXaABiXWNNmluwjUvk1m3RYQqy2vFZyP4x9jWI+QEA6Zel9 /Xvr6lqRIxeTRkMhoAn5vVKXxWbaSabtdkyDN8GYDS3HSb4tQujHA5sxaKW8BOBb53XA NNrB29AEKJnWU1ED5Bl4Jah0WpWK5boy+bL0MpfBKijqFiwZqYbk2W4KS0qp9Y4ms+Qa ZUGw== X-Gm-Message-State: AOAM532yEyTwpjaRQxM3ZWVTuwfEVeZmFpAOyEgorve1Dp5Dgu4E1luZ pn+LxHCvdNHhQvggDi+KuLLci73tL+A= X-Google-Smtp-Source: ABdhPJw0PA+P0HcUXiWXYQRZQG2lReeBtiQJfZFPYkFAcWtI7Dg+DCbBae2YfDUJLHDk1mI3Rm2NpA== X-Received: by 2002:a1c:acc8:: with SMTP id v191mr18521019wme.154.1590240443748; Sat, 23 May 2020 06:27:23 -0700 (PDT) Received: from localhost.localdomain (lfbn-nic-1-65-232.w2-15.abo.wanadoo.fr. [2.15.156.232]) by smtp.gmail.com with ESMTPSA id g69sm8098703wmg.15.2020.05.23.06.27.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 May 2020 06:27:23 -0700 (PDT) From: Bartosz Golaszewski To: Jonathan Corbet , "David S . Miller" , Matthias Brugger , John Crispin , Sean Wang , Mark Lee , Jakub Kicinski , Arnd Bergmann , Fabien Parent , Heiner Kallweit , Edwin Peer Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, Stephane Le Provost , Pedro Tsai , Andrew Perepech , Bartosz Golaszewski Subject: [PATCH v2 3/5] net: devres: define a separate devres structure for devm_alloc_etherdev() Date: Sat, 23 May 2020 15:27:09 +0200 Message-Id: <20200523132711.30617-4-brgl@bgdev.pl> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200523132711.30617-1-brgl@bgdev.pl> References: <20200523132711.30617-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org From: Bartosz Golaszewski Not using a proxy structure to store struct net_device doesn't save anything in terms of compiled code size or memory usage but significantly decreases the readability of the code with all the pointer casting. Define struct net_device_devres and use it in devm_alloc_etherdev_mqs(). Signed-off-by: Bartosz Golaszewski --- net/devres.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/net/devres.c b/net/devres.c index c1465d9f9019..b97b0c5a8216 100644 --- a/net/devres.c +++ b/net/devres.c @@ -7,30 +7,34 @@ #include #include -static void devm_free_netdev(struct device *dev, void *res) +struct net_device_devres { + struct net_device *ndev; +}; + +static void devm_free_netdev(struct device *dev, void *this) { - free_netdev(*(struct net_device **)res); + struct net_device_devres *res = this; + + free_netdev(res->ndev); } struct net_device *devm_alloc_etherdev_mqs(struct device *dev, int sizeof_priv, unsigned int txqs, unsigned int rxqs) { - struct net_device **dr; - struct net_device *netdev; + struct net_device_devres *dr; dr = devres_alloc(devm_free_netdev, sizeof(*dr), GFP_KERNEL); if (!dr) return NULL; - netdev = alloc_etherdev_mqs(sizeof_priv, txqs, rxqs); - if (!netdev) { + dr->ndev = alloc_etherdev_mqs(sizeof_priv, txqs, rxqs); + if (!dr->ndev) { devres_free(dr); return NULL; } - *dr = netdev; devres_add(dev, dr); - return netdev; + return dr->ndev; } EXPORT_SYMBOL(devm_alloc_etherdev_mqs); From patchwork Sat May 23 13:27:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 200119 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5E42BC433DF for ; Sat, 23 May 2020 13:27:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3A02F20829 for ; Sat, 23 May 2020 13:27:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="WCoxlxcA" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387883AbgEWN1m (ORCPT ); Sat, 23 May 2020 09:27:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387884AbgEWN12 (ORCPT ); Sat, 23 May 2020 09:27:28 -0400 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9940C08C5C1 for ; Sat, 23 May 2020 06:27:27 -0700 (PDT) Received: by mail-wr1-x443.google.com with SMTP id x14so7603643wrp.2 for ; Sat, 23 May 2020 06:27:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=64kvwBG1/A4ZIpIpQ81Lq/ynCrPXhKaGjAzI5WzwgPE=; b=WCoxlxcAreaFf6FWNGwNvYKxgyg/0gU+HbaYFg23bXDv4PSZYQHZlcxTOz7FCYoubj 5e5E0jUoENWF/3lKC2kOeluwhMEcroHJYd4LLhnNzHEnkUXIYnNGkbayPKVmcdBOa4Ct Zd7GHa3AvzA8wj3qLAFTjfju/dvJxGVk6M8DDJ+ik4ZotMuSwK1r56f3O59Uk50PFPVn R0DaSsNzfIUyeO9IWOXdsNRiOpScHj5lcBRivA9lt7wATE958fMmZQ8bNr/E3zw9Lp+a lRCGiGC2Qe4t821qu5XEVbdXbkQ+sQS32lFBOC3K6B9MwNUMYCIjE+kQk5GoDFnQ/755 JQPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=64kvwBG1/A4ZIpIpQ81Lq/ynCrPXhKaGjAzI5WzwgPE=; b=UbyHUVpdTCEXeUfKnvEpUj91smqSHlGa0styCG2SlUdfrPDReSSM6jF1ERM6VFzvxX en5IUfD8Sx49+5fLeqrSH6TifC2yZO153B2Huqmc8P8dcsWNZuG0cIcJIpOJTHR9vY/D XRvZwiM8YDGtnNR3+pyAh11ZqlgHJmejVWpDQqb3GaCXmVNzsftYndlhgL77DTErZkZR M6UfZ9Va4CO8/cu8r5vLohgWK1jQjj336ROY/xOG1BsFlxoP3RrtkZAlBPnXfh/XV4FJ nboU8h/xUp+YCn23y0xhMPunufW3bKA+LRp3PPVQG8fY3aEHKC3DCfB0VbVq3579oebf 3o+g== X-Gm-Message-State: AOAM530fJc7IKQ1JDIXIdHOQRfwpoNyMB+0X6jHDBXHAbwE4wHHVv392 uJ7wnYeoWWsk7r1m/YHScS86iw== X-Google-Smtp-Source: ABdhPJzIGyb5J01y0YxEKH5gekjElLjvEzQP6NEzA1GtaboJVo5CQutHS2WF+ceWndsriO45lbSBPQ== X-Received: by 2002:adf:e3c1:: with SMTP id k1mr3797110wrm.33.1590240446683; Sat, 23 May 2020 06:27:26 -0700 (PDT) Received: from localhost.localdomain (lfbn-nic-1-65-232.w2-15.abo.wanadoo.fr. [2.15.156.232]) by smtp.gmail.com with ESMTPSA id g69sm8098703wmg.15.2020.05.23.06.27.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 May 2020 06:27:26 -0700 (PDT) From: Bartosz Golaszewski To: Jonathan Corbet , "David S . Miller" , Matthias Brugger , John Crispin , Sean Wang , Mark Lee , Jakub Kicinski , Arnd Bergmann , Fabien Parent , Heiner Kallweit , Edwin Peer Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, Stephane Le Provost , Pedro Tsai , Andrew Perepech , Bartosz Golaszewski Subject: [PATCH v2 5/5] net: ethernet: mtk_star_emac: use devm_register_netdev() Date: Sat, 23 May 2020 15:27:11 +0200 Message-Id: <20200523132711.30617-6-brgl@bgdev.pl> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200523132711.30617-1-brgl@bgdev.pl> References: <20200523132711.30617-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org From: Bartosz Golaszewski Use the new devres variant of register_netdev() in the mtk-star-emac driver and shrink the code by a couple lines. Signed-off-by: Bartosz Golaszewski --- drivers/net/ethernet/mediatek/mtk_star_emac.c | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/drivers/net/ethernet/mediatek/mtk_star_emac.c b/drivers/net/ethernet/mediatek/mtk_star_emac.c index 789c77af501f..b74349cede28 100644 --- a/drivers/net/ethernet/mediatek/mtk_star_emac.c +++ b/drivers/net/ethernet/mediatek/mtk_star_emac.c @@ -1519,13 +1519,6 @@ static void mtk_star_mdiobus_unregister(void *data) mdiobus_unregister(priv->mii); } -static void mtk_star_unregister_netdev(void *data) -{ - struct net_device *ndev = data; - - unregister_netdev(ndev); -} - static int mtk_star_probe(struct platform_device *pdev) { struct device_node *of_node; @@ -1641,15 +1634,7 @@ static int mtk_star_probe(struct platform_device *pdev) netif_napi_add(ndev, &priv->napi, mtk_star_poll, MTK_STAR_NAPI_WEIGHT); - ret = register_netdev(ndev); - if (ret) - return ret; - - ret = devm_add_action_or_reset(dev, mtk_star_unregister_netdev, ndev); - if (ret) - return ret; - - return 0; + return devm_register_netdev(dev, ndev); } static const struct of_device_id mtk_star_of_match[] = {