Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2677359rwb; Sat, 19 Nov 2022 22:46:02 -0800 (PST) X-Google-Smtp-Source: AA0mqf4MeGcr56+10f/IViD5MIRor668GAinKv1fqFHJqkjpnTTy89i/KxZVhdgIMHqFhpTnCYJr X-Received: by 2002:a17:90b:1d44:b0:218:7a67:b259 with SMTP id ok4-20020a17090b1d4400b002187a67b259mr9637739pjb.28.1668926762525; Sat, 19 Nov 2022 22:46:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668926762; cv=none; d=google.com; s=arc-20160816; b=aVqm9UYsqMBWU5Mvk3umMY/OLe5pbPm5v5EvuX1pfEmwid6rKOREzqA0YZgft0bfCo Bp8+jS1oM4SQQy2kVvE2syMSdd0ohVLwclxyIzy9kbB98MmD1L1m0TCkB6R/SlC5Uhnk tN1/9SN6A6IfYLpYmwk3IvCvmwZOlTndLdh1NczsNGZPdAxtsFERoL9Q6E1qfo2QCWIs adac4cR9BZp/mbuI3jseqCJogdBHjqg7qKzIIEv11KVN7B7gL1sZkfd6kScdB7P36EVD R7msTEeNv/Am5EFADwi5JgvNbBtUeMQsyZtFSfahHUIXoPgLC6p5dsgYUhIgE4cmswCR DZGA== 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=EI9vPJ1dpgrgiUIARNEtLLOq/n2iVB/BO3L+EGI8wko=; b=iLD8GaIy4vjyJJyz2WvgH3I/XGGsdimijP7Au28JWc/84cKrjv99QlzIboAQVBCnSd Ji7nJy6B2hJGaMmCao0Bo2DSe+F0uwOwJEkikdQD5xCYidoogihK/VXcbkqSnLBpoYwM qUrYRt7lHBaOlJ5qBfstz5EylvF5rExDFJlsSFvkrim18LDFEmV4CDJUg53M1bj39bhH WH8L9Di7kSMuuFLMK3KAcJVMl5ikvvbUL0wnQZc/I7vcE8tjgBL+QZ9B1n+u9M1gPMet 72ibO/cneyWk3pqH0JmEb7OAWuXRUF9n28qbOKtf4poquazt1lbUDApReSblZQT1NOld 4Haw== 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 e9-20020a631e09000000b0046fc6e02bb9si8267743pge.253.2022.11.19.22.45.27; Sat, 19 Nov 2022 22:46:02 -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 S229508AbiKTGYs (ORCPT + 93 others); Sun, 20 Nov 2022 01:24:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49162 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229447AbiKTGYr (ORCPT ); Sun, 20 Nov 2022 01:24:47 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 16F739E0AA; Sat, 19 Nov 2022 22:24:45 -0800 (PST) Received: from dggemv711-chm.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4NFL8J4hjWzRp1c; Sun, 20 Nov 2022 14:24:16 +0800 (CST) Received: from kwepemm600001.china.huawei.com (7.193.23.3) by dggemv711-chm.china.huawei.com (10.1.198.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Sun, 20 Nov 2022 14:24:41 +0800 Received: from huawei.com (10.175.113.133) by kwepemm600001.china.huawei.com (7.193.23.3) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Sun, 20 Nov 2022 14:24:40 +0800 From: Wang Hai To: , , , , , CC: , Subject: [PATCH net] arcnet: fix potential memory leak in com20020_probe() Date: Sun, 20 Nov 2022 14:24:38 +0800 Message-ID: <20221120062438.46090-1-wanghai38@huawei.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.113.133] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To kwepemm600001.china.huawei.com (7.193.23.3) 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 In com20020_probe(), if com20020_config() fails, dev and info will not be freed, which will lead to a memory leak. This patch adds freeing dev and info after com20020_config() fails to fix this bug. Compile tested only. Fixes: 15b99ac17295 ("[PATCH] pcmcia: add return value to _config() functions") Signed-off-by: Wang Hai --- drivers/net/arcnet/com20020_cs.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/net/arcnet/com20020_cs.c b/drivers/net/arcnet/com20020_cs.c index 24150c933fcb..dc3253b318da 100644 --- a/drivers/net/arcnet/com20020_cs.c +++ b/drivers/net/arcnet/com20020_cs.c @@ -113,6 +113,7 @@ static int com20020_probe(struct pcmcia_device *p_dev) struct com20020_dev *info; struct net_device *dev; struct arcnet_local *lp; + int ret = -ENOMEM; dev_dbg(&p_dev->dev, "com20020_attach()\n"); @@ -142,12 +143,18 @@ static int com20020_probe(struct pcmcia_device *p_dev) info->dev = dev; p_dev->priv = info; - return com20020_config(p_dev); + ret = com20020_config(p_dev); + if (ret) + goto fail_config; + + return 0; +fail_config: + free_arcdev(dev); fail_alloc_dev: kfree(info); fail_alloc_info: - return -ENOMEM; + return ret; } /* com20020_attach */ static void com20020_detach(struct pcmcia_device *link) -- 2.17.1