From patchwork Fri Aug 23 10:15:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 13774923 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 C19CFC531DC for ; Fri, 23 Aug 2024 10:19:37 +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:In-Reply-To:References :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:List-Owner; bh=st6dBA4B9Nv1zPtX9T/2rfu/snV3K8fE/9qGZsxtuyY=; b=Ogu5NHsH7NS+trARTFFvuxZkn6 3Ak8HOrWNmmL5IP/BoOLzdvxmpyPvctmPGm7ETeiu0KFU3y3cI1Ob0GV7uh14w9J5zsODH4VEQ9iO Xq3jdfj45ZV/iUJgjieSSWqw9UGTR4jsfkSlaNo/YNG5DVskfn/gNKv1ezrDr1IyR874fmaxnKf2m aW/bMBreiR6VikMlcpRbMJaWrC1auRRKj+jKnjdPSnZ9Omdf8CjkV/BZQGg8tuFclX0jBE0qSOq7q 5lGD70FmiRbVd8fkEYPeTPA6RcjVwzBMxQbbANzJFS0CR4LwWPz/RzHP8rsXCN94vg4Cxmwpcdjkc 6ZD7dCcQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1shROC-0000000GIvH-29PY; Fri, 23 Aug 2024 10:19:28 +0000 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1shRL2-0000000GHp5-1n6p for linux-arm-kernel@lists.infradead.org; Fri, 23 Aug 2024 10:16:13 +0000 Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-428e09ee91eso2187115e9.3 for ; Fri, 23 Aug 2024 03:16:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1724408170; x=1725012970; darn=lists.infradead.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=st6dBA4B9Nv1zPtX9T/2rfu/snV3K8fE/9qGZsxtuyY=; b=bXBNccoICLQepXVHRuurt1KGJqWB3vvAEccplze0SUyICU2DarZWoP71y1bdRzt1gH yrJ08p+xK+vKU6jJfgu6PTRSzmJtyzSxx8nWfZUqAThULN4SCDZuXlKA+D4ZMaFmmBq+ yBkohhcAMG7vqlXRmaGeJjN+x04lYsDW8DjyphmzjlYcq3Qa9/vdUCdS4pq4LLMzLc28 BilJJ6fO+Pfs+A9xEBILGF25SL/MsV2EaE7uX9kteX4Wrdrt9WeRWyV2PjjlIidjF7zL +pm81WwbO1+Vj85WIVSidUgU+yoGxECaCW89y7fCegtPbCuf0jtKWYJRZooxQRX6JgnR Y6Qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724408170; x=1725012970; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=st6dBA4B9Nv1zPtX9T/2rfu/snV3K8fE/9qGZsxtuyY=; b=Shkm5Q0eHF30UVoNaO3BL1t28JAPOUm9rI7S541bhfb5jG7XCECb1WXQXTpydcRTsa vQ7iu2URYccOrv7+9yNbESfqzt6r/a/gW4qXsp8s7Pth5cBS3ugVIdTEmCDxhv4gtOKf xZap39sli0fj+/ZT7Pslde0Diz/l4h6Eg+9uCfYkA8wW5ajoCjODRvxcFRPaicwcQMvJ CrU0EEnjcCzSABqi8YNx5KtEEE7G0L6Y6zLP6EoscecclK0BFA3CAbcsWVifTybi9Njg a79VcPIILzycx50AhfcRlgKJ2xWHUNwEezl0U8Nexi2dgc9k0eUXS5nEggNye7BQ/vAh C9GA== X-Forwarded-Encrypted: i=1; AJvYcCUYg+RmU1PvZYapufZxNvUbHuYocN6jfvAOMUjHoekuEfg9bEwz57MUL/YpNNNdEdiet+WlQlu3cW5fZBAo+N4e@lists.infradead.org X-Gm-Message-State: AOJu0YzGctelHf3Qdeyvn7sFZR8SQ1/SaoE1GrKIwJmQvrLKHCHaPObo ZmxgcXWS6iWxLzjSMIBc96Pze1SyWe5zuVAZV7vVUUtvRpkAhAZwCypfDe58EPfkUWUXWolodwT Y X-Google-Smtp-Source: AGHT+IHh+J5equdBgJ4usKEKsDj7Qu7AiwgUQ/PKWo7hs5cHZCzKxrqsYJ8/hj1kRnLZzBypj0LIRA== X-Received: by 2002:a5d:64cc:0:b0:366:eb60:bcf2 with SMTP id ffacd0b85a97d-3731185bd1cmr541652f8f.4.1724408170571; Fri, 23 Aug 2024 03:16:10 -0700 (PDT) Received: from [127.0.1.1] ([178.197.222.82]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a868f2a1df5sm237912166b.68.2024.08.23.03.16.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Aug 2024 03:16:10 -0700 (PDT) From: Krzysztof Kozlowski Date: Fri, 23 Aug 2024 12:15:58 +0200 Subject: [PATCH 3/7] memory: omap-gpmc: simplify locking with guard() MIME-Version: 1.0 Message-Id: <20240823-b4-cleanup-h-guard-v1-3-01668915bd55@linaro.org> References: <20240823-b4-cleanup-h-guard-v1-0-01668915bd55@linaro.org> In-Reply-To: <20240823-b4-cleanup-h-guard-v1-0-01668915bd55@linaro.org> To: Santosh Shilimkar , Krzysztof Kozlowski , Roger Quadros , Tony Lindgren , Vladimir Zapolskiy , Miquel Raynal , Michal Simek Cc: linux-kernel@vger.kernel.org, linux-omap@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Krzysztof Kozlowski X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=2384; i=krzysztof.kozlowski@linaro.org; h=from:subject:message-id; bh=c3EBYma5kTUA/zOkUfd/wHDJYd2x1OE5BHWso7TEYUU=; b=owEBbQKS/ZANAwAKAcE3ZuaGi4PXAcsmYgBmyGFgGrbj7x0yA560ueSSqqbWUdMCZ0SabmhuE ym90ud3QVCJAjMEAAEKAB0WIQTd0mIoPREbIztuuKjBN2bmhouD1wUCZshhYAAKCRDBN2bmhouD 12IOD/9vL/BYpE4yYF+b/K4kXxcWaYRXgrsbhNWRg8XaVfPIallsAQsvyKUqWN6t518a1OLo3b4 sn+hB2hXu7k9fg9FpOuCZehdoyMlkh2YuTIEXXIaxkenyb0u+pRzSaEcYgMJPGz72RkYlvK2I2v gERCuH1mD0G8KfBVSw1rCNMMtcpv5pOzbS1lFBIFLKCLssCwGCze2vpMhQlsSLKyvWEEroUqqv7 oz1hkNFujKVJEroViUTY3wnR0QAoR4Td2Uw0Pqc1sSvW6xLBFqp254JVqa9/cdTyEH4tTgQtanz T1jYRgOK3LuLs11JAveVcE4eaYM6M/hyoKgjj4YlFoaa7wdHpjYkCXhmLUiz+Q/fOb9ccZ16W02 ZZMUPeD/w+wqYHRFAabYbiHztb3l6CYiM3S5KkDR4+XpgzoxSAMxFG8Ps99oqasdJd2rohlJxA/ iPYIzJauth0VYLZzeNX6vTL5njvNWh37M++OXEv6bby67HJlhAGw4x2ZVNQyO5KsNq8TuBImT9o eijwwReaEd/XELR2g//Ai5o7jd/Cdfe4PEQc3DrdzIU3anUzRmIE3gE2kQsTn0RjeQ8BCLYWwVy VW6KvoTVgVf9msP1Zv8rL4XEu2NpYSICA5MFQXps7GgewmpcUxeWw7kgbfMpC+7NtuinXO1beS/ MyWW70f2i9MKLEg== X-Developer-Key: i=krzysztof.kozlowski@linaro.org; a=openpgp; fpr=9BD07E0E0C51F8D59677B7541B93437D3B41629B X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240823_031612_501960_0DBB563F X-CRM114-Status: GOOD ( 15.47 ) 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 Simplify error handling (less gotos) over locks with guard(). Signed-off-by: Krzysztof Kozlowski Reviewed-by: Jonathan Cameron --- drivers/memory/omap-gpmc.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/drivers/memory/omap-gpmc.c b/drivers/memory/omap-gpmc.c index 80d038884207..c8a0d82f9c27 100644 --- a/drivers/memory/omap-gpmc.c +++ b/drivers/memory/omap-gpmc.c @@ -9,6 +9,7 @@ * Copyright (C) 2009 Texas Instruments * Added OMAP4 support - Santosh Shilimkar */ +#include #include #include #include @@ -989,18 +990,18 @@ int gpmc_cs_request(int cs, unsigned long size, unsigned long *base) if (size > (1 << GPMC_SECTION_SHIFT)) return -ENOMEM; - spin_lock(&gpmc_mem_lock); - if (gpmc_cs_reserved(cs)) { - r = -EBUSY; - goto out; - } + guard(spinlock)(&gpmc_mem_lock); + + if (gpmc_cs_reserved(cs)) + return -EBUSY; + if (gpmc_cs_mem_enabled(cs)) r = adjust_resource(res, res->start & ~(size - 1), size); if (r < 0) r = allocate_resource(&gpmc_mem_root, res, size, 0, ~0, size, NULL, NULL); if (r < 0) - goto out; + return r; /* Disable CS while changing base address and size mask */ gpmc_cs_disable_mem(cs); @@ -1008,16 +1009,15 @@ int gpmc_cs_request(int cs, unsigned long size, unsigned long *base) r = gpmc_cs_set_memconf(cs, res->start, resource_size(res)); if (r < 0) { release_resource(res); - goto out; + return r; } /* Enable CS */ gpmc_cs_enable_mem(cs); *base = res->start; gpmc_cs_set_reserved(cs, 1); -out: - spin_unlock(&gpmc_mem_lock); - return r; + + return 0; } EXPORT_SYMBOL(gpmc_cs_request); @@ -1026,10 +1026,9 @@ void gpmc_cs_free(int cs) struct gpmc_cs_data *gpmc; struct resource *res; - spin_lock(&gpmc_mem_lock); + guard(spinlock)(&gpmc_mem_lock); if (cs >= gpmc_cs_num || cs < 0 || !gpmc_cs_reserved(cs)) { WARN(1, "Trying to free non-reserved GPMC CS%d\n", cs); - spin_unlock(&gpmc_mem_lock); return; } gpmc = &gpmc_cs[cs]; @@ -1039,7 +1038,6 @@ void gpmc_cs_free(int cs) if (res->flags) release_resource(res); gpmc_cs_set_reserved(cs, 0); - spin_unlock(&gpmc_mem_lock); } EXPORT_SYMBOL(gpmc_cs_free);