From patchwork Wed Jun 12 13:11:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Carrasco X-Patchwork-Id: 13694968 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 030F2C27C53 for ; Wed, 12 Jun 2024 13:11:35 +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=wNDZP3olXhf0m0jznv4sHsrpG3mrdyMI3Wu77Y+9NAw=; b=Z4Y6lXR+fAt1M0Pwt5G+bA6/Iu u6SlJxWZZ8uRitr8SHWeu/Lt3PwFpfdGvL+Kn8Qk87F6yTl1jdPZn4fwbI7BRPwcyEnFqOkbB9sS7 uB9enplJA2wU9mV2GfDWDeZNGmr5AcsTqPWHPWTOAnGrd85sMne/bAjIfXho2fg5lB1WUzUTdIZvU bfTebeW0kZgDg0JirKn/EE/c91JE4nvCalf7nKmwqsse0oyGK8H5ZR6JdeFyAnWu0a/XqslWrLqd9 f1B/ywvZs2MtMUtrCAc9OfAMok9hdZiUodwdVQuAFPPjAcFvZypT0oZqpDH2DT+Pehllwqvz4lXEm Uuu5oaLA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sHNl4-0000000CgmA-1q9v; Wed, 12 Jun 2024 13:11:22 +0000 Received: from mail-ed1-x530.google.com ([2a00:1450:4864:20::530]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sHNl0-0000000Cgj9-1Cuf for linux-arm-kernel@lists.infradead.org; Wed, 12 Jun 2024 13:11:20 +0000 Received: by mail-ed1-x530.google.com with SMTP id 4fb4d7f45d1cf-57c7ec8f1fcso4659402a12.0 for ; Wed, 12 Jun 2024 06:11:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718197874; x=1718802674; darn=lists.infradead.org; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:from:to:cc:subject:date:message-id:reply-to; bh=wNDZP3olXhf0m0jznv4sHsrpG3mrdyMI3Wu77Y+9NAw=; b=GqKu8Y1ZVxRLFrvUQ5WrF/kiXiZ1boD7k/pPJo9Vqg4MTFQ9rq4t0PZdXGlCYK3if0 cJilZqlXRY4R91vRbVcwZPKhF9/3OVRJuEPxz+C/IUz6ScAc8K4xIkIS5oI26H51Bt9E VHLr9/YTRmyhUekIkrUf81Tb3E5syQfceet6H2PqRxNJ1q7ORbk8J6mZcur4gj3ophmn epeLPr128VhyFplR8VSVJSst+/XS6t0jqiWYOT4evfXds+srd5VLQ0LDVwwLUikXWgUJ HlwdTHe+8WAoaJ0t+a/9m0+OZrYDwW7qwvpbAgfZamBVUouANGcT36Nd3kqdKfYM/wW8 mJjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718197874; x=1718802674; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=wNDZP3olXhf0m0jznv4sHsrpG3mrdyMI3Wu77Y+9NAw=; b=XwmBg8+ERmRKbhZnzZP8B5Qra2NaYcsf0yvdOZ6Keip5NIKQmZk7SS5AAUlLTQiv1/ K0V1ffAOl0gLjdBMPBylS6lXIvTQImqdaGgkgoUVdkYs1tq6UeoGP84Ru/R5vyId/vq2 673PQpRz13nc8qPxyPplp8YraSnnp7ARj7aH5LBGMiDtqnxi7l53pU/3X2LnhcCrHmbB PODuPKceyqF68t/GQyb9GKPHgU3ao14fnOu5CJikGaNNGYhK4+Z79VOvG8aG8MVLdwa7 k0GGuBlfSVV4xcG8pOql1wl7pHDzq2Go4raQvBKu/0Ea59esLnVt3eftbvXoYHC330eG AyVg== X-Forwarded-Encrypted: i=1; AJvYcCWTwDghZJeak9X3uI/KchWf3NLogwRaVSm70bvC5iHDoeXT5ogUH+gJYSziYw4zzZmy+JWARU04RVjFnukR8AMyqAOdbHtuP4t2aQCPF4z6hLUKGU4= X-Gm-Message-State: AOJu0Yy4sftA7tEBEGzxzPffAqPEUjAVfsvZNvj2cNej0n0yCT6ejhMw jI2wZr7/FwGDeyYE2BBlBHrT9dUJZinXCg7IPyj/ujXM+p/HbTvn88peTB/D X-Google-Smtp-Source: AGHT+IGp/qoxB+zL6ngPmsZ4PnHWEDtB+UvZ6sOM9/TIP4yOSEHF/GZYEmSsDYcsZ0tU6XTE6HW/0g== X-Received: by 2002:a17:906:2da2:b0:a6f:309d:f889 with SMTP id a640c23a62f3a-a6f48013fe8mr107003566b.54.1718197874324; Wed, 12 Jun 2024 06:11:14 -0700 (PDT) Received: from [127.0.1.1] (84-115-213-103.cable.dynamic.surfer.at. [84.115.213.103]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a6f00108531sm591165666b.211.2024.06.12.06.11.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 06:11:13 -0700 (PDT) From: Javier Carrasco Date: Wed, 12 Jun 2024 15:11:01 +0200 Subject: [PATCH] coresight: cti: move fwnode_handle_put to the early break MIME-Version: 1.0 Message-Id: <20240612-coresight-cti-platform-handle-put-v1-1-6817c5854e2b@gmail.com> X-B4-Tracking: v=1; b=H4sIAGSeaWYC/x2NQQqDMBAAvyJ77oKuIbX9SvEgyUYX1IRNlIL49 4YeB4aZCzKrcIZ3c4HyKVniXqF7NOCWaZ8ZxVcGasm0tiN0UTnLvBR0RTCtUwlRN6yuXxnTUdA b/7L0tNQPPdROUg7y/T8+433/AFYyVLRzAAAA To: Suzuki K Poulose , Mike Leach , James Clark , Alexander Shishkin Cc: coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Javier Carrasco X-Mailer: b4 0.14-dev X-Developer-Signature: v=1; a=ed25519-sha256; t=1718197872; l=2158; i=javier.carrasco.cruz@gmail.com; s=20240312; h=from:subject:message-id; bh=e9aTL45b/5VauqiLnFJX3VwIBSY8e722VlmpSLAk3tg=; b=3Wt9ngjsY/3xxjem8OHTiHgddO/flhIkmQ7tilcfn9FzzYWRyMMO2Y5YNHOeLhys1fzAX3sYo /i34OUYRjrHDOgvSRp/eVgl9F/jyMCXv0BOlQ3DJQwCt4t8pY6W9bfe X-Developer-Key: i=javier.carrasco.cruz@gmail.com; a=ed25519; pk=lzSIvIzMz0JhJrzLXI0HAdPwsNPSSmEn6RbS+PTS9aQ= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240612_061118_379305_3C6AE383 X-CRM114-Status: GOOD ( 15.72 ) 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 The explicit call to fwnode_handle_put() is only required if the fwnode_for_each_child_node() loop contains early exits. On the other hand, it is not required otherwise, and its usage is then unnecessary. The current approach is not buggy (NULL pointer is ignored), but can be optimized by limiting the calls to fwnode_handle_put() to the case where it is really necessary. Move fwnode_handle_put() to the early break within the loop to avoid calling the function when it is not required. Signed-off-by: Javier Carrasco --- Note that this issue was already mentioned during the patch review [1], but the outcome was that fwnode_handle_put() is required for early exits. Apparently, that was the end of the discussion, but the call to the function that decrements the refcount is unnecessary if the end of the loop is reached without any break/goto/return. This issue was found while analyzing the code, and I don't have the hardware to validate it beyond compilation and static analysis. Any tests to catch regressions with real hardware are always welcome. Link: https://lore.kernel.org/all/20191119231912.12768-8-mike.leach@linaro.org/ [1] --- drivers/hwtracing/coresight/coresight-cti-platform.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) --- base-commit: 83a7eefedc9b56fe7bfeff13b6c7356688ffa670 change-id: 20240612-coresight-cti-platform-handle-put-d4d962762383 Best regards, diff --git a/drivers/hwtracing/coresight/coresight-cti-platform.c b/drivers/hwtracing/coresight/coresight-cti-platform.c index ccef04f27f12..5aec37be1177 100644 --- a/drivers/hwtracing/coresight/coresight-cti-platform.c +++ b/drivers/hwtracing/coresight/coresight-cti-platform.c @@ -426,10 +426,11 @@ static int cti_plat_create_impdef_connections(struct device *dev, if (cti_plat_node_name_eq(child, CTI_DT_CONNS)) rc = cti_plat_create_connection(dev, drvdata, child); - if (rc != 0) + if (rc != 0) { + fwnode_handle_put(child); break; + } } - fwnode_handle_put(child); return rc; }