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=1796380950; b=4hFFqv8UvKGMf5WfU45jLEAKNKZJo7zRKu/ne4e3IlA4RVsepI8ko+pUYnYNLIK8oZUV Z2thRsCxMb+A2q3A1EkejOmpOeRDS1sv6dJIBu5TQZB0a7/BgjTQgkzaeFAQNUOLCbBfU QB7x3H1MQfwH/5DcL7oLyS7YpUNseZm3ljadeuxc3L6mGIzxmCoxTDOXayA4BuKQcYt06 zMBwu/tsWwXqmv7ZlrKtMnGOGaWS2v81Vwh3nwR2CS3qemWGFYli5al6Xtqmg6XlMGhIv 7KwD0k4+dyAZ4r1+LTet3z3GCsRmnsbZuwF0RBgJSXkQLYDGXg9Y0wJGiMsn3+/zPbQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796380950; 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=ITG08PrippwX6/dEK6ZhKS/92bHYCtHZpvhunUZ7LKo=; b=S2v79eoSf7hOelD/mlS9kIwqmIhK/EaRn18b/MqG91RF9whb98gKsEgfIqf3vfrLFYCv qKmkdbv3Yy+P0Q8V/nT5+hO37K8Ga0r9+QCn4ryjVybgTJQsABasq4mHPU+IgGYIGGxFr b9zgOZzSlaWv/8lHdl4p4+jZnQNqrplnZybaY91sZwl7Be964hJnNE9YbVgDrqcvHFmX6 kzAYAHrlrO3l2DuvKmO8sJM4ERoNi8mEBa9nv5PgFpbJv20tWm8vtgjcxCO/nA4Yy9imd PorS3DpJ5Xsr/sdMR7lrqJoZA7WHc4BnyAObed0TXdwblbGjaxV5ROalyvTmPOeB82w== 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=LSa0l6Zk; 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 4A2DA606A335; Fri, 4 Dec 2026 10:42:30 +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=LSa0l6Zk Received: by smtp.kernel.org (Postfix) with ESMTPSA id BAF6A1F0092C; Fri, 4 Dec 2026 10:42:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796380950; bh=ITG08PrippwX6/dEK6ZhKS/92bHYCtHZpvhunUZ7LKo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=LSa0l6ZkYg0vyC+7/XWJvy+JZ4AJ6rD+pgB9fKbZ3sZPaQFfHwuQ4/aVZxJb8DDzi qGtfBx7YiYagNopK8CPaMsEE2QHnQU5kD1mmNKfMoXfxl5GbLhIDF3M7UA7HLheFwx cPRgzUh0EFlP8/rPCWrs8y8bUZK+7K2TkslkkI9w= 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 7.3 495/742] hwmon: Use per-device lockdep keys Date: Fri, 4 Dec 2026 19:05:59 +0900 Message-ID: <20261204100648.285614001@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@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 7.3-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_const); kfree(hwdev->groups); kfree(hwdev->label); + mutex_destroy(&hwdev->lock); + lockdep_unregister_key(&hwdev->lock_key); kfree(hwdev); } @@ -933,6 +937,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) { const struct attribute **attrs; @@ -987,7 +993,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);