Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp1892049lqo; Mon, 13 May 2024 01:13:34 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUJLn0rzqj86HRyXc08CK25GRuAq+bvP3t9uP2mTKEHcGr44kFlwZM0jthnlNI2kjVO/V0klHBX3pwSjGxMUGVCHlr9vg0WJAv4mrMU2A== X-Google-Smtp-Source: AGHT+IFz3GjgH4+oSvgsuH03hVB2jwqHHlVoAh2EYv+llT2BlLT/5BJfqfddPZzafHvVyn8p3zBR X-Received: by 2002:a05:6808:246:b0:3c9:8c97:9850 with SMTP id 5614622812f47-3c997061228mr10541744b6e.24.1715588013944; Mon, 13 May 2024 01:13:33 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715588013; cv=pass; d=google.com; s=arc-20160816; b=UKDkl3fqmJEDwzZXsKtpgEPHID/J/isew0hFCPWGohWPvFMtgT3eJ8980grNibjhha qlORLWRKqkQYyh/GwfAej4TpkaKfMnhHiZezezhaDAHvhrXzCRYjcsihuJMxEZ+x3S0v 2yxRpUuw6cDnY4K+5uq7RRDBwSFbYnAx+MhXW68bxSAh6qFRoeOAwBRMDj+T4e4gz/aP t8GN35pdr6Xp4ji2fQ3TgKvcEakQonJSjqNVARftVmCZX1m542NmyAASTQAjed624EuP haDGq1ihaSQwhR0V97d3GjCGZuZt/hSVGNz5XCtoiDUFobrZ2EMxGUrxnAkcjwNET6qQ ArJA== 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:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=HgKHgocriTlqxjVjw6xoeGLIqR6uQf/U72vB9VWFXgg=; fh=5oNZyJGKbJzd7eJBLfd/mTMMpIE+ozu8Atc8UsowOps=; b=0mTigFEjzwLi4yLpIJwPfxQ/gYuabZxNc1LwfYbQslducap+cLr6b8pqiwf9U8v3vE tJ0R335aHOL1r6T74mMKvZfxA7TCzNXeAk8nff53dYakdpR0t6owWKp8uB5RqpzEzm3w ygEF9wyYYfI6+hLmw+Csvj3Efx9EU+BIEwDLqy0Zqq0saF+EDfQusrmsazGuFOy74wtf L3VvfcYrBzS9VN+dcIMLb2TyNuf5P8w4MUH/HGDaGXrKSeAJ146FGMAdr+zKeT9+KjvY zfX0r453e3gYEtgPxzNAP/kAa3WpmJaGb6S6QQ2Tb5uK/UwrKPlQVaA46qQY3SQounlp qe1w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=aPq8leOO; 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-177326-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-177326-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 41be03b00d2f7-634103f54c1si8741095a12.409.2024.05.13.01.13.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 May 2024 01:13:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-177326-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=aPq8leOO; 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-177326-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-177326-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 708E62821C6 for ; Mon, 13 May 2024 08:13:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3F31D1474CB; Mon, 13 May 2024 08:13:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="aPq8leOO" Received: from mail-lj1-f177.google.com (mail-lj1-f177.google.com [209.85.208.177]) (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 C14CE146D62 for ; Mon, 13 May 2024 08:13:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715587994; cv=none; b=SPu5gD43AQOq4ijVZEGJHv89VlHIl43pe1ww1bwMbW/pOLgF1VfNvglFDtXYv5/Vsvc4Wd5/YS+uz7W57hAFNOuy+52zgKTYqa2mmiCnr9FWEFJZXOTgVHBBjHc5d5UOv20Vku/bcKfr3RtqF/NPk/Cx2jl+6toJAD5rrEkaOYE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715587994; c=relaxed/simple; bh=FUdlLBoU9E5VgyeKJsX9kcOBcDZzkpEsqNBxhlyWkZs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=KCXQT5Ndp1jxDSXDwz+mUt6dKSrhHrfqlH8RCm/Rn1NPzNik2Zh/M5KmFsI1zgkFFLP7u3MvRlJQSPsR1t6sh+0TwaXNbuia5Ela3YC+edi0iIbhkq8acXYJ5f+XmtqbmMKJRJQi8Y6FtGG9gF1bL8IOz7YQlM8sLPs/ojbKOaE= 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=aPq8leOO; arc=none smtp.client-ip=209.85.208.177 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-lj1-f177.google.com with SMTP id 38308e7fff4ca-2e538a264e0so39030631fa.1 for ; Mon, 13 May 2024 01:13:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715587991; x=1716192791; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=HgKHgocriTlqxjVjw6xoeGLIqR6uQf/U72vB9VWFXgg=; b=aPq8leOOlu3xs57yHTomEb0cZUIl8x+7LS77bJoLGTouXQO7dAM+AvY1E3I0uYQNlx RKDMNGIBnZpnSC9JFnwTsbvJGPycPR3B3Q4FltzC1awKdaLBzggUkWMtnpG3/j7NsBXE vCZ6Ar1aon1n/gChOZn8xgqxxHtcxKuMBYAPFlicTpnKI5086wwTDStRBS1LnIgVCDYD QkgB50xO10m1KwpKTNjQqFLmI9g+Au/Csw810FC6n5fVtHBbMOTiNKe0jJx0SDhMMJcm BxgLXH5oipeJL2F0fuTC+47sk1jDN3WC9225caA9ykRtyPbHnMVFZ928O+RjQzOIitzp 6PnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715587991; x=1716192791; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HgKHgocriTlqxjVjw6xoeGLIqR6uQf/U72vB9VWFXgg=; b=a+tTllgFc+eJETiQYMoliX/UqnUZMyYvOUuuFaVSFJfxVM/NBKwZXYe9AaKUeHOD+H qhpWnZbfJYl7o9DULKXU7o7NG0l0KYrGds2ZE1YF+8E+wex+QVbMRjcQO07rClNh2rlY bogZpRHHYBi9BIWSQ56n/BphheV+VmXgyBl/tYrYMDZKIdCjZkTSRSziRHAaNif2tDwS ufaU0j1bp9MTr0cUZoGMJAfUhpiozH/b4yeezzvQornNQraibqndEVvbuRvi2OrjY4D1 qoHZc4xK+Z6IY9IxVYjdcLje2UQ2pH3PUciaHcT3s2rErI83Neaf+4unZ1sKffEsNEOu u1dw== X-Forwarded-Encrypted: i=1; AJvYcCVdSEjUbNGU3diLJzWNH4lZ0pvnb+2QIu30hK7UejFfy/Wfq7iBnKvdlz0lbf9g/y6ewnExMGawJU+o5qXkHgmMi7aleMHF8EEOd3m5 X-Gm-Message-State: AOJu0Yxplsc+k+cAQhcY1C8TLDodPqSk4/zdlgZzHcOhSenAp30mjhwl ktjp/2JprQEfMYYluMPhb/eotbEqnWVUSrrXs1pmCXQAI3xrDksq X-Received: by 2002:a2e:8096:0:b0:2dd:d3a0:e096 with SMTP id 38308e7fff4ca-2e52005f693mr76119471fa.31.1715587990618; Mon, 13 May 2024 01:13:10 -0700 (PDT) Received: from localhost.localdomain ([2001:b07:ac9:e686:c88b:6249:b2f4:9ae2]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3502b8a77f8sm10399563f8f.54.2024.05.13.01.13.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 May 2024 01:13:10 -0700 (PDT) From: Vincenzo Mezzela To: sudeep.holla@arm.com Cc: vincenzo.mezzela@gmail.com, gregkh@linuxfoundation.org, javier.carrasco.cruz@gmail.com, julia.lawall@inria.fr, linux-kernel@vger.kernel.org, rafael@kernel.org, skhan@linuxfoundation.org Subject: [PATCH 0/2 v4] drivers: arch_topology: introduce automatic cleanup feature Date: Mon, 13 May 2024 10:13:02 +0200 Message-Id: <20240513081304.499915-1-vincenzo.mezzela@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240501094313.407820-1-vincenzo.mezzela@gmail.com> References: <20240501094313.407820-1-vincenzo.mezzela@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit This patch series introduces the automatic cleanup feature using the __free attribute. With this modification, resources allocated with __free are automatically released at the end of the scope. In some cases, modifying the structure of loops is necessary to utilize the __free attribute effectively. For example: ``` struct device_node *t; do { t = of_get_child_by_name(..); if (t) { // some code here of_node_put(t); } i++; } while (t); // ^ // | // device_node here ``` To use the __free attribute here, we need to move the declaration of the device_node within the loop, otherwise the automatic cleanup is called only at the end of the function, and not at end of each iteration of the loop, being it scope-based. However, moving the declaration of the device_node within the loop, we can no longer check the exit condition in the loop statement, being it outside the loop's scope. Therefore, this work is split into two patches. The first patch moves the exit condition of the loop directly within the loop's scope with an explicit break statement: ``` struct device_node *t; do { t = of_get_child_by_name(..); if (!t) break; // some code here of_node_put(t); i++; } while (1); ``` The second patch eliminates all of_node_put() calls, introducing the __free attribute to the device_node. changes in v2: - check loop exit condition within the loop - add cleanup.h header changes in v3: - split patch in two - fix misalignment - fix checkpatch warnings - replace break with return statement where possible changes in v4: - fix commit subject - fix coding style Vincenzo Mezzela (2): drivers: arch_topology: Refactor do-while loops drivers: arch_topology: use __free attribute instead of of_node_put() drivers/base/arch_topology.c | 145 +++++++++++++++++------------------ 1 file changed, 72 insertions(+), 73 deletions(-) -- 2.34.1