Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3522117pxf; Mon, 15 Mar 2021 11:25:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz1b6P2OMwUllro7bFO/payPAPTvy0ePzMjhtr0ffLu2VMCe4olJoYu7zIeXy9a8C638W9u X-Received: by 2002:aa7:cd54:: with SMTP id v20mr31791964edw.80.1615832732106; Mon, 15 Mar 2021 11:25:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615832732; cv=none; d=google.com; s=arc-20160816; b=I9lgQYWY08fv0kwonwpu30hRz/1ZrLU2lP9YdZMioRrREv7RTAk1RgLEOBJidjgSRB TjJDEJeJm0JSvBxz891JkpO4epQ4KPxHvU5qZSUNTy+RdYYuSWwYftd4htXjmaW+sKob xSIxggwDrY9vb9H6cXOssu1Wxq+etH053zCuVw1VNsY4ba9UqmmUjlsFcf86jqg4Rsz4 8+nb2sBzTDpqNkZtxtOV3dSThMcP/BZTowtkzRC6Pq5sfWYi7IgWsTUzIngv4dOZGtAH 6qAnVnU2ONYYhCqtHutHx4xKicQ1zNpcUsOAPJPqVr+H0PKVC89zlsVgZ2OVQtotrpob uqLg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=XyCbf7X84ykJ5v+tHiEhW8UtUBxEDufDQRJGs0+Lhvw=; b=uhu3cxeRQqxTeRLIAtOMAe7jjV8U7uKJSRROjR8RlgcCeRPiANt8KgN004EqfXX37e wy7lziCaSVVKjS9mp2x10ARWKaGYMchrdJDYU/k4o/gS6wWyouEZeMu04kZtKuAFyZ9M OQAe04GvfM5ZRM3OUkVJnN3gprBEqdNFEFeQidIDrNih3Tcp2Fp0jXpjE7DKkiQdw1rD 1PiagonxNxf3adI9M36PEWub2huGjvALWa6X7N5OPrN2kwSa6mSFD+0s1j8rDMUFVFnd VF6Xgz1qyKHGa2W6U5HzXzIS/y6y9A0V3J71Ddg6ZTxqvLg0qPsjC8NJJF+4DUHDbd2C BDxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=CZTwnIIq; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id jo14si12035182ejb.460.2021.03.15.11.25.09; Mon, 15 Mar 2021 11:25:32 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=CZTwnIIq; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231688AbhCOOYK (ORCPT + 99 others); Mon, 15 Mar 2021 10:24:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:35610 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231990AbhCOOAR (ORCPT ); Mon, 15 Mar 2021 10:00:17 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 520F764F18; Mon, 15 Mar 2021 14:00:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615816803; bh=enOh4DF4ELE20QCSde+JnHmzf2w8hW8NSNxMlRnX/uI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CZTwnIIq+XSLs2DKoxcjT2ZcPjDyVRMXXz0yWiPTRIa07Q5FTrMPlIG8xkq3N5C18 wzw92TZ+oFZnv2YZjLQZleoB8CW0zDSzPry5MkULGqJYepGdAlQmCPf8ee7zNsPm8V Vf9+DrRw4+qmR1qC4bnZt0Ii1dZdg0F+ruaBz3xg= From: gregkh@linuxfoundation.org To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Pan Bian , Hans de Goede , Sasha Levin Subject: [PATCH 5.11 134/306] platform/x86: amd-pmc: put device on error paths Date: Mon, 15 Mar 2021 14:53:17 +0100 Message-Id: <20210315135512.178419088@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315135507.611436477@linuxfoundation.org> References: <20210315135507.611436477@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Greg Kroah-Hartman From: Pan Bian [ Upstream commit 745ed17a04f966406c8c27c8f992544336c06013 ] Put the PCI device rdev on error paths to fix potential reference count leaks. Signed-off-by: Pan Bian Link: https://lore.kernel.org/r/20210121045005.73342-1-bianpan2016@163.com Reviewed-by: Hans de Goede Signed-off-by: Hans de Goede Signed-off-by: Sasha Levin --- drivers/platform/x86/amd-pmc.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/drivers/platform/x86/amd-pmc.c b/drivers/platform/x86/amd-pmc.c index ef8342572463..b9da58ee9b1e 100644 --- a/drivers/platform/x86/amd-pmc.c +++ b/drivers/platform/x86/amd-pmc.c @@ -210,31 +210,39 @@ static int amd_pmc_probe(struct platform_device *pdev) dev->dev = &pdev->dev; rdev = pci_get_domain_bus_and_slot(0, 0, PCI_DEVFN(0, 0)); - if (!rdev || !pci_match_id(pmc_pci_ids, rdev)) + if (!rdev || !pci_match_id(pmc_pci_ids, rdev)) { + pci_dev_put(rdev); return -ENODEV; + } dev->cpu_id = rdev->device; err = pci_write_config_dword(rdev, AMD_PMC_SMU_INDEX_ADDRESS, AMD_PMC_BASE_ADDR_LO); if (err) { dev_err(dev->dev, "error writing to 0x%x\n", AMD_PMC_SMU_INDEX_ADDRESS); + pci_dev_put(rdev); return pcibios_err_to_errno(err); } err = pci_read_config_dword(rdev, AMD_PMC_SMU_INDEX_DATA, &val); - if (err) + if (err) { + pci_dev_put(rdev); return pcibios_err_to_errno(err); + } base_addr_lo = val & AMD_PMC_BASE_ADDR_HI_MASK; err = pci_write_config_dword(rdev, AMD_PMC_SMU_INDEX_ADDRESS, AMD_PMC_BASE_ADDR_HI); if (err) { dev_err(dev->dev, "error writing to 0x%x\n", AMD_PMC_SMU_INDEX_ADDRESS); + pci_dev_put(rdev); return pcibios_err_to_errno(err); } err = pci_read_config_dword(rdev, AMD_PMC_SMU_INDEX_DATA, &val); - if (err) + if (err) { + pci_dev_put(rdev); return pcibios_err_to_errno(err); + } base_addr_hi = val & AMD_PMC_BASE_ADDR_LO_MASK; pci_dev_put(rdev); -- 2.30.1