public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jiri Slaby <jirislaby@kernel.org>
To: Shresth Prasad <shresthprasad7@gmail.com>,
	davem@davemloft.net, gregkh@linuxfoundation.org
Cc: sparclinux@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-serial@vger.kernel.org, javier.carrasco.cruz@gmail.com,
	skhan@linuxfoundation.org, Julia Lawall <julia.lawall@inria.fr>
Subject: Re: [PATCH v2][next] tty: sunsu: Simplify device_node cleanup by using __free
Date: Thu, 2 May 2024 09:56:00 +0200	[thread overview]
Message-ID: <01cbcdf5-8a7a-4b47-a2aa-05c041e3cab2@kernel.org> (raw)
In-Reply-To: <20240501084110.4165-2-shresthprasad7@gmail.com>

On 01. 05. 24, 10:41, Shresth Prasad wrote:
> Add `__free` function attribute to `ap` and `match` pointer
> initialisations which ensure that the pointers are freed as soon as they
> go out of scope, thus removing the need to manually free them using
> `of_node_put`.
> 
> This also removes the need for the `goto` statement and the `rc`
> variable.
> 
> Tested using a qemu x86_64 virtual machine.
> 
> Suggested-by: Julia Lawall <julia.lawall@inria.fr>
> Signed-off-by: Shresth Prasad <shresthprasad7@gmail.com>
> ---
> Changes in v2:
>      - Specify how the patch was tested
> 
>   drivers/tty/serial/sunsu.c | 37 +++++++++++--------------------------
>   1 file changed, 11 insertions(+), 26 deletions(-)

Nice cleanup.

> --- a/drivers/tty/serial/sunsu.c
> +++ b/drivers/tty/serial/sunsu.c
> @@ -1382,44 +1382,29 @@ static inline struct console *SUNSU_CONSOLE(void)
>   
>   static enum su_type su_get_type(struct device_node *dp)
>   {
> -	struct device_node *ap = of_find_node_by_path("/aliases");
> -	enum su_type rc = SU_PORT_PORT;
> +	struct device_node *ap __free(device_node) =
> +			    of_find_node_by_path("/aliases");

If we used c++, that would be even nicer; like:
Destroyer ap(of_find_node_by_path("/aliases"));

But we don't :P. OTOH. can't we achieve that with macro-fu and typeof() 
magic? Perhaps not really exactly the above, but something like
   Destroyer(ap, of_find_node_by_path("/aliases"));
maybe?

Reviewed-by: Jiri Slaby <jirislaby@kernel.org>

thanks,
-- 
js
suse labs


  reply	other threads:[~2024-05-02  7:56 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-01  8:41 [PATCH v2][next] tty: sunsu: Simplify device_node cleanup by using __free Shresth Prasad
2024-05-02  7:56 ` Jiri Slaby [this message]
2024-05-02  8:55   ` Shresth Prasad
2024-05-02 16:05 ` Ilpo Järvinen
2024-05-02 16:51   ` Shresth Prasad
2024-05-03  5:34     ` Greg KH
2024-05-03  9:01       ` Shresth Prasad
2024-05-04 16:02         ` Greg KH
2024-05-14 19:37           ` Shresth Prasad

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=01cbcdf5-8a7a-4b47-a2aa-05c041e3cab2@kernel.org \
    --to=jirislaby@kernel.org \
    --cc=davem@davemloft.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=javier.carrasco.cruz@gmail.com \
    --cc=julia.lawall@inria.fr \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=shresthprasad7@gmail.com \
    --cc=skhan@linuxfoundation.org \
    --cc=sparclinux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox