From patchwork Fri Sep 27 14:02:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Zabel X-Patchwork-Id: 13814343 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1ECA9CDD1B2 for ; Fri, 27 Sep 2024 14:04:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=DFkxZesFWkIhSMn9PRT8+xmm0hnX8LdRQSHGRaDGO1g=; b=cNdh+RZktWNDF+F4q+Mca3M43A CQeX9/lxuq+O8Yv1KUE04dsqGCLHotdlrbCjZe9ggNNpW7NPAklAWezhy5wXSUEmNh9VuBi+U501E P7JAcQ0ZyevOLq3kgKhWwEfC7MmZaGV6AbFRNZ3N9/Iyy374ev3MgbQOJNs2UA+O31f1Q41VMTvy/ uOeqz/kqM0mmVW9zusgy3FOCldhdnQ2GHLFvUDTC0xHBB3ZjXNUWUERVapFC51EgT2w5xm731D24q ZQ5zKvXclMW9E/XUoY3Iy5mUyBPNbR0L/IyUlgmh5vsJOOD4K0+DSyQvqu87jXCNQ/I6hV6MT2jMP nvH2pAiQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1suBa7-0000000BPOy-1hoL; Fri, 27 Sep 2024 14:04:27 +0000 Received: from metis.whiteo.stw.pengutronix.de ([2a0a:edc0:2:b01:1d::104]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1suBYJ-0000000BOuD-45SB for linux-arm-kernel@lists.infradead.org; Fri, 27 Sep 2024 14:02:37 +0000 Received: from dude05.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::54]) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1suBYH-000740-8T; Fri, 27 Sep 2024 16:02:33 +0200 From: Philipp Zabel Date: Fri, 27 Sep 2024 16:02:32 +0200 Subject: [PATCH] reset: Further simplify locking with guard() MIME-Version: 1.0 Message-Id: <20240927-reset-guard-v1-1-293bf1302210@pengutronix.de> X-B4-Tracking: v=1; b=H4sIAPe69mYC/y3MSwqAMAxF0a1IxhZqKIpuRRyUNmomftIqQnHvF nV4HrybIJAwBeiKBEInB16XjKoswM12mUixzwbUaHSLjRIKFNV0WPHKGfSjR4u1ayA/NqGRr7f WD5+F9iNH4z/e9wO22c/WcgAAAA== To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel@pengutronix.de, Krzysztof Kozlowski Cc: Philipp Zabel X-Mailer: b4 0.15-dev-13183 X-SA-Exim-Connect-IP: 2a0a:edc0:0:1101:1d::54 X-SA-Exim-Mail-From: p.zabel@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-arm-kernel@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240927_070236_059153_E0CADDBD X-CRM114-Status: GOOD ( 11.39 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Use guard(mutex) to automatically unlock mutexes when going out of scope. Simplify error paths by removing a goto and manual mutex unlocking in multiple places. Follow-up to commit 3ec21e7fa854 ("reset: simplify locking with guard()"). Signed-off-by: Philipp Zabel --- drivers/reset/core.c | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) --- base-commit: 487b1b32e317b85c2948eb4013f3e089a0433d49 change-id: 20240927-reset-guard-c42dfd2a26c7 Best regards, diff --git a/drivers/reset/core.c b/drivers/reset/core.c index 4d509d41456a..6fbc6f3c14c9 100644 --- a/drivers/reset/core.c +++ b/drivers/reset/core.c @@ -676,25 +676,20 @@ int reset_control_acquire(struct reset_control *rstc) if (reset_control_is_array(rstc)) return reset_control_array_acquire(rstc_to_array(rstc)); - mutex_lock(&reset_list_mutex); + guard(mutex)(&reset_list_mutex); - if (rstc->acquired) { - mutex_unlock(&reset_list_mutex); + if (rstc->acquired) return 0; - } list_for_each_entry(rc, &rstc->rcdev->reset_control_head, list) { if (rstc != rc && rstc->id == rc->id) { - if (rc->acquired) { - mutex_unlock(&reset_list_mutex); + if (rc->acquired) return -EBUSY; - } } } rstc->acquired = true; - mutex_unlock(&reset_list_mutex); return 0; } EXPORT_SYMBOL_GPL(reset_control_acquire); @@ -1041,29 +1036,27 @@ __of_reset_control_get(struct device_node *node, const char *id, int index, } } - mutex_lock(&reset_list_mutex); + guard(mutex)(&reset_list_mutex); rcdev = __reset_find_rcdev(&args, gpio_fallback); if (!rcdev) { rstc = ERR_PTR(-EPROBE_DEFER); - goto out_unlock; + goto out_put; } if (WARN_ON(args.args_count != rcdev->of_reset_n_cells)) { rstc = ERR_PTR(-EINVAL); - goto out_unlock; + goto out_put; } rstc_id = rcdev->of_xlate(rcdev, &args); if (rstc_id < 0) { rstc = ERR_PTR(rstc_id); - goto out_unlock; + goto out_put; } /* reset_list_mutex also protects the rcdev's reset_control list */ rstc = __reset_control_get_internal(rcdev, rstc_id, shared, acquired); -out_unlock: - mutex_unlock(&reset_list_mutex); out_put: of_node_put(args.np); @@ -1098,7 +1091,7 @@ __reset_control_get_from_lookup(struct device *dev, const char *con_id, const char *dev_id = dev_name(dev); struct reset_control *rstc = NULL; - mutex_lock(&reset_lookup_mutex); + guard(mutex)(&reset_lookup_mutex); list_for_each_entry(lookup, &reset_lookup_list, list) { if (strcmp(lookup->dev_id, dev_id)) @@ -1107,11 +1100,9 @@ __reset_control_get_from_lookup(struct device *dev, const char *con_id, if ((!con_id && !lookup->con_id) || ((con_id && lookup->con_id) && !strcmp(con_id, lookup->con_id))) { - mutex_lock(&reset_list_mutex); + guard(mutex)(&reset_list_mutex); rcdev = __reset_controller_by_name(lookup->provider); if (!rcdev) { - mutex_unlock(&reset_list_mutex); - mutex_unlock(&reset_lookup_mutex); /* Reset provider may not be ready yet. */ return ERR_PTR(-EPROBE_DEFER); } @@ -1119,13 +1110,10 @@ __reset_control_get_from_lookup(struct device *dev, const char *con_id, rstc = __reset_control_get_internal(rcdev, lookup->index, shared, acquired); - mutex_unlock(&reset_list_mutex); break; } } - mutex_unlock(&reset_lookup_mutex); - if (!rstc) return optional ? NULL : ERR_PTR(-ENOENT);