From patchwork Fri Dec 6 17:37:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thadeu Lima de Souza Cascardo X-Patchwork-Id: 13897528 X-Patchwork-Delegate: pkshih@realtek.com Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6C57A220681 for ; Fri, 6 Dec 2024 17:37:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.60.130.6 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733506652; cv=none; b=hUV7FQuyB4kVAlMnHxddiA1i69ZSRWAvnRIhhbTGV69SgItQMgYUT/ijhusGN41wLpf/wt45qvZkflLneVmypmuSM6Ssona1NBSyq1OclMNJGHBQRGP/BMJB2NUl+lFOKf4AafmKk+fi3Ho2sxikCKOslvxWtfwSTEfxseQKuxw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733506652; c=relaxed/simple; bh=8mm+oheBy3kJBRUCVtw0bhOr3mG8c2ExlpQlJTxqRRQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=hdv+LhbXfZKkh3PscXb4GZZjElcWcPmTLD+VsV48oc/195WHD5xc/zV4VJDMxkGPjqjV8MVylyi1kC7gaJShL8sVHGtdmKrOTLzlHxTZszLbgCDRoj2w1oq8K2yJDTJsRuMj0UFI+KfH2PjyE3ha/KybwJcEvs6Wd4qtS8pr7OQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=mnhx7vd+; arc=none smtp.client-ip=178.60.130.6 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="mnhx7vd+" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=frp+1S5rnDFTEK/6ccNCZaLIUqKtwge4ykyvnw0KTm8=; b=mnhx7vd+BuN26E6Irz3Xmz5FEo kQ8szOBCU62xPdYQosaX82V0pcNTHJoQi1Ve7o1fin0jF9fEYbj/x24lAb6HwAObu7Ncm3JqXiBID XVWVKL10JzUA9VmVSh+J8QiNPED6M1A3jSAZb676D3KDwu7hVBsGfpbYoWVhwGy+TfPLrKZDrrjJ7 M+c5XNkpt/5WUNSV/U7c3996DEdfkKS2XzcBBsrmmMeqp78wH0HRTbOZkhUJVaq1d165G/UM5JHsA YQVDYL1F/CnD9umof62N7Y3Ci5fF//Hj7pMlki0Jfge8v0yVb/Qw6uvrtxy4jtzBTyqIXRlDPb7DQ Vh3T0tEg==; Received: from 179-125-79-245-dinamico.pombonet.net.br ([179.125.79.245] helo=localhost.localdomain) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1tJcGe-00HUvD-7p; Fri, 06 Dec 2024 18:37:28 +0100 From: Thadeu Lima de Souza Cascardo To: linux-wireless@vger.kernel.org Cc: Ping-Ke Shih , Kalle Valo , kernel-dev@igalia.com, Thadeu Lima de Souza Cascardo Subject: [PATCH v2 3/4] wifi: rtlwifi: fix memory leaks and invalid acess at probe error path Date: Fri, 6 Dec 2024 14:37:12 -0300 Message-Id: <20241206173713.3222187-4-cascardo@igalia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241206173713.3222187-1-cascardo@igalia.com> References: <20241206173713.3222187-1-cascardo@igalia.com> Precedence: bulk X-Mailing-List: linux-wireless@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Deinitialize at reverse order when probe fails. When init_sw_vars fails, rtl_deinit_core should not be called, specially now that it destroys the rtl_wq workqueue. And call rtl_pci_deinit and deinit_sw_vars, otherwise, memory will be leaked. Remove pci_set_drvdata call as it will already be cleaned up by the core driver code and could lead to memory leaks too. cf. 8d450935ae7f ("wireless: rtlwifi: remove unnecessary pci_set_drvdata()") and 3d86b93064c7 ("rtlwifi: Fix PCI probe error path orphaned memory"). Fixes: 0c8173385e54 ("rtl8192ce: Add new driver") Signed-off-by: Thadeu Lima de Souza Cascardo --- drivers/net/wireless/realtek/rtlwifi/pci.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/net/wireless/realtek/rtlwifi/pci.c b/drivers/net/wireless/realtek/rtlwifi/pci.c index e60ac910e750..a870117cf12a 100644 --- a/drivers/net/wireless/realtek/rtlwifi/pci.c +++ b/drivers/net/wireless/realtek/rtlwifi/pci.c @@ -2165,7 +2165,7 @@ int rtl_pci_probe(struct pci_dev *pdev, if (rtlpriv->cfg->ops->init_sw_vars(hw)) { pr_err("Can't init_sw_vars\n"); err = -ENODEV; - goto fail3; + goto fail2; } rtl_init_sw_leds(hw); @@ -2183,14 +2183,14 @@ int rtl_pci_probe(struct pci_dev *pdev, err = rtl_pci_init(hw, pdev); if (err) { pr_err("Failed to init PCI\n"); - goto fail3; + goto fail4; } err = ieee80211_register_hw(hw); if (err) { pr_err("Can't register mac80211 hw.\n"); err = -ENODEV; - goto fail3; + goto fail5; } rtlpriv->mac80211.mac80211_registered = 1; @@ -2213,9 +2213,12 @@ int rtl_pci_probe(struct pci_dev *pdev, set_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status); return 0; -fail3: - pci_set_drvdata(pdev, NULL); +fail5: + rtl_pci_deinit(hw); +fail4: rtl_deinit_core(hw); +fail3: + rtlpriv->cfg->ops->deinit_sw_vars(hw); fail2: if (rtlpriv->io.pci_mem_start != 0)