Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1764473rwb; Thu, 10 Nov 2022 23:13:33 -0800 (PST) X-Google-Smtp-Source: AA0mqf7RFgBMzPOjqaHRi/qmfRk5GbNkz1R82HxkPQ7YZlbA8KHF8Q6D2Bikv6Mfw+fdW5y0sQKI X-Received: by 2002:a63:f158:0:b0:43c:2e57:9636 with SMTP id o24-20020a63f158000000b0043c2e579636mr601643pgk.81.1668150813780; Thu, 10 Nov 2022 23:13:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668150813; cv=none; d=google.com; s=arc-20160816; b=R8v0MsO3AycaEi+wBveE1geOmc7PYlEXvr6TAT140wOU7rzDeaZbj0QDPe6sCDkyIB 1tky0c4sQaiM+Qio/zOPQPxVevCa4uoVPmuFXSoUdOWmZsMQkyRcJVsCxam4Q7SI09Yp DwovIKDAkUIfp+weblaRL8DoSNhX3D24W3DTUaR0OrlxZhOusELes+wYWOgr2DvX2Hf6 PmdT6XOI4+rfvNdAPQh84mHetaj3G2RclH6+hVDjTIXWPZNJgV2VWbKfXS2pUuhAqbWa OHOcTkRhN2Xuq9OGT1W9f9vL6qkUqQRrGLU3iIOFJfXFTl4f8si428kRP/YVOfXieNwa gclA== 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:to:from; bh=wb71QJz6wD+QXFRyDngo3oF7jpyMls9VkyC3zoZddOk=; b=gr2NnUCrlQgqGCl6mwRObM5LmBlFiTthnhECTv3r60C51is/537N2XybHvitQoXUG9 X83zuS/sahsmmLJU3QzL4gIpROuA3OBlgmyi2IgUMZBVaDf7CDpHKaGlnhmGFeL5Zxm0 yZXntq/enMc7cddjbK+CK2mUtcQfSuRotFFJvQXi15rcpsRbNgFqOk5iJTBGidkwgn1H m6Okj5tEVxOSPCm4DrM2cVgzsNFSezJe15EaUfpkAP4Mx8/eN0l5RcnpKjJ8jbA5f5H1 k2cwQ3AH54b62nHOn5u057DQftP8aCfS2bj3edEmhUKqTqJGdgipVIBmFQF94gV2N7y8 lYDw== 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 u9-20020a63d349000000b0047063e55de3si1489027pgi.711.2022.11.10.23.13.21; Thu, 10 Nov 2022 23:13: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 S233077AbiKKHJf (ORCPT + 92 others); Fri, 11 Nov 2022 02:09:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47722 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233170AbiKKHJ3 (ORCPT ); Fri, 11 Nov 2022 02:09:29 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0189318351; Thu, 10 Nov 2022 23:09:28 -0800 (PST) Received: from canpemm500006.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4N7qZL6kZnzRp9n; Fri, 11 Nov 2022 15:09:14 +0800 (CST) Received: from localhost.localdomain (10.175.104.82) by canpemm500006.china.huawei.com (7.192.105.130) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Fri, 11 Nov 2022 15:09:26 +0800 From: Ziyang Xuan To: , , , , , , , , Subject: [PATCH net 3/4] octeon_ep: fix potential memory leak in octep_device_setup() Date: Fri, 11 Nov 2022 15:09:23 +0800 Message-ID: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.104.82] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To canpemm500006.china.huawei.com (7.192.105.130) 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 When occur unsupported_dev and mbox init errors, it did not free oct->conf and iounmap() oct->mmio[i].hw_addr. That would trigger memory leak problem. Add kfree() for oct->conf and iounmap() for oct->mmio[i].hw_addr under unsupported_dev and mbox init errors to fix the problem. Fixes: 862cd659a6fb ("octeon_ep: Add driver framework and device initialization") Signed-off-by: Ziyang Xuan --- drivers/net/ethernet/marvell/octeon_ep/octep_main.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/marvell/octeon_ep/octep_main.c b/drivers/net/ethernet/marvell/octeon_ep/octep_main.c index 546bcebf4462..53f288c32238 100644 --- a/drivers/net/ethernet/marvell/octeon_ep/octep_main.c +++ b/drivers/net/ethernet/marvell/octeon_ep/octep_main.c @@ -956,7 +956,7 @@ int octep_device_setup(struct octep_device *oct) ret = octep_ctrl_mbox_init(ctrl_mbox); if (ret) { dev_err(&pdev->dev, "Failed to initialize control mbox\n"); - return -1; + goto unsupported_dev; } oct->ctrl_mbox_ifstats_offset = OCTEP_CTRL_MBOX_SZ(ctrl_mbox->h2fq.elem_sz, ctrl_mbox->h2fq.elem_cnt, @@ -966,6 +966,10 @@ int octep_device_setup(struct octep_device *oct) return 0; unsupported_dev: + for (i = 0; i < OCTEP_MMIO_REGIONS; i++) + iounmap(oct->mmio[i].hw_addr); + + kfree(oct->conf); return -1; } -- 2.25.1