Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1201446pxa; Thu, 20 Aug 2020 05:30:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyZq1jrcY7ouilq5caLfyfoM+xWgGWRD8kFOp+rV6eysl3+PJq6c7+K03mSLBsT0EZCUKXF X-Received: by 2002:a17:907:9483:: with SMTP id dm3mr3110668ejc.333.1597926652287; Thu, 20 Aug 2020 05:30:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597926652; cv=none; d=google.com; s=arc-20160816; b=kUhm0DiOKRA1EaaAO/IsM0536xSP8K0j90NdYYUqC6oK6KxvE+IOaUYlfKFY8D9hI6 VlLVpP65pMz2j4dmdsgOaX4deefDS0mVnSLIRi8jmJmBecez9yBYrACDwUP/2kPydKbq +Jex8NnuQpyYI2kq0ym0F246cbpSwk0FrbxsCd2MeBdtyvMzFP/8NCp7AO3LWXrVpeda uYvog7OOJbvU6VVslwY6dyca71cfaGSa/NOmFt4imf4VGBpL4b/ROmWcBoJNMgRvo9zL vMXwTLHpT8ByunGXJxq3Et/3xr6+fVj92HDxAtFTSdahzzZcSZHtMP30AGZaykbNvVL/ swTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=B6J0f6aR5ZhYpIOzJkPshM2K6XqpWaXheOLqVvxW6NQ=; b=InLlPg7+z9vnzAsQlWT9GwTO5NAI2x/7eijbGjU2DBpnns31oP9Kyvr8Xrp/bf49+z AON3dl1DvW12bKxPpk1imPay+KBFW2Tgk+R5Raf+nPD6uzBaI9+vNLUfgq2p8pK5EZZi xeJRryW/vQtRZ2unjjZfnc3MVOFz4GQ/YplS83zZ9hWkqs6dSK7e6UCO84/ItaIJvbRP hNcs43PJ5GL5yBeceVXr9GM8yhJKPbh2LNjmjnJXI6iojYCzc4Jny4x69Vy5r2nk7KWT 3JXNJdxgW/UGw0F4w/FN+feIaonjUDpMYUunNTCNyGiLVoResjtIUJpIe0soZk3ByKOO DNzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="dFKwq5/Z"; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 39si1293121edq.552.2020.08.20.05.30.28; Thu, 20 Aug 2020 05:30:52 -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=@kernel.org header.s=default header.b="dFKwq5/Z"; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730194AbgHTM1y (ORCPT + 99 others); Thu, 20 Aug 2020 08:27:54 -0400 Received: from mail.kernel.org ([198.145.29.99]:33226 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729879AbgHTJwF (ORCPT ); Thu, 20 Aug 2020 05:52:05 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 34EC02078D; Thu, 20 Aug 2020 09:52:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597917122; bh=CB91mRZZtwRX5Rs6Z2McPo2ROvipo0Nrx6PjkXAUo9k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dFKwq5/ZY45YTrCT85wXupL/TEmFdAmtyj0qe2NVl21r62+FlBFTQDocLCYeKMV0S 8USlRwdh6WxZcN4jAz5arZ8WV/ZSxUOsDYl5OdNJa9HIm7SE8JWf5bP7xEi2fKOnto /g7K8e3SH2qdno3U9neFLkS+3BXQmtEyzuHqZEU4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vasily Averin , "Rafael J. Wysocki" Subject: [PATCH 4.19 03/92] PCI: hotplug: ACPI: Fix context refcounting in acpiphp_grab_context() Date: Thu, 20 Aug 2020 11:20:48 +0200 Message-Id: <20200820091537.671767388@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200820091537.490965042@linuxfoundation.org> References: <20200820091537.490965042@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Rafael J. Wysocki commit dae68d7fd4930315389117e9da35b763f12238f9 upstream. If context is not NULL in acpiphp_grab_context(), but the is_going_away flag is set for the device's parent, the reference counter of the context needs to be decremented before returning NULL or the context will never be freed, so make that happen. Fixes: edf5bf34d408 ("ACPI / dock: Use callback pointers from devices' ACPI hotplug contexts") Reported-by: Vasily Averin Cc: 3.15+ # 3.15+ Signed-off-by: Rafael J. Wysocki Signed-off-by: Greg Kroah-Hartman --- drivers/pci/hotplug/acpiphp_glue.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) --- a/drivers/pci/hotplug/acpiphp_glue.c +++ b/drivers/pci/hotplug/acpiphp_glue.c @@ -122,13 +122,21 @@ static struct acpiphp_context *acpiphp_g struct acpiphp_context *context; acpi_lock_hp_context(); + context = acpiphp_get_context(adev); - if (!context || context->func.parent->is_going_away) { - acpi_unlock_hp_context(); - return NULL; + if (!context) + goto unlock; + + if (context->func.parent->is_going_away) { + acpiphp_put_context(context); + context = NULL; + goto unlock; } + get_bridge(context->func.parent); acpiphp_put_context(context); + +unlock: acpi_unlock_hp_context(); return context; }