Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp640457lqp; Sat, 13 Apr 2024 12:15:47 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVSw6ILTQ0scl617TFaLFbFOg6VK/9+8wInx/LJB7/xnnDALCxx+VWeWIVxeG+1cbVBzyqFGbB3K6W6CGfx18W23pjYPhF9e3n/GUHeaw== X-Google-Smtp-Source: AGHT+IEDGGP07aamGfG8GaEUQnloBrm38qAuej/AaYf//mmEVlokxSuBDcY9eKNy/rgMKXpgY+az X-Received: by 2002:a05:6a00:1406:b0:6ec:d76b:6fac with SMTP id l6-20020a056a00140600b006ecd76b6facmr7221626pfu.12.1713035746969; Sat, 13 Apr 2024 12:15:46 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713035746; cv=pass; d=google.com; s=arc-20160816; b=f/0Q0LI4iI2FmFufAIO0squ1adt6fVN74LOHc+BQjtN+RdF7Mgsw6ugdqqgr7HbNz4 NYzMRrP/RYqNQum8iARkYsQ7bcTy5+My2kp4s1spw22ZxZcO+9tHMHxEk/WNSXhq8su1 gBOUmbxdBw6nhJj7D9m6U2APxKHlDAXASgo7xWNRy/EO1ULiJv0ZNlRUITLD9mUSEgKR kbbRurzA0JPhzoRm9lqNcttGXf9jM+YTW7pxvKoM54IwU0ZKU463jvDMYDorXZrXLIk9 EmQ/s7JouRTmXpJvGCVo9SYOylkMQYCTqfVfpIzQy9qbaB9+ppTGFtbiPlE0AS2+UAkf 11pQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :user-agent:references:message-id:in-reply-to:subject:cc:to:from :date:dkim-signature; bh=asONdpdArG+MOBmLcsAmo2WXpEy8zk0Cigt+bZtUvK0=; fh=Yqk6dNE+dyvtWAei0vs1HAB1o3hAntT1Wui8lPHmcog=; b=mFnuYPVYAGBPgGY3Rc4whm+Q9pFQ/1ImSc0to0gC6HWDYWTKZJXzkeazqF++jZci0j /0VpoX5qUq/hS0v8OjkxaYm8DCV1dEONWVWacUd1iCQqxfGiq6fKXh4wSEcNNu747Cbp nrL5Yg/o4tYpF2vS+zgl/XsufZYdQCaUehsQoH/Cn138Qw016qmiRlSYvXmft0HgHBT4 jLC0a/UX/cEAJKXg8zkMegRUKKqtkUhew1JZay2zz6uTdlgYwJappC5rzZqmERH5TudC GKUaSYxMln5DrAvbAnlxzT0FHe+CycTg0IDWZAUdItAUo5EFzjlEmK98ZDTE9C/SxXVt Il6Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@inria.fr header.s=dc header.b=WM5DiaCD; arc=pass (i=1 spf=pass spfdomain=inria.fr dkim=pass dkdomain=inria.fr dmarc=pass fromdomain=inria.fr); spf=pass (google.com: domain of linux-kernel+bounces-143851-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-143851-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=inria.fr Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id ff22-20020a056a002f5600b006ed14fed3d6si5240643pfb.79.2024.04.13.12.15.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Apr 2024 12:15:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-143851-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=@inria.fr header.s=dc header.b=WM5DiaCD; arc=pass (i=1 spf=pass spfdomain=inria.fr dkim=pass dkdomain=inria.fr dmarc=pass fromdomain=inria.fr); spf=pass (google.com: domain of linux-kernel+bounces-143851-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-143851-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=inria.fr 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 A11B8281FAF for ; Sat, 13 Apr 2024 19:15:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2A30253E3B; Sat, 13 Apr 2024 19:15:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=inria.fr header.i=@inria.fr header.b="WM5DiaCD" Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) (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 2556D2901; Sat, 13 Apr 2024 19:15:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.134.164.104 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713035739; cv=none; b=L5KdZR+6eFdX8x6m8bqPcknUY9k2/46gXCx1bcbBbavlACzbVbpfSi3Z/ej5wwS+d1E/r6wM4X2q6GqBRe7/z+UCOkZMxBrxFXMcvXfa8ljD3YcQVS3GnzHhbzwgsqWPoZH+gQcnJIFlYjdjxM/pfb/dKKPRccbe0TwPBIrylmY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713035739; c=relaxed/simple; bh=4cGjbS7oZv3MqXnUHAus2v7DZuTRY4ghBpQ6dnNDpM8=; h=Date:From:To:cc:Subject:In-Reply-To:Message-ID:References: MIME-Version:Content-Type; b=BS6+L7DEH6i0gqjzjpk6OyrHWzJpawxv82e1t7Hl/pTFa6o/CYxORDbUHg8NI5G+4oocM3UCmAplMFXMr0FLBACYRrZT6xGG1KbPX7uf+QmiHI7aBFLgj5B0PIkX/pRUOmFLwSyVpib8f68wTQIGj74fChFh2imS773k9L5rQhI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=inria.fr; spf=pass smtp.mailfrom=inria.fr; dkim=pass (1024-bit key) header.d=inria.fr header.i=@inria.fr header.b=WM5DiaCD; arc=none smtp.client-ip=192.134.164.104 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=inria.fr Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=inria.fr DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=inria.fr; s=dc; h=date:from:to:cc:subject:in-reply-to:message-id: references:mime-version; bh=asONdpdArG+MOBmLcsAmo2WXpEy8zk0Cigt+bZtUvK0=; b=WM5DiaCDP5zKrAzdddx2gwE7da09vEs/ZhFfDa9ODud/54fsUFCHc+1B U18Xu+0URGYPS7lpuYwiiSxTvz2UKreKJiPM0w2n75urw2vOSy1HTDCPG SANAZK/M4JG5+mgXU+dPtUj+zVWtg93ivk3lTr+oOpsKbQZrgTbwBXrEL s=; Authentication-Results: mail3-relais-sop.national.inria.fr; dkim=none (message not signed) header.i=none; spf=SoftFail smtp.mailfrom=julia.lawall@inria.fr; dmarc=fail (p=none dis=none) d=inria.fr X-IronPort-AV: E=Sophos;i="6.07,199,1708383600"; d="scan'208";a="84712531" Received: from 231.85.89.92.rev.sfr.net (HELO hadrien) ([92.89.85.231]) by mail3-relais-sop.national.inria.fr with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Apr 2024 21:15:26 +0200 Date: Sat, 13 Apr 2024 21:15:25 +0200 (CEST) From: Julia Lawall X-X-Sender: jll@hadrien To: Greg KH cc: Julia Lawall , Rob Herring , 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 In-Reply-To: <2024041211-statistic-reformist-bf70@gregkh> Message-ID: References: <20240411180256.61001-1-romeusmeister@gmail.com> <2024041111-tummy-boil-a6aa@gregkh> <2024041211-statistic-reformist-bf70@gregkh> User-Agent: Alpine 2.22 (DEB 394 2020-01-19) 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 On Fri, 12 Apr 2024, Greg KH wrote: > 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. Jonathan Cameron pointed me to the following series from Rob Herring: https://lore.kernel.org/linux-devicetree/20240409-dt-cleanup-free-v2-0-5b419a4af38d@kernel.org/ The patch for of_node_put is: https://lore.kernel.org/linux-devicetree/20240409-dt-cleanup-free-v2-3-5b419a4af38d@kernel.org/ It uses __free directy. The cases in the file drivers/of/property.c have quite simple structure, with for each get just one put at the end of the scope in most cases. julia > > thanks, > > greg k-h >