Received: by 2002:ab2:7407:0:b0:1f4:b336:87c4 with SMTP id e7csp233670lqn; Thu, 11 Apr 2024 22:24:29 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVQChYd+2j9KSJ5+CFDuGCZGain9UAqZAuc5vPTjp5Ys331x1lGHd69sjPlsXl+7XTrmd6AY2p3hwUJT1c+B8sO/7SDA79r3qZy1BH6iA== X-Google-Smtp-Source: AGHT+IEDbAhHyBbxxQrqVpUNh+onBVhCKHRWgRS/9UFjF1Gj0re3YkzjkPd6mZmnNu6QLr1giGVr X-Received: by 2002:a17:903:120c:b0:1e4:2bf1:a047 with SMTP id l12-20020a170903120c00b001e42bf1a047mr1567400plh.37.1712899468752; Thu, 11 Apr 2024 22:24:28 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712899468; cv=pass; d=google.com; s=arc-20160816; b=DVGmEQNiM1TNiFV3oZAddUB8Qz3/IPoe/LdXEApzz2DMf0KNWdDMK7qhaecOuXzYYq KDOVMnZX9elWbfaRZ8RAh+0qSe/DgNCSOS93FQ+JJt9z81KrjjYbsLOcaeqVHdVZLEct kon9hxcu8gX7TqrARh+tRzbnscZ3+Z+HjIjc6QyKe9CuTY4ijSYfVcpMOT5XotgYPsqx oO4WTWWoQYJzT9Hb6PmWLF9inpFo2vUIa3yOEeH3tuy++eXHt0ohb1USTB9UFF8myLK6 dJQ8qQE1MiN6FiEGpCesC28YEQMz2tJl6Ua3ICRgmm+P9PX77lQ7B1nl2w44yBKsqBuM 4tjw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=imh0MYy5a+sXQSMGzaE1qNEZgdoWiDUba986UAGmnD4=; fh=Sh0c12CKvaspnHfRYshWOR25gnaCvHGE8cR8IBa0EIE=; b=fBsjvalMvLesHzVQvdYTSlRLUadN3FluN4KxvriVGCJijlV1w8fmFRl5lPzAE+m1hQ Rjwv5mmwkHXLZFL9gmbbkgaiKMr1+pLRFg3Ug86y2LhpKsFfZYODLZbk9OxvalXnoRqn d9JXwY9U1EAF82mQ1Qooqme2GG/vyQq1ELLOZQ+G/xWC7rYbRRdiX/9IaNIrnps89oy9 Ud+LLugqNwEMJhZ3WgDrEeWTpBE6wK6Xhhc27IqLuui/1Vjb9LRBHENzow3gL7wUd1Eu WZbRJzYjGkMDCQkmsoFdnji7Ad9R84ZeuXgdYQZ/yWjc8mfIAw9/sJhQ5G1rhE1tZXGc 32LQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=RAznAcCa; arc=pass (i=1 dkim=pass dkdomain=linuxfoundation.org); spf=pass (google.com: domain of linux-kernel+bounces-141977-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-141977-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id cp12-20020a170902e78c00b001e5893023c1si1164527plb.150.2024.04.11.22.24.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Apr 2024 22:24:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-141977-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=RAznAcCa; arc=pass (i=1 dkim=pass dkdomain=linuxfoundation.org); spf=pass (google.com: domain of linux-kernel+bounces-141977-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-141977-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id A8581B22FCF for ; Fri, 12 Apr 2024 05:23:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D84EA1BDCF; Fri, 12 Apr 2024 05:23:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="RAznAcCa" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0A7311BC20; Fri, 12 Apr 2024 05:23:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712899383; cv=none; b=KNZWAPWevF9tv64XuAvrnWXnk6LyS3ib1hNTmyIFoAmRHViOjHBtGUpvb0HxTb7z59ETXXc82CcEjsWoZ7EX2s2e1UDGnqr5/FpT6IT0om35xm8wU3b8bWeNWyLqJpdZHovGrIFx6E50yYLsd4RVFyogD42/4bBDoWZrbOwaKrA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712899383; c=relaxed/simple; bh=Be1HIkMk4Xq+RofQvGmPKjjQ46/GPbpbgN3h/Gu/xYE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=rqvLnmasUaE4nFZlG4Ax5vNQm9Yf5RusvAUoFsyB3+chBoSW36BXVDq9Pfn+1HfHxW/aJ0d5+mU0PflnJCMitXPlaPVnL/7+ZQx880aSNrjwhx7cuXfy9Qbj50BwmurH5mtpac08GuAFfA0ESg5e5zI9C4w1/9jwiQLiepVTPm8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=RAznAcCa; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 33FE1C2BBFC; Fri, 12 Apr 2024 05:23:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1712899382; bh=Be1HIkMk4Xq+RofQvGmPKjjQ46/GPbpbgN3h/Gu/xYE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=RAznAcCa4v1zg+MWzZPzsKyWCIAMFob1sqkC/qAYvAT4bbAdeaK7Z5adZuvxx2zQe mVuwk+5aFsqnHO0utprwDvV0HPWWhTcOUXLl/m5ZMuX4ScVgz8HVnhig60mB8I2D4o Jw+D4uIXpWgHsz0r78lzv8B/xsqae2s9Ab8nlt0A= Date: Fri, 12 Apr 2024 07:22:59 +0200 From: Greg KH To: Julia Lawall Cc: Roman Storozhenko , jirislaby@kernel.org, skhan@linuxfoundation.org, javier.carrasco.cruz@gmail.com, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org Subject: Re: [PATCH] sysrq: Auto release device node using __free attribute Message-ID: <2024041211-statistic-reformist-bf70@gregkh> References: <20240411180256.61001-1-romeusmeister@gmail.com> <2024041111-tummy-boil-a6aa@gregkh> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Thu, Apr 11, 2024 at 08:17:07PM +0200, Julia Lawall wrote: > > > On Thu, 11 Apr 2024, Greg KH wrote: > > > On Thu, Apr 11, 2024 at 08:02:56PM +0200, Roman Storozhenko wrote: > > > Add a cleanup function attribute '__free(device_node)' to the device node > > > pointer initialization statement and remove the pairing cleanup function > > > call of 'of_node_put' at the end of the function. > > > The '_free()' attrubute is introduced by scope-based resource management > > > in-kernel framework implemented in 'cleanup.h'. A pointer marked with > > > '__free()' attribute makes a compiler insert a cleanup function call > > > to the places where the pointer goes out of the scope. This feature > > > allows to get rid of manual cleanup function calls. > > > > > > Suggested-by: Julia.Lawall > > > Signed-off-by: Roman Storozhenko > > > --- > > > This patch targets the next tree: > > > tree: git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git > > > tag: next-20240411 > > > --- > > > drivers/tty/sysrq.c | 7 +++---- > > > 1 file changed, 3 insertions(+), 4 deletions(-) > > > > > > diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c > > > index 02217e3c916b..1d1261f618c0 100644 > > > --- a/drivers/tty/sysrq.c > > > +++ b/drivers/tty/sysrq.c > > > @@ -758,11 +758,12 @@ static void sysrq_detect_reset_sequence(struct sysrq_state *state, > > > static void sysrq_of_get_keyreset_config(void) > > > { > > > u32 key; > > > - struct device_node *np; > > > struct property *prop; > > > const __be32 *p; > > > > > > - np = of_find_node_by_path("/chosen/linux,sysrq-reset-seq"); > > > + struct device_node *np __free(device_node) = > > > + of_find_node_by_path("/chosen/linux,sysrq-reset-seq"); > > > + > > > if (!np) { > > > pr_debug("No sysrq node found"); > > > return; > > > @@ -781,8 +782,6 @@ static void sysrq_of_get_keyreset_config(void) > > > > > > /* Get reset timeout if any. */ > > > of_property_read_u32(np, "timeout-ms", &sysrq_reset_downtime_ms); > > > - > > > - of_node_put(np); > > > } > > > #else > > > static void sysrq_of_get_keyreset_config(void) > > > > Also, this change really makes no sense at all, the pointer never goes > > out of scope except when the function is over, at the bottom. So why > > make this complex change at all for no benefit? > > > > In other words, properly understand the change you are making and only > > make it if it actually makes sense. It does not make any sense here, > > right? > > Maybe it would be nice to get rid of of_node_puts in the general case? That's a call for the of maintainer to make, and then if so, to do it across the whole tree, right? > Even though this one is not very annoying, there are some other functions > where there are many of_node_puts, and convoluted error handling code to > incorporate them on both the success and failure path. So maybe it would > be better to avoid the situation of having them sometimes and not having > them other times? But this is an opinion, and if the general consensus is > to only get rid of the cases that currently add complexity, then that is > possible too. Let's keep things simple until it has to be complex please. thanks, greg k-h