Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp880747pxk; Thu, 17 Sep 2020 20:12:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyoa4YfDJv81cd4UafXhS8nuGN8swsrEeWa04xc14x5WvWVs1PFDi0fKyjZjoN7boQEGQr5 X-Received: by 2002:a05:6402:176c:: with SMTP id da12mr37129097edb.386.1600398726881; Thu, 17 Sep 2020 20:12:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600398726; cv=none; d=google.com; s=arc-20160816; b=C+Xl5NA0GACl4ouKIDuTBN83w7f5/rtTFTrKgjxDULAY4hr88CqCUBv4yaIm1Onx0/ Q34dFipHCvzXaYLVr4DjHRhEsOfn3qYuuHK6ALk7M3CVo3iDpcTx8r8z3juxwepVB9tc sqQl1ulBwhS2rx17dH4miuXiDsyPZlRAZ0HFpFbN/IqNip6pBCkKfq/f4ExKndJOazzN 8dZGK+iDP9vCjHo69/YNYkKhN1cKDn+01aHoWlVz2oOivFmpSelKb7gWhjPQK4+ImKya rGZR88X5E0b3Wb0Te4HGzrJ9X+cp2iohw6X0V+mOsxgyIALSvTIYG9qFhBN2rJSU4JTn otLg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=yoIMlAElZ8gDtAxz8ce+NxUtQMZVMNPmRTNgK0eOjr0=; b=jZBoniABS5f5StBjJR+hyRXLsYy5NC0L3ckf5CGdPlS8CK+XJWCo4oyP4y349DXoTA JWDCJ2lo0grPI1bB40kc1SLTRN7KsYyA0y1jwnFbrOx472ncwCkgkzyfcCmT5eyLQUgx cGPbAzr5WWVSh8L+yt8zCKEZbJKI5Y73lY2eo0by9nnGyQTjrSoff4EkImWKlvK6SARz //WoP6TPGfIAwZBAg9Z8fU+UByrtFEpva8btCJJ45ERx/lIcgWbJL3aZyfgMmnYM/Rcs 2HsLEVp7HI/yYCwose0XvtFRwE3Y57f0dkODGYyy4aqRYhJaKWTyAENuxUTKgL2/QoEj xlIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=iNzxuLd0; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id jr1si1467184ejb.164.2020.09.17.20.11.43; Thu, 17 Sep 2020 20:12:06 -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=iNzxuLd0; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730504AbgIRDJi (ORCPT + 99 others); Thu, 17 Sep 2020 23:09:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:48838 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726824AbgIRCDA (ORCPT ); Thu, 17 Sep 2020 22:03:00 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id AEE6322211; Fri, 18 Sep 2020 02:02:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600394580; bh=6In8Y7DkPN2i+MJDFsQhZPWyJqsgDZkvzAAX35ClLiI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iNzxuLd0BC7K02/nUVJcccFg7wJfuYj07NYcr/ebBM+W9iXgeOeOqldVNImKSl6p/ HSshCx6xLUwtF5tdoreoI+RdbpS8Q1nbdFPFVCxepc2HJ9/DTM3ylM6EYk1m0B7ZvO Vb7paBxCDhMx4HT09tqrc0qsvg4B3sonZkTwXD28= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: "Rafael J. Wysocki" , Sasha Levin , linux-acpi@vger.kernel.org Subject: [PATCH AUTOSEL 5.4 091/330] ACPI: EC: Reference count query handlers under lock Date: Thu, 17 Sep 2020 21:57:11 -0400 Message-Id: <20200918020110.2063155-91-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200918020110.2063155-1-sashal@kernel.org> References: <20200918020110.2063155-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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) -- 2.25.1