From patchwork Mon Nov 21 11:10:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Changzhong X-Patchwork-Id: 23658 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1508073wrr; Mon, 21 Nov 2022 02:52:33 -0800 (PST) X-Google-Smtp-Source: AA0mqf7v0t2sn9iI9nh6p/cormHIv5sTa7Ko5PvLiNQ1efrANF8fGyYXF5GsXLWiltGZvhO3V9go X-Received: by 2002:a05:6402:12d3:b0:45f:c86e:5336 with SMTP id k19-20020a05640212d300b0045fc86e5336mr15608083edx.233.1669027953085; Mon, 21 Nov 2022 02:52:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669027953; cv=none; d=google.com; s=arc-20160816; b=rx4c1zXZVktgdG5G0EsmC+IHuZvbtGeFIU21xkyeAGlfB0FRPrFcnW/Jo89cBexK5s z3qMgDLV5ujuzCo7xAvbAYD9DXfHfCFvbrQjefln3RDvyWKsANplpRiYOb0mHUdqjEej 8Awd0U+uTfqPNogUayVdieRUMkZBvkvoPbRnA/tqKLFfHpArcIBbjNOEUwrvAhD+wdge qF1mJxvW3IjhKFilLTlS37UMt8qt4Wfk8uFRY/86cO/hqF0yjce7XCOEO2gtUQ3ixJDY /h57t2kyVDJ96K98q152sh1fsNNVbGFxicRLlAqJVgNYlnW2g64wr44IMS56XuU3QNeF bfzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=Hk6p83tOJrBBStUFJC387pgoliEzBJc+1xCPmVm7EY8=; b=RXDr36h6VJvsXwBWX3BJchXDD+mIkfq1KQ4B0cCWKkx1WUREj2n9PRbjUhZi9aV7j9 wl4lAF9Ceb2+SerGxCP3vh0hQzGcf1AA417MdWvfosXZj151FKWYTOYVcRpBn1P1iS1z GPM3A9/yNBt45vSTHUVJ2AvBvGVFG0lu/SRSBNbHl/iM8D3R5ATrlAftmRcfP551fVVm Il5W2TnTH56BI6OIKB5yvmB0eYYPmYcUiQ6NrQNBLzYpVHPZ2y4FSGaYP6VehAHUxcVx eU5MU7toP7XviYXBwQW4QKsdt8UzYsL1+B2fWrsruR49WzcLZKBNcQ2mn7IUycnd7U+9 Ja5A== 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; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v14-20020a170906338e00b00770534b5a71si8026151eja.858.2022.11.21.02.52.05; Mon, 21 Nov 2022 02:52:33 -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; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229447AbiKUKuq (ORCPT + 99 others); Mon, 21 Nov 2022 05:50:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229501AbiKUKup (ORCPT ); Mon, 21 Nov 2022 05:50:45 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CCE861055C; Mon, 21 Nov 2022 02:50:44 -0800 (PST) Received: from dggpeml500025.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4NG40k2RmXzmW4Y; Mon, 21 Nov 2022 18:50:14 +0800 (CST) Received: from dggpeml500006.china.huawei.com (7.185.36.76) by dggpeml500025.china.huawei.com (7.185.36.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Mon, 21 Nov 2022 18:50:43 +0800 Received: from localhost.localdomain (10.175.112.70) by dggpeml500006.china.huawei.com (7.185.36.76) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Mon, 21 Nov 2022 18:50:42 +0800 From: Zhang Changzhong To: Wolfgang Grandegger , Marc Kleine-Budde , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Julia Lawall , Pavel Cheblakov CC: Zhang Changzhong , , , Subject: [PATCH] can: sja1000: plx_pci: fix error handling path in plx_pci_add_card() Date: Mon, 21 Nov 2022 19:10:30 +0800 Message-ID: <1669029031-7743-1-git-send-email-zhangchangzhong@huawei.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 X-Originating-IP: [10.175.112.70] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpeml500006.china.huawei.com (7.185.36.76) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,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?1750102654955655773?= X-GMAIL-MSGID: =?utf-8?q?1750102654955655773?= If pci_iomap() or register_sja1000dev() fails, netdev will not be registered, but plx_pci_del_card() still deregisters the netdev. To avoid this, let's free the netdev and clear card->net_dev[i] before calling plx_pci_del_card(). In addition, add the missing pci_iounmap() when the channel does not exist. Compile tested only. Fixes: 951f2f960e5b ("drivers/net/can/sja1000/plx_pci.c: eliminate double free") Fixes: 24c4a3b29255 ("can: add support for CAN interface cards based on the PLX90xx PCI bridge") Signed-off-by: Zhang Changzhong --- drivers/net/can/sja1000/plx_pci.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/net/can/sja1000/plx_pci.c b/drivers/net/can/sja1000/plx_pci.c index 5de1ebb..1158f5a 100644 --- a/drivers/net/can/sja1000/plx_pci.c +++ b/drivers/net/can/sja1000/plx_pci.c @@ -678,6 +678,8 @@ static int plx_pci_add_card(struct pci_dev *pdev, if (!addr) { err = -ENOMEM; dev_err(&pdev->dev, "Failed to remap BAR%d\n", cm->bar); + free_sja1000dev(dev); + card->net_dev[i] = NULL; goto failure_cleanup; } @@ -699,6 +701,9 @@ static int plx_pci_add_card(struct pci_dev *pdev, if (err) { dev_err(&pdev->dev, "Registering device failed " "(err=%d)\n", err); + pci_iounmap(pdev, priv->reg_base); + free_sja1000dev(dev); + card->net_dev[i] = NULL; goto failure_cleanup; } @@ -710,6 +715,7 @@ static int plx_pci_add_card(struct pci_dev *pdev, } else { dev_err(&pdev->dev, "Channel #%d not detected\n", i + 1); + pci_iounmap(pdev, priv->reg_base); free_sja1000dev(dev); card->net_dev[i] = NULL; }