Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1431173pxb; Wed, 20 Oct 2021 05:07:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy18ixIhd25cT03c9ZKJ3U2npLG6KAQ2LAT7t+/H1eYE9tGCVGXEEFRfJKF0bneriwiF5im X-Received: by 2002:a17:906:4793:: with SMTP id cw19mr43466534ejc.200.1634731656643; Wed, 20 Oct 2021 05:07:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634731656; cv=none; d=google.com; s=arc-20160816; b=rMpMFkxBcwdGs5QqY3gGiZAfp3qbGVSN5qUky7ik4jIxHWKcxapWSsmhT6+7lVdTKN SFH/OUgK7vBYKcVbrj+aoO11doj98VkVDn/Bs/xf1H/JLB+kSPikuBdBLsPSeW2yg/MD PwtxDQRIJWtT4T6GHMtHpP83fsbpCjeeUGbgdGxoUzSA5mM+3NPpoiWYmxmBLPn34GXh Oy2sV+a5GfdXgkQyoIkQYATYguRsPMJtsmgu/dwqNOHNgPJh9tG+Al6iQPI5SiEZokBx EGYP1yw2pw0aerGANXV1Ug17cPBiVM2sdK+VEzvJLolAMDr5J+rMTSUF0o8mFsOftrvT 9S+g== 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:cc:to:from; bh=MWHVHtj6/OGIriwnGkSRM66ppoA+W3Ezf1LBO6VmhCw=; b=H+kGRgORXx/QM7e2AuYuOB9odt+5iRj7Q3RjInWZXV735DSuBWGduDDmJR6sTU8IHw Q2WWZk1oUDE6FLYxxi6oNw5Rz9oqdhhlhycs2ICSQ2ObHO4s0gCAc7uQ+UmOjci6IKul K0wrrgJDj1Zc2SggEXCncXYo5WXOsORoHCi3C0MK7DdZLzZBjGjnbCZ/6ihWzQ0fqQq9 g+Fd6CzbQA2T3XdstpDyWw0s8/8hOsdJ2WxiYX7yAeU1A96faHcsoAbMFpTz6+ZeS8bV Er4h5ssikdCHdRp7ucsAU1tmJEOUhACCkqWNmzltT7rDarf6tFzU2qAxhc1vSTHlygGQ T1Ow== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n22si2380927eda.113.2021.10.20.05.07.08; Wed, 20 Oct 2021 05:07:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230308AbhJTMHE (ORCPT + 99 others); Wed, 20 Oct 2021 08:07:04 -0400 Received: from szxga08-in.huawei.com ([45.249.212.255]:26104 "EHLO szxga08-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230265AbhJTMHC (ORCPT ); Wed, 20 Oct 2021 08:07:02 -0400 Received: from dggemv704-chm.china.huawei.com (unknown [172.30.72.55]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4HZ8Pt6jHCz1DHh8; Wed, 20 Oct 2021 20:02:58 +0800 (CST) Received: from kwepemm600001.china.huawei.com (7.193.23.3) by dggemv704-chm.china.huawei.com (10.3.19.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.15; Wed, 20 Oct 2021 20:04:43 +0800 Received: from huawei.com (10.175.104.82) 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.2308.15; Wed, 20 Oct 2021 20:04:42 +0800 From: Wang Hai To: , , , , , , , CC: , , , Subject: [PATCH v2 wireless-drivers 2/2] libertas: Fix possible memory leak in probe and disconnect Date: Wed, 20 Oct 2021 20:03:45 +0800 Message-ID: <20211020120345.2016045-3-wanghai38@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211020120345.2016045-1-wanghai38@huawei.com> References: <20211020120345.2016045-1-wanghai38@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.104.82] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To kwepemm600001.china.huawei.com (7.193.23.3) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org I got memory leak as follows when doing fault injection test: unreferenced object 0xffff88812c7d7400 (size 512): comm "kworker/6:1", pid 176, jiffies 4295003332 (age 822.830s) hex dump (first 32 bytes): 00 68 1e 04 81 88 ff ff 01 00 00 00 00 00 00 00 .h.............. 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ backtrace: [] slab_post_alloc_hook+0x9c/0x490 [] kmem_cache_alloc_trace+0x1f7/0x470 [] if_usb_probe+0x63/0x446 [usb8xxx] [] usb_probe_interface+0x1aa/0x3c0 [usbcore] [] really_probe+0x190/0x480 [] __driver_probe_device+0xf9/0x180 [] driver_probe_device+0x53/0x130 [] __device_attach_driver+0x105/0x130 [] bus_for_each_drv+0x129/0x190 [] __device_attach+0x1c9/0x270 [] device_initial_probe+0x20/0x30 [] bus_probe_device+0x142/0x160 [] device_add+0x829/0x1300 [] usb_set_configuration+0xb01/0xcc0 [usbcore] [] usb_generic_driver_probe+0x6e/0x90 [usbcore] [] usb_probe_device+0x6f/0x130 [usbcore] cardp is missing being freed in the error handling path of the probe and the path of the disconnect, which will cause memory leak. This patch adds the missing kfree(). Fixes: 876c9d3aeb98 ("[PATCH] Marvell Libertas 8388 802.11b/g USB driver") Reported-by: Hulk Robot Signed-off-by: Wang Hai --- drivers/net/wireless/marvell/libertas/if_usb.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/net/wireless/marvell/libertas/if_usb.c b/drivers/net/wireless/marvell/libertas/if_usb.c index 20436a289d5c..5d6dc1dd050d 100644 --- a/drivers/net/wireless/marvell/libertas/if_usb.c +++ b/drivers/net/wireless/marvell/libertas/if_usb.c @@ -292,6 +292,7 @@ static int if_usb_probe(struct usb_interface *intf, if_usb_reset_device(cardp); dealloc: if_usb_free(cardp); + kfree(cardp); error: return r; @@ -316,6 +317,7 @@ static void if_usb_disconnect(struct usb_interface *intf) /* Unlink and free urb */ if_usb_free(cardp); + kfree(cardp); usb_set_intfdata(intf, NULL); usb_put_dev(interface_to_usbdev(intf)); -- 2.25.1