From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8C128362120 for ; Mon, 23 Feb 2026 10:06:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771841212; cv=none; b=DM2BPE9XRX6PDvyNvWk6QLBePAopGpzjdEATaKDrNcimKbm6lHqnyOU/eIfZenzco6FjoAaQxd/dr3EpYkaLojbDgwDvO26XkfslU1GYiCYCUSTXW9Fv9e0DONUfWrfMcbqvhuI6T5ilAXIoQBSRf3jxxwwampZiqCxT5Tznnzg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771841212; c=relaxed/simple; bh=FJixpdRr9RVjSNGAF4dAgado5bV56wITIMLjI/KfEC8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=jbuHKb9lPpUtLTpJnTmYVvO4FVcw6nnE6hfmqJmKBwUnt4gQjuuuVQZTlXha9Zi5Q1IwSeGJK7eRfUopVSswC8IUrQeLMg1XkCGVGsEipz6xEj1LcfEcb2f6IQ9luIYGBDFT5JpYTGHQ1LrSf+pnmhP/Eswx2gKYTQcNejEH4QY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b=bwjtz3bV; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=OGTo0zRQ; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b="bwjtz3bV"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="OGTo0zRQ" Received: from pps.filterd (m0279864.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 61N9c18T3234263 for ; Mon, 23 Feb 2026 10:06:50 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= rg6UttrPDN9MfpCZ9fONPOkfz6eMrgkH8r0kh8ZqjyQ=; b=bwjtz3bVTvOL6O3m PKiVGXgMQt9jdbxepOXF2v0ZoKzi7w0nUFdBbSDCzjb70sT0AguA+MheArimYzdH nsxJ9qc0bl1/YXjx9FXeLgQ05sg1I75E+DiFqEl84YFBT7gS0q+KaICw5HWumEk8 2B1DYnW2CKyKpjnZKDs45ycTZEMQI25jrEls098dTK1UEXmCk5jUOBn0j+48J1D9 7HjwY9KAjLiJXla7K9Mvfq41VQBgAi98G85V6EOa6oN+3iL3q5Q4wbo0Sq+sHvJb KlbAZUqtTk2S8o4BuYfGPcr5OodfQQtBPtKga+7j/9KM8XtxjV8rH1CdAdtJlHb1 Aua9zQ== Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4cf5wk4901-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Mon, 23 Feb 2026 10:06:49 +0000 (GMT) Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-8cb0595def4so5316618485a.0 for ; Mon, 23 Feb 2026 02:06:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1771841209; x=1772446009; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=rg6UttrPDN9MfpCZ9fONPOkfz6eMrgkH8r0kh8ZqjyQ=; b=OGTo0zRQneRtBLNAY93nOt5sn6DdSp3G3DWMdWnI7ZWyVqq4A7URZI+KTvw30fhv+F Lkk0k+jKfZqYdlP/zBlxAcT3ErfqXb8xo0iNv8UdNO4/IwiaDChMPz1eVdiTgw5Svs96 qcBI5eIZAUSKf1aj9Ffwgf2RSNZDLR6za3JdqgQ6kagplRerL2VAdJEvkvRkFCkZKp3/ yrSTQuTp7dtJmq+Z/NmHfDDmD8s/M4lsr2bMlzWY+Sw8PFAIJrsyb1IW6ETeQbYxWty2 0JV+6S2d2sgba50ggxwx5YhJqqfQmDP7EZg3x4VxlpZ46gou6syEBT7YHjTS7YZPvB11 japw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771841209; x=1772446009; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=rg6UttrPDN9MfpCZ9fONPOkfz6eMrgkH8r0kh8ZqjyQ=; b=Qhsf2U5CZggzt+gyzLa2SYAzPZ2WDS6Ptfy39uv+smzhMlfQ/0A0t0KHbVv5jRd0dW N0LLQaZcYMwq1B1UL4Xll0lzlfyFLRj8cwty+mNRRO6v/JfuVxE+cM6pRuYPGQ/xkjBK 3zL/PZcpiIz1//UjxytjzPBzxRr7NH+bySOtWsqPYs/39Mujqt+qzjbT+m+7YHHW9Vtz YtXKGZOsQB61aw8wcofy2f64bZPEVVCZWd4Xit0DSjpmUMzRYFJnLjW9rfdlLM9qGe02 mhKomv8ttjxa5AcDJPd5LNaVyj95VVaV5P+8msWsGzU0KS0pGX47Z/TLMOFy5K2s54AT HUkg== X-Gm-Message-State: AOJu0YyBQ9e1uJGr9RGQZr9wG+kJ4NFt9za2MKfdtymguLgyCyFRc8Q0 QFXFelRQzFFH7nqBFM5bhv3ghoLfnSTIqZYe9guWniaHhS/+ds2loRYJ3Glo/e5TuU+/TMvprMx wloA3anLhVsIEPDuX5cNl3IPL1TtK2GKkqH77Fof3h73vC3gVhq4EcwF2/N6UFZOgjho= X-Gm-Gg: AZuq6aI2PayzxgJ2A1akmHsostHg/xun/oztccwYwOzlR7YcoGc7byW3qTKFMDeO2tL atj2mszlgsn/yr3gPVU0j6CMKLv79NVVlB1/zT739C2WzbbYbaYhlQTbdjvTnEggIT2ybXNuqyc qMaZzSvvkK5xoDcwz22bzRv+QjtIjLIuNfF4Jz+nMtbFhnxUYGET4F8DLnvuDtaaop+dayewlBX bAzEck4XNxrTkCak5aFfrJzVf4UCUSUZhgTiN/RIQqvZK13sllRsSmyPATnK7ObiIdqzYRDOtq1 2/5zYeGosV5SMwaG9xxvpYEfLt4Y2kYxPXMZxYphLyV1j7jWV88GHhSN0iK+n/2yymPswT06EQX 8ah8WRf01d7W3qRJrLFekmIxjZinRUuNx31L1rgZDc4P7N0E0SaKb X-Received: by 2002:ae9:ea0a:0:b0:8cb:83d8:31bd with SMTP id af79cd13be357-8cb83d836c2mr975735185a.40.1771841208680; Mon, 23 Feb 2026 02:06:48 -0800 (PST) X-Received: by 2002:ae9:ea0a:0:b0:8cb:83d8:31bd with SMTP id af79cd13be357-8cb83d836c2mr975733685a.40.1771841208227; Mon, 23 Feb 2026 02:06:48 -0800 (PST) Received: from brgl-qcom.local ([2a01:cb1d:dc:7e00:bd71:422c:5e83:8b37]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43970d54760sm18288885f8f.35.2026.02.23.02.06.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Feb 2026 02:06:47 -0800 (PST) From: Bartosz Golaszewski Date: Mon, 23 Feb 2026 11:06:23 +0100 Subject: [PATCH v2 10/14] reset: protect struct reset_control with its own mutex Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260223-reset-core-refactor-v2-10-5e5a7289190c@oss.qualcomm.com> References: <20260223-reset-core-refactor-v2-0-5e5a7289190c@oss.qualcomm.com> In-Reply-To: <20260223-reset-core-refactor-v2-0-5e5a7289190c@oss.qualcomm.com> To: Krzysztof Kozlowski , Philipp Zabel Cc: linux-kernel@vger.kernel.org, Bartosz Golaszewski X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=5041; i=bartosz.golaszewski@oss.qualcomm.com; h=from:subject:message-id; bh=FJixpdRr9RVjSNGAF4dAgado5bV56wITIMLjI/KfEC8=; b=owEBbQKS/ZANAwAKAQWdLsv/NoTDAcsmYgBpnCapCvHSLtZRXRlys2e+f+SxucYyfek/Rypkj 2tVxYIhCBSJAjMEAAEKAB0WIQSR5RMt5bVGHXuiZfwFnS7L/zaEwwUCaZwmqQAKCRAFnS7L/zaE w8LAD/0ba5XGHVSHAvMTgn41dqGYKvuFlQPQ/+MJCUhJypPetuGakYjhwlOTYZP76T2bSASGAOt gmAUu13LWrH/Mz8yoqiUf++jBmFGcMkcGy7T+UJMGNHjD7wrb2KQYD2XOJlFLWauTF6+Ot8i/ys V64DeGBIpT7XlivcscI7CJAYJjftUnF9aH2vECEuqZ+gP8cNtN89rgjOMoq3gdOAzHLUte9NohS juITjaweqXzXQoz7GJ83DmDZGkyeBEen4VFGR6X7QQketjoF1wzT8pkFaiwTce/GfCIpAPGKhza iw3XlUGSGCU1shZCQ1MeHSlc9cMcsRAirKdm8YBtZvoMfLz3/tYv/9oyM1ayq4NOX+pylOB6aEG I9OEmAURFK1/lcnT3T2ya+CYpFE+JSPCzg3gaKjCvyCziYvvOVj6MknX7Jf4s6/tPF8bs3B8d72 rHfksJJOPxd2V+7kgQX+6aJq0hWSVBWDkv/q32gzxj+HNmZjSm7yaxiwz6yEETtdiTORy71Veqw D8/FxNG9z4nzJ0AyGGR+8nmSBs2gHvjXJQzap8PFgxEkc8Qzo2l9TkcCgSgBr/72jMSIgk3ygEx J5HqL8LjtBFaeSwa4FMshIwDcpBe0usqCcCQwR+RmtE9zclHO3TW8f+BONiTNkLsAImZn1I599P oBpDFGkJv1Zbngg== X-Developer-Key: i=bartosz.golaszewski@oss.qualcomm.com; a=openpgp; fpr=169DEB6C0BC3C46013D2C79F11A72EA01471D772 X-Authority-Analysis: v=2.4 cv=a6k9NESF c=1 sm=1 tr=0 ts=699c26b9 cx=c_pps a=HLyN3IcIa5EE8TELMZ618Q==:117 a=xqWC_Br6kY4A:10 a=IkcTkHD0fZMA:10 a=HzLeVaNsDn8A:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=DJpcGTmdVt4CTyJn9g5Z:22 a=EUspDBNiAAAA:8 a=dYSpPNroVltAtaK4QdUA:9 a=QEXdDO2ut3YA:10 a=bTQJ7kPSJx9SKPbeHEYW:22 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwMjIzMDA4NiBTYWx0ZWRfXygkFUVj2zVEK 0rnny06ny+pMTjU3ckR24HGjpaFEZ6bQnZ9LvwSvhlvDneK445aZhNeJ2ubyA0UrPjd98ruV7Sw Pa2hw2/FXQYAiJSfn0YOnG6E/PFggCYldKVbK3zxwxYifxO5u+PSVeqAOUm+KHI0qfshqgHXJ2i 3b7kahOuKFNgY5SM3+S9uU7w2d8X6258vH01A/AgRPRJvsCYJdTvZsgALhy5iv722Ocd6fypzgj aoYVsrh1KpG+FxKWFS378E2I/UOIXzJdFkmngLTNlOhKC9l6UYJTEC20sye5zXJDDoCW5WcNsXC FgObw4Zt+53Z6vrwfKZ0JktgP/Cu9v/osL3Niv5tCPQLkmH1WJGrM+5W7prTHPQfergP+iFeVNj igl8FsMMhfxhEEe+Q99QEOCO5GFRayo5mp0yBFuUGgYaReEFTvkV2OoRgM5XCH7iK+EU/G+ovPq C3z8IYwL7MQYl0mFh8Q== X-Proofpoint-ORIG-GUID: _SSKw1J0TiV3NUDFbUkRoIHBS2tA2-iG X-Proofpoint-GUID: _SSKw1J0TiV3NUDFbUkRoIHBS2tA2-iG X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-02-23_02,2026-02-20_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 suspectscore=0 phishscore=0 impostorscore=0 priorityscore=1501 bulkscore=0 lowpriorityscore=0 adultscore=0 spamscore=0 clxscore=1015 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2602130000 definitions=main-2602230086 Currently we use a single, global mutex - misleadingly names reset_list_mutex - to protect the global list of reset devices, per-controller list of reset control handles and also internal fields of struct reset_control. Locking can be made a lot more fine-grained if we use a separate mutex for serializing operations on the list AND accessing the reset control handle. Signed-off-by: Bartosz Golaszewski --- drivers/reset/core.c | 38 ++++++++++++++------------------------ 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/drivers/reset/core.c b/drivers/reset/core.c index d4813c712abf3df7993b0c2be1fe292b89241d11..647e7112779517d2425f55728e1e7fb6e76a8045 100644 --- a/drivers/reset/core.c +++ b/drivers/reset/core.c @@ -49,6 +49,7 @@ static DEFINE_IDA(reset_gpio_ida); * @triggered_count: Number of times this reset line has been reset. Currently * only used for shared resets, which means that the value * will be either 0 or 1. + * @lock: Serializes access to other fields of this structure */ struct reset_control { struct reset_controller_dev __rcu *rcdev; @@ -61,6 +62,7 @@ struct reset_control { bool array; atomic_t deassert_count; atomic_t triggered_count; + struct mutex lock; }; /** @@ -707,7 +709,7 @@ int reset_control_acquire(struct reset_control *rstc) if (reset_control_is_array(rstc)) return reset_control_array_acquire(rstc_to_array(rstc)); - guard(mutex)(&reset_list_mutex); + guard(mutex)(&rstc->lock); if (rstc->acquired) return 0; @@ -859,6 +861,7 @@ __reset_control_get_internal(struct reset_controller_dev *rcdev, list_add(&rstc->list, &rcdev->reset_control_head); rstc->id = index; kref_init(&rstc->refcnt); + mutex_init(&rstc->lock); rstc->acquired = acquired; rstc->shared = shared; get_device(rcdev->dev); @@ -872,8 +875,6 @@ static void __reset_control_release(struct kref *kref) refcnt); struct reset_controller_dev *rcdev; - lockdep_assert_held(&reset_list_mutex); - scoped_guard(srcu, &rstc->srcu) { rcdev = rcu_replace_pointer(rstc->rcdev, NULL, true); if (rcdev) { @@ -882,15 +883,14 @@ static void __reset_control_release(struct kref *kref) } } + mutex_destroy(&rstc->lock); synchronize_srcu(&rstc->srcu); cleanup_srcu_struct(&rstc->srcu); kfree(rstc); } -static void __reset_control_put_internal(struct reset_control *rstc) +static void reset_control_put_internal(struct reset_control *rstc) { - lockdep_assert_held(&reset_list_mutex); - if (IS_ERR_OR_NULL(rstc)) return; @@ -1104,7 +1104,7 @@ __of_reset_control_get(struct device_node *node, const char *id, int index, { bool optional = flags & RESET_CONTROL_FLAGS_BIT_OPTIONAL; bool gpio_fallback = false; - struct reset_control *rstc; + struct reset_control *rstc = ERR_PTR(-EINVAL); struct reset_controller_dev *rcdev; struct of_phandle_args args; int rstc_id; @@ -1169,8 +1169,8 @@ __of_reset_control_get(struct device_node *node, const char *id, int index, flags &= ~RESET_CONTROL_FLAGS_BIT_OPTIONAL; - /* reset_list_mutex also protects the rcdev's reset_control list */ - rstc = __reset_control_get_internal(rcdev, rstc_id, flags); + scoped_guard(mutex, &rcdev->lock) + rstc = __reset_control_get_internal(rcdev, rstc_id, flags); out_put: of_node_put(args.np); @@ -1213,10 +1213,8 @@ int __reset_control_bulk_get(struct device *dev, int num_rstcs, return 0; err: - guard(mutex)(&reset_list_mutex); - while (i--) - __reset_control_put_internal(rstcs[i].rstc); + reset_control_put_internal(rstcs[i].rstc); return ret; } @@ -1226,10 +1224,8 @@ static void reset_control_array_put(struct reset_control_array *resets) { int i; - guard(mutex)(&reset_list_mutex); - for (i = 0; i < resets->num_rstcs; i++) - __reset_control_put_internal(resets->rstc[i]); + reset_control_put_internal(resets->rstc[i]); kfree(resets); } @@ -1247,9 +1243,7 @@ void reset_control_put(struct reset_control *rstc) return; } - guard(mutex)(&reset_list_mutex); - - __reset_control_put_internal(rstc); + reset_control_put_internal(rstc); } EXPORT_SYMBOL_GPL(reset_control_put); @@ -1260,10 +1254,8 @@ EXPORT_SYMBOL_GPL(reset_control_put); */ void reset_control_bulk_put(int num_rstcs, struct reset_control_bulk_data *rstcs) { - guard(mutex)(&reset_list_mutex); - while (num_rstcs--) - __reset_control_put_internal(rstcs[num_rstcs].rstc); + reset_control_put_internal(rstcs[num_rstcs].rstc); } EXPORT_SYMBOL_GPL(reset_control_bulk_put); @@ -1482,10 +1474,8 @@ of_reset_control_array_get(struct device_node *np, enum reset_control_flags flag return &resets->base; err_rst: - guard(mutex)(&reset_list_mutex); - while (--i >= 0) - __reset_control_put_internal(resets->rstc[i]); + reset_control_put_internal(resets->rstc[i]); kfree(resets); -- 2.47.3