Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp4043763rwb; Mon, 21 Nov 2022 03:03:11 -0800 (PST) X-Google-Smtp-Source: AA0mqf6T+KQmrMYkoJ3ljKSEa3wZOzKIPpFMPaOrKEh5HfLyAkiDtaj8AKA40cocZYA42J1XXLGp X-Received: by 2002:a17:90b:1057:b0:218:8c53:b37 with SMTP id gq23-20020a17090b105700b002188c530b37mr13990095pjb.203.1669028591625; Mon, 21 Nov 2022 03:03:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669028591; cv=none; d=google.com; s=arc-20160816; b=BBBVX+mcTr1lPIpULLooSfzedy3IZvHEu9h5VnqJm//g+icW+KqkFaC7DN92c2eOe9 4J0hYwvZ6XwTOpI62ZFxTkcbegvuIWtkBm3iOHmRcE+czFf7/ltUw5Ga+eE7xGZea86h 2EOys2xO1+Y1wrKm5dwn7FN/zrV0+OlvAkFFs6i8IzSR5pLY9PJ5j3THikqtFwffYb/A JjGQ/DAScl4L5zIf9VtXEGKs+5VMP84QuxHZLsZQ0iyHjCOrGz4K1VCtAHXW1ubeUbTN 466InNEBsxscGoUvL+gnCfHl6ScuMN1V9gw4lKYJ/KrBX3wvBV9n7Bz694LrAZBbf35I 2PhA== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ja13-20020a170902efcd00b001867d1a71a6si4767830plb.473.2022.11.21.03.02.36; Mon, 21 Nov 2022 03:03:11 -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 + 93 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 Content-Type: text/plain 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 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; } -- 2.9.5