From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796382424; b=cF1sZHMDozBNfQhhk9BDeCTPpQyvfAwES6h5/jaJZgQfmSZME7VqphF3bbFqeBYOlE7w A7YoyslQm+6h2cqqQIByEgJIVpY78sRHGY+mCReroghTl1meGVunQWn4F6WIPkIQLranR tsPWYX69akntLwDroGlTwLa+mwZjPi5gcS64DBl2JIUYcbttD0L/97Tcrfor/3nNi1M8S Zrg6+n+JuDpcWffDel0FTVpVICNCnvtHE1p7OaPhFJdJVBwOa47V81BCJIn0P6inWEdsn KRVwaLJCeGVsx5bQQS7DKqfDE8u1wg1rfYBYfUr3Ev4M5UPh09eP/6xxlhyPp6w8/tg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796382424; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Type:Content-Transfer-Encoding; bh=hJoheYHHFparIFznU/X4vGtVOA+0R/LySQ1TGd9Tjrw=; b=iSHxYfAIcUym2fdgQ8707J9o1hUgrJO1gByeBhwM0aeblkCIdp508fma2qx11KW194st LfmHI0HkDfiJNikfIcmr77jdL+mKwDFPOUrs/PAzHCg5lAGoJwW3NxD8nDAkkWwzvqT6D uIZXyQnqfQgmWbjwbMJAX6PYHxrM13T5PhJ6cAbUoIbVnd9rJ4aT5yRBJqFKjvvc5ScW8 ENeqqU+ZL77eMSFWgYin8xpdc+4kHVNlMdAjY99F37i6IaaPTMdj9LRMs+I+n5NvudRip 5wIh840AYuYQnrqgyvfBasw2Oj2vP7IuE8W8qYnbDwU6dQWecbhkpT6HbADJDfPr29g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=KsJVnkDV; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 78F2E606A32D; Fri, 4 Dec 2026 11:07:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=KsJVnkDV Received: by smtp.kernel.org (Postfix) with ESMTPSA id E93771F000C2; Fri, 4 Dec 2026 11:07:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796382424; bh=hJoheYHHFparIFznU/X4vGtVOA+0R/LySQ1TGd9Tjrw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=KsJVnkDVs4AHFDuImBkyu8ccs0e6hKuJBZC2IFyN3nQEzOY/anjWO83sbiu8VlNeL ITr/R9BrMWj9wm0ByvcCvFPOMZ5Sd42xD9VzFy1kjXcPlCErl+T5YaurzI9yKWQgDm V/9gTkL5iyasTSxrAF8REVPaf+C8cO/AeoFk4B1Q= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, =?UTF-8?q?Dav=C3=AD=C3=B0=20Steinn=20Geirsson?= , Guenter Roeck Subject: [PATCH 6.18 446/703] hwmon: Use per-device lockdep keys Date: Fri, 4 Dec 2026 19:05:45 +0900 Message-ID: <20261204100639.664060660@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Guenter Roeck commit f17d77541c909b7c03fa29095d45f23a79699879 upstream. Currently, mutex_init(&hwdev->lock) in __hwmon_device_register() assigns a single static lockdep key to all hardware monitoring device locks. If one hardware monitoring device accesses another hardware monitoring device (for example, pwm-fan controlling a PWM output provided by adt7470), lockdep sees two instances of the same lock class acquired in sequence and reports a false-positive recursive locking warning. Give each struct hwmon_device its own dynamic struct lock_class_key, registered via lockdep_register_key() and initialized with mutex_init_with_key() before any error path that calls hwmon_dev_release(), and cleaned up with mutex_destroy() and lockdep_unregister_key() in hwmon_dev_release(). This allows nested locking across distinct hwmon devices while preserving full lockdep deadlock and self-recursion detection. Fixes: 3ad2a7b9b15d ("hwmon: Serialize accesses in hwmon core") Cc: stable@vger.kernel.org Cc: Davíð Steinn Geirsson Signed-off-by: Guenter Roeck Signed-off-by: Greg Kroah-Hartman --- drivers/hwmon/hwmon.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) --- a/drivers/hwmon/hwmon.c +++ b/drivers/hwmon/hwmon.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -37,6 +38,7 @@ struct hwmon_device { const char *label; struct device dev; const struct hwmon_chip_info *chip; + struct lock_class_key lock_key; struct mutex lock; struct list_head tzdata; struct attribute_group group; @@ -136,6 +138,8 @@ static void hwmon_dev_release(struct dev hwmon_free_attrs(hwdev->group.attrs); kfree(hwdev->groups); kfree(hwdev->label); + mutex_destroy(&hwdev->lock); + lockdep_unregister_key(&hwdev->lock_key); kfree(hwdev); } @@ -923,6 +927,8 @@ __hwmon_device_register(struct device *d } hdev = &hwdev->dev; + lockdep_register_key(&hwdev->lock_key); + mutex_init_with_key(&hwdev->lock, &hwdev->lock_key); if (chip) { struct attribute **attrs; @@ -977,7 +983,6 @@ __hwmon_device_register(struct device *d tdev = tdev->parent; hdev->of_node = tdev ? tdev->of_node : NULL; hwdev->chip = chip; - mutex_init(&hwdev->lock); dev_set_drvdata(hdev, drvdata); dev_set_name(hdev, HWMON_ID_FORMAT, id); err = device_register(hdev);