From patchwork Sun Nov 20 06:24:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Hai X-Patchwork-Id: 23383 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp997961wrr; Sat, 19 Nov 2022 22:25:43 -0800 (PST) X-Google-Smtp-Source: AA0mqf68nn7FZIdFINza9UeC1kVcRwG2/YNvRjHdyqDs4SljFlVPM2Nu0NQYLeGCELaxjdaJGPH8 X-Received: by 2002:a63:1b63:0:b0:470:38f8:4b1a with SMTP id b35-20020a631b63000000b0047038f84b1amr12531434pgm.461.1668925543356; Sat, 19 Nov 2022 22:25:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668925543; cv=none; d=google.com; s=arc-20160816; b=yNFSavK6sb7gShywV9RvFKAzfridihdhuBLzbliRmeB5gqEvLmpV6GE2yrxROzNvtw VI0nIPBohv9UG4OX+OxaWrbBMSQ7ob1IfgQpn7Bh50VNTp9Krev/aUgnk+/K8ABGMqVX NiyAj87KGRTbbQfWB7a03eEWMYn41/gV0SYOr7oC3167aYKHtA2XAryecmEd+oozCMVg fZclzWJWP39WFSd6mb3SDguMuuPa6Lf1Z+AGC6+T5QfRLZVEvNTK66h9agjI8qDfbCMy OM0/+MyCZexUwercFOxsMVsMh6LCGbn6vbXi7MYu0wxUqagsv7d3u3cZbVQZIh17Bprp V6HA== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i8-20020aa78d88000000b0056e48944895si7507570pfr.317.2022.11.19.22.25.17; Sat, 19 Nov 2022 22:25:43 -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 + 99 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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749995270493626545?= X-GMAIL-MSGID: =?utf-8?q?1749995270493626545?= 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)