Received: by 2002:ab2:7a09:0:b0:1f8:46dc:890e with SMTP id k9csp259221lqo; Wed, 15 May 2024 13:35:59 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWaqp09p3MIzLStzZlLVGdflQpqkg+rHfHDK0x6AxCLzoC89psg7WhIq2oNCcW68Kfd07QtOtaZDWxmpJsLD4lAzXLLAkDwjKOHeeRkXw== X-Google-Smtp-Source: AGHT+IHDIma4v27YIiOzGJWo4CvHlsEc2+vbwaWQ/E+eIBRIKdOK12wp6u/o+t2brSoJW750QKAm X-Received: by 2002:ac8:7e83:0:b0:43a:d398:588e with SMTP id d75a77b69052e-43dfce2592cmr282788511cf.23.1715805359383; Wed, 15 May 2024 13:35:59 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715805359; cv=pass; d=google.com; s=arc-20160816; b=l8wDkKLf/uafpR2dxtu3lPZBUK69x03WCfhgFpjKPq6bSygNneUbjp86nhmPtZIdFg Llw8dur4iEmmGQCOd+CTHVvDifzH9UetQSTTmNVgkEeGw99+zCBUojnjZ1YVcQUI5v3d mYQ6cAAcYufNZdIZNlL//CQMHnIVV9fzd3Zbg4pYpkqRkuCYdnMELvi7t94D0+pvwHWs RC+aN05lXxNs0sEAlpK7Km0EJSDiMoTDSAPhm7+3M3+rt9pBZirK8yd020pnVWRGDl+a 7N/FEWcmogwo9MQUCHI2eCvJOrz9F6jdcxCzRMkPl+/CcDj1OfCfJImxYDjF5XU0VGOn iglw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=EhDrIIYuqrWkc8JCUvRQERr8uFUaepc3V2Gr+6xnLX4=; fh=EcNs45uKCm4zW558vufaQfLRKQaFBSNAySq9KVBlALo=; b=Gd+Iw61Ya3PH7aVrmjY72RdzS7We2JLjbf7dB/nN2fBg4YPYDXz6BCao0ijIBffWsh jYAw3c0cKy8m8aI5ts2gkD0xtA9gFKq3Qw1YZji+5nhwm9Lk9eDAPnF7HVc+zsDnIMDc MqDJavPmVhRDp9nSU1qc93jkjDUMh3dTwZaJm6YxfIWeJhBbrz2iPUvLTu1nwqg2mK3t G0yOTkMPCeWmROPodcYO5Jm+knU/dh6hMyJwHtelYy27DorwXgiScxMSuOQa6PLx3tfP 9EO24Q18EzmsesxrGd2Ld1XudXm5fAEDm6cg2l6NOboF1NlTjIFrsU1dXECnnyaWp238 B/fg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=dDClOATh; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-180350-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-180350-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id d75a77b69052e-43e12a09576si90288381cf.526.2024.05.15.13.35.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 13:35:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-180350-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=dDClOATh; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-180350-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-180350-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 13F3E1C220E9 for ; Wed, 15 May 2024 20:35:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2296315B544; Wed, 15 May 2024 20:35:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dDClOATh" Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E0A0615B14E; Wed, 15 May 2024 20:35:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715805333; cv=none; b=aDoGSUBhGVFsmMgQpyuBga88oIcZzG37SgXctVoksmNYDzVUkjBTxbedxDactg+Z5nX5gDXETFa0LvEiugsu1w2R8ZZ9IBJJmTEw79FXgV7ZcG8mmWsjrNhd2G6rR6PdMJrbpW6/ysLkVNkE5LvXRSZRt9CzC4Sh8TdwP5o1g9k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715805333; c=relaxed/simple; bh=VbGJP2NaAz4tBqRFEIPiguZVuuL1Evp7KZQ6dB94Z3Y=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=bWOIwOyVLfjxwlkgZPXom/ZHBuFarYUqkF1lwLfZANos2BvEhfuZdOhlBe/BsKtVYqy8pCQPmuJdbVwhZxgP/zZEsX4BRCsMSgN18ueGWMb5GGRXOAp9T/6tPID0e0uUnwnttgzt5YJnjlTRU6tsyp/eR7i6NulN7QAnm2VqAQI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=dDClOATh; arc=none smtp.client-ip=209.85.210.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-6f4ed9dc7beso3257313b3a.1; Wed, 15 May 2024 13:35:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715805331; x=1716410131; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=EhDrIIYuqrWkc8JCUvRQERr8uFUaepc3V2Gr+6xnLX4=; b=dDClOATh6LxoRt6euC9hn3ObXHpBScNM6Qhj3zA04Lq/0Dj/1P/cLca3hRCFPy8KQP n/5q89DZrmMws50grmEXZfy7FJ08OjM1KPiNK/O3B07IseNh1TEfj9G4CmmmryDTR0Yr v0KqnYSRCp7t6CVvKlublPtf7B+Z19JFsVXB/gbdqmdako4Ve5I6Ob1UVv8qwABYAwn2 eurWwCj12GPsu3t1SwGgLnSj79f/RSN92577pP+2l/JxPKFNaZ/wtE6hHsP0bKxF9+iA wPfMdqc+lAGGeDkIMDkVBBQsqh0fJrBwrrcRZ7Jzz2IfIpQbXkvnoz4HYvY8QgtTqWY0 R2lQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715805331; x=1716410131; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=EhDrIIYuqrWkc8JCUvRQERr8uFUaepc3V2Gr+6xnLX4=; b=BM+WTbNQkqKsDceKrXrdpPZR6ytkd+n3CR8sFuSaWGTlpsL2fXifraJ+TDVAbcYRlr gDhLIlLXYFYziOPgOV/kLceptyyxffW0Xfuf+XMVr6kqE2lacHYbyf62kizHBM94dpuj GmexUXEvGE8UsjCQQUXtck52pLWU3KknONAvRjKwaTPLvWaMo2iwzaJuTYd+T0oSXHjz QY8cq9Rs33qG1vZ/zzbnmJ2q4dEXzbvyHHHMDoK1AkivSgMX0yu9CFgT5kicVLG+fULm qhzP4tm+OD9SYhbQmpwMKdvl1/LjZxgY0O81wdkPrQFiv5D7WhcpWFqShcrCGQAsfpy0 kQaA== X-Forwarded-Encrypted: i=1; AJvYcCUwK9B90Qdok1xFWx/V1wbfQMck9HcEaIF7HmCjUF5Da/KkB0f1UErKK6mfQ0cGBAdwkPZNlYIJTZK9t/xuPveH+sTEzwI/MbYeC9xm X-Gm-Message-State: AOJu0YzyWT/+QVGIy4+KBCV07OfQVBzfefDF3UzjEOI2RvIYIkpBbF3n A4n9XjZVs1GOxD3jB8GgRTplZ4Np7NryekXm4sQpwlOxYGkAD4uf X-Received: by 2002:a05:6a00:98d:b0:6f4:9fc7:d239 with SMTP id d2e1a72fcca58-6f4c9334e39mr31522883b3a.14.1715805331160; Wed, 15 May 2024 13:35:31 -0700 (PDT) Received: from localhost.localdomain ([106.195.57.212]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-6f4d2a66691sm11892785b3a.16.2024.05.15.13.35.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 13:35:30 -0700 (PDT) From: Shresth Prasad To: robh@kernel.org, saravanak@google.com Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, skhan@linuxfoundation.org, javier.carrasco.cruz@gmail.com, julia.lawall@inria.fr, Shresth Prasad Subject: [PATCH][next] of: property: Remove calls to of_node_put Date: Thu, 16 May 2024 01:59:17 +0530 Message-ID: <20240515202915.16214-3-shresthprasad7@gmail.com> X-Mailer: git-send-email 2.45.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Add __free cleanup handler to some variable initialisations, which ensures that the resource is freed as soon as the variable goes out of scope. Thus removing the need to manually free up the resource using of_node_put. Suggested-by: Julia Lawall Signed-off-by: Shresth Prasad --- I had submitted a similar patch a couple weeks ago addressing the same issue, but as it turns out I wasn't thorough enough and had left a couple instances. I hope this isn't too big an issue. --- drivers/of/property.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/drivers/of/property.c b/drivers/of/property.c index 17b294e16c56..96a74f6a8d64 100644 --- a/drivers/of/property.c +++ b/drivers/of/property.c @@ -773,15 +773,14 @@ EXPORT_SYMBOL(of_graph_get_port_parent); struct device_node *of_graph_get_remote_port_parent( const struct device_node *node) { - struct device_node *np, *pp; + struct device_node *pp; /* Get remote endpoint node. */ - np = of_graph_get_remote_endpoint(node); + struct device_node *np __free(device_node) = + of_graph_get_remote_endpoint(node); pp = of_graph_get_port_parent(np); - of_node_put(np); - return pp; } EXPORT_SYMBOL(of_graph_get_remote_port_parent); @@ -835,17 +834,18 @@ EXPORT_SYMBOL(of_graph_get_endpoint_count); struct device_node *of_graph_get_remote_node(const struct device_node *node, u32 port, u32 endpoint) { - struct device_node *endpoint_node, *remote; + struct device_node *endpoint_node __free(device_node) = + of_graph_get_endpoint_by_regs(node, port, endpoint); + + struct device_node *remote __free(device_node) = + of_graph_get_remote_port_parent(endpoint_node); - endpoint_node = of_graph_get_endpoint_by_regs(node, port, endpoint); if (!endpoint_node) { pr_debug("no valid endpoint (%d, %d) for node %pOF\n", port, endpoint, node); return NULL; } - remote = of_graph_get_remote_port_parent(endpoint_node); - of_node_put(endpoint_node); if (!remote) { pr_debug("no valid remote node\n"); return NULL; @@ -853,7 +853,6 @@ struct device_node *of_graph_get_remote_node(const struct device_node *node, if (!of_device_is_available(remote)) { pr_debug("not available for remote node\n"); - of_node_put(remote); return NULL; } @@ -1064,19 +1063,15 @@ static void of_link_to_phandle(struct device_node *con_np, struct device_node *sup_np, u8 flags) { - struct device_node *tmp_np = of_node_get(sup_np); + struct device_node *tmp_np __free(device_node) = of_node_get(sup_np); /* Check that sup_np and its ancestors are available. */ while (tmp_np) { - if (of_fwnode_handle(tmp_np)->dev) { - of_node_put(tmp_np); + if (of_fwnode_handle(tmp_np)->dev) break; - } - if (!of_device_is_available(tmp_np)) { - of_node_put(tmp_np); + if (!of_device_is_available(tmp_np)) return; - } tmp_np = of_get_next_parent(tmp_np); } -- 2.45.1