From patchwork Tue Sep 29 10:56:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 263077 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 765ECC4727C for ; Tue, 29 Sep 2020 12:12:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 27AF92075A for ; Tue, 29 Sep 2020 12:12:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601381529; bh=Ez7h5Y7dNN75H9HX5nWi6Lv6jInqTF30XzoxscAwpBY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=gTnS6jOsiy5yF5/7YGNhQRjCNC1020oFbB2XPfBhKordkTpz37RG0Y9E/+4vTh8E2 3YstW/uH/C5kyNVSK43g1UC1wpsc6m0w0czgziNp5MjEQKuUztpKsMXzsYoP9UTB+M oMp/v6B8lHC4iSK9UPFnscpMaSEpkYyywb41j7Os= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730558AbgI2MMA (ORCPT ); Tue, 29 Sep 2020 08:12:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:53442 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730155AbgI2Lhc (ORCPT ); Tue, 29 Sep 2020 07:37:32 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 337DC23B9B; Tue, 29 Sep 2020 11:35:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601379309; bh=Ez7h5Y7dNN75H9HX5nWi6Lv6jInqTF30XzoxscAwpBY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2TNCQnb1q0HfcuXtjxeot7vKx+j623/oTduzy3rmuAAzV0DUSVVugW0fgEcjs/DOn Tz4Vi1twwiQmudDYJr+QD33fMJr2UohZnRFQYZhOp2GQ+lDTCTlrzsDYbn7Xdq+kjN EB1lgfZj98bebwA6ZMVakd1Ml9pFo1wb4403lTcU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Rafael J. Wysocki" , Sasha Levin Subject: [PATCH 5.4 088/388] ACPI: EC: Reference count query handlers under lock Date: Tue, 29 Sep 2020 12:56:59 +0200 Message-Id: <20200929110014.744953208@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200929110010.467764689@linuxfoundation.org> References: <20200929110010.467764689@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Rafael J. Wysocki [ Upstream commit 3df663a147fe077a6ee8444ec626738946e65547 ] There is a race condition in acpi_ec_get_query_handler() theoretically allowing query handlers to go away before refernce counting them. In order to avoid it, call kref_get() on query handlers under ec->mutex. Also simplify the code a bit while at it. Signed-off-by: Rafael J. Wysocki Signed-off-by: Sasha Levin --- drivers/acpi/ec.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c index 57eacdcbf8208..1ec55345252b6 100644 --- a/drivers/acpi/ec.c +++ b/drivers/acpi/ec.c @@ -1043,29 +1043,21 @@ void acpi_ec_unblock_transactions(void) /* -------------------------------------------------------------------------- Event Management -------------------------------------------------------------------------- */ -static struct acpi_ec_query_handler * -acpi_ec_get_query_handler(struct acpi_ec_query_handler *handler) -{ - if (handler) - kref_get(&handler->kref); - return handler; -} - static struct acpi_ec_query_handler * acpi_ec_get_query_handler_by_value(struct acpi_ec *ec, u8 value) { struct acpi_ec_query_handler *handler; - bool found = false; mutex_lock(&ec->mutex); list_for_each_entry(handler, &ec->list, node) { if (value == handler->query_bit) { - found = true; - break; + kref_get(&handler->kref); + mutex_unlock(&ec->mutex); + return handler; } } mutex_unlock(&ec->mutex); - return found ? acpi_ec_get_query_handler(handler) : NULL; + return NULL; } static void acpi_ec_query_handler_release(struct kref *kref)