Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1213311pxa; Thu, 20 Aug 2020 05:50:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxEb0WLGeu1YOkHs3glnVAmNmm0FC+6DayPZazYrMBPA3HCS2i3d9j+UhjgOZX4m7iOX4Jy X-Received: by 2002:a17:906:ce59:: with SMTP id se25mr3229223ejb.359.1597927842547; Thu, 20 Aug 2020 05:50:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597927842; cv=none; d=google.com; s=arc-20160816; b=w/UEEKTZY54HdK895yYj2F593MAVjG0FH9k46BlhZsRgogsgh7w4kmqjEXzJIOJOw+ V4jbUTfefwRmUaktKUI/IUSl/H96Xpo1+MYKnJ7RHmg/ttFlqOiMnjM0kZKBBtkB2Sdr kTs8mgFRbhtZOE4FpSTKXxtI+PfXbWDBw5oUV5EqFEPjQDUB9zegmGU+0vMEA7oNUGri Mlpi4M3DWSNpEwL3G0A017f/iAPhMRsQRs6qK9sLiEmU4rFflnsD4D59jnL9WOnHGV8C 7HomQFt1A3w8aoCYtZuL80BxDWSFYLNnV7PtTBjx7P8wUePuXcO5WKcAl7WwjEg+Blt8 8LuA== 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=0k3rT+mfwIknGWrqpt9m68DcNDqdIbX3L+Cdb7aN4J2xp9TgxmIBKC/PRPPJmrvn7t 9eXFxdghmTszTGX1HnfkkXox2Fooiu/nZE5F5l2+T+E481HVRPsIPzBR0X6vb+J3ZZDX AejWgRfRy+D0APwX3LuqM6whQY8aISFf0lN8GbLyoJkyUKZ0LY3AFeXv//gB0G0K5arA 7VuO9vqye45sFFACNGkMUGwgpRklL0LJ5b+VtTe9Ci2VCbYD7+t9mbdeunjApQ/VVWzG LXV/N71LDKfCWAn+qyfMRu1rGAO3GZX/kAiQQTcIpRoL63qkWfS0pPhm3llzYb9gsZyL r0nw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=lUjnIdek; 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 bd21si1348822edb.117.2020.08.20.05.50.18; Thu, 20 Aug 2020 05:50:42 -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=lUjnIdek; 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 S1730316AbgHTMri (ORCPT + 99 others); Thu, 20 Aug 2020 08:47:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:42570 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729212AbgHTJp3 (ORCPT ); Thu, 20 Aug 2020 05:45:29 -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 81C9D22D3E; Thu, 20 Aug 2020 09:44:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597916688; bh=CB91mRZZtwRX5Rs6Z2McPo2ROvipo0Nrx6PjkXAUo9k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lUjnIdekwuKj0EslyrqzQXFaeeO9AtI2RuKFgaeCSiX+2o7/bu58rTOx4N9p2OeG6 Iv20mW+ZaYFXBzUZkVciH+yGxM/cD9ACLTTuMWfdS7ww2SyntBLmEiDQF/ncy7ljjg 4s3C6fwKPcodVLExs3SSvZ3SnTUEuF1q/o+gddx8= 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 5.4 004/152] PCI: hotplug: ACPI: Fix context refcounting in acpiphp_grab_context() Date: Thu, 20 Aug 2020 11:19:31 +0200 Message-Id: <20200820091553.844491744@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200820091553.615456912@linuxfoundation.org> References: <20200820091553.615456912@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; }