From patchwork Wed Jan 4 21:05:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 39094 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp5358797wrt; Wed, 4 Jan 2023 13:12:37 -0800 (PST) X-Google-Smtp-Source: AMrXdXvvNYb4QCC45QgxlfEmhxWl3wT/FZjeM/+dqsEX4ohOHXyf5OXCiOhBwag1adNQM/8UNYuQ X-Received: by 2002:a17:907:3e0c:b0:7c0:f90f:163d with SMTP id hp12-20020a1709073e0c00b007c0f90f163dmr55601590ejc.11.1672866757497; Wed, 04 Jan 2023 13:12:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672866757; cv=none; d=google.com; s=arc-20160816; b=iczCj0PFMktmPYkTxYHQ+2DepeBpnkfJ1oWqbE96tuKNXPwRUAP5/BqGUKq3XzyK5O Y4i4I37AO7rWlpFqcNstn7cLf5kt4QcanoQlF2mU2Qr0r2r+iF2SXnJRVqK/xSuZqX2i 2kKNU1ND3a7hgNp2IWGQ6fp99I0LtrwZ+vaN64HJJdx5EPHaObaDhaF+R+Is98zmF1lU 4k7NAvwwcpZ16xeopiwJ7f06NRCaDXyP1Op5PfnJ+QR9Fie75JvokgG+cYRZ/x0N5gvS jRvme7cl2Iy5QMg7POHOgBkEeI4U9pknhv4Shpea6lXkmJwuE9qV7eiMfRrJDmWXoecX 85bg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=NOk8FwoRz/XzGggrBt07CoRND5dXo8gXC/b5eEKGq6Y=; b=IkfOmq6AgiS0XcMLmn0UwUpcGF6Enq8zEK83Rp76PAvhZPW/MiGCGTgBJe6qsg7M1f dfouCpdQizjKHYfAohZbyPt5rv7hXH/goK54aLQFoOPP5zgB3iUMsUprlIOyTSsKy47v wN/HoNIwKescKqpCnO/yMvC0isscn3EzPpZCCAPwp0p3RaEnzITUMtgPW3obnnDbwfTr MXaUAyN3qld48EWzc6XdxBmGpn0XuoCqbsP/ne3nit0D6q5cHOtJvZCBzOdThP5Uxmb8 x90XQLrXJcyAE9Hvj510b1opvO2gaMgBh46yAWHm+jbPPMgmcw20VaxLvHNFpRgt2NRK d1qQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id go39-20020a1709070da700b0077cfdda438csi36135851ejc.35.2023.01.04.13.12.13; Wed, 04 Jan 2023 13:12:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231171AbjADVGn (ORCPT + 99 others); Wed, 4 Jan 2023 16:06:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240308AbjADVG1 (ORCPT ); Wed, 4 Jan 2023 16:06:27 -0500 Received: from smtp.smtpout.orange.fr (smtp-13.smtpout.orange.fr [80.12.242.13]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D15DB1CB12 for ; Wed, 4 Jan 2023 13:06:26 -0800 (PST) Received: from pop-os.home ([86.243.100.34]) by smtp.orange.fr with ESMTPA id DAxcpwWwVxN58DAxtpFlJp; Wed, 04 Jan 2023 22:06:25 +0100 X-ME-Helo: pop-os.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Wed, 04 Jan 2023 22:06:25 +0100 X-ME-IP: 86.243.100.34 From: Christophe JAILLET To: "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, netdev@vger.kernel.org, Christophe JAILLET Subject: [PATCH net-next 2/3] ezchip: Switch to some devm_ function to simplify code Date: Wed, 4 Jan 2023 22:05:33 +0100 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754127932954778529?= X-GMAIL-MSGID: =?utf-8?q?1754127932954778529?= devm_alloc_etherdev() and devm_register_netdev() can be used to simplify code. Now the error handling path of the probe and the remove function are useless and can be removed completely. Signed-off-by: Christophe JAILLET --- drivers/net/ethernet/ezchip/nps_enet.c | 42 ++++++-------------------- 1 file changed, 9 insertions(+), 33 deletions(-) diff --git a/drivers/net/ethernet/ezchip/nps_enet.c b/drivers/net/ethernet/ezchip/nps_enet.c index 6389c6b5005c..21e230150104 100644 --- a/drivers/net/ethernet/ezchip/nps_enet.c +++ b/drivers/net/ethernet/ezchip/nps_enet.c @@ -579,7 +579,7 @@ static s32 nps_enet_probe(struct platform_device *pdev) if (!dev->of_node) return -ENODEV; - ndev = alloc_etherdev(sizeof(struct nps_enet_priv)); + ndev = devm_alloc_etherdev(dev, sizeof(struct nps_enet_priv)); if (!ndev) return -ENOMEM; @@ -594,10 +594,8 @@ static s32 nps_enet_probe(struct platform_device *pdev) ndev->flags &= ~IFF_MULTICAST; priv->regs_base = devm_platform_ioremap_resource(pdev, 0); - if (IS_ERR(priv->regs_base)) { - err = PTR_ERR(priv->regs_base); - goto out_netdev; - } + if (IS_ERR(priv->regs_base)) + return PTR_ERR(priv->regs_base); dev_dbg(dev, "Registers base address is 0x%p\n", priv->regs_base); /* set kernel MAC address to dev */ @@ -607,41 +605,20 @@ static s32 nps_enet_probe(struct platform_device *pdev) /* Get IRQ number */ priv->irq = platform_get_irq(pdev, 0); - if (priv->irq < 0) { - err = -ENODEV; - goto out_netdev; - } + if (priv->irq < 0) + return -ENODEV; netif_napi_add_weight(ndev, &priv->napi, nps_enet_poll, NPS_ENET_NAPI_POLL_WEIGHT); /* Register the driver. Should be the last thing in probe */ - err = register_netdev(ndev); - if (err) { - dev_err(dev, "Failed to register ndev for %s, err = 0x%08x\n", - ndev->name, (s32)err); - goto out_netif_api; - } + err = devm_register_netdev(dev, ndev); + if (err) + return dev_err_probe(dev, err, "Failed to register ndev for %s\n", + ndev->name); dev_info(dev, "(rx/tx=%d)\n", priv->irq); return 0; - -out_netif_api: -out_netdev: - free_netdev(ndev); - - return err; -} - -static s32 nps_enet_remove(struct platform_device *pdev) -{ - struct net_device *ndev = platform_get_drvdata(pdev); - struct nps_enet_priv *priv = netdev_priv(ndev); - - unregister_netdev(ndev); - free_netdev(ndev); - - return 0; } static const struct of_device_id nps_enet_dt_ids[] = { @@ -652,7 +629,6 @@ MODULE_DEVICE_TABLE(of, nps_enet_dt_ids); static struct platform_driver nps_enet_driver = { .probe = nps_enet_probe, - .remove = nps_enet_remove, .driver = { .name = DRV_NAME, .of_match_table = nps_enet_dt_ids,