linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: Markus Elfring <Markus.Elfring@web.de>
Cc: linux-trace-devel@vger.kernel.org,
	Daniel Wagner <dwagner@suse.de>,
	Julia Lawall <julia.lawall@inria.fr>
Subject: Re: [PATCH RFC] libtraceevent: Improve exception handling in parse_arg_add()
Date: Mon, 13 Mar 2023 12:16:12 -0400	[thread overview]
Message-ID: <20230313121612.3b16fcf1@gandalf.local.home> (raw)
In-Reply-To: <94b6775c-406e-4b17-2984-84f1bb54f375@web.de>

On Sun, 12 Mar 2023 10:02:24 +0100
Markus Elfring <Markus.Elfring@web.de> wrote:

> Hello,
> 
> I hope that the advice “If there is no cleanup needed then just return directly.”

                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


> can be taken better into account.
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/coding-style.rst?h=v6.3-rc1#n532
> 
> Another improvable implementation detail was detected by the means of
> the semantic patch language (Coccinelle software).
> How will the chances evolve to integrate the following change suggestion?
> 
> 
> diff --git a/src/event-parse.c b/src/event-parse.c
> index e655087..1ca5fdd 100644
> --- a/src/event-parse.c
> +++ b/src/event-parse.c
> @@ -6388,22 +6388,20 @@ static int parse_arg_add(struct tep_print_parse **parse, char *format,
>  
>      parg = calloc(1, sizeof(*parg));
>      if (!parg)
> -        goto error;
> +        return -1;
> +
>      parg->format = strdup(format);
> -    if (!parg->format)
> -        goto error;
> +    if (!parg->format) {
> +        free(parg);
           ^^^^^^^^^^

That's clean up.

-- Steve

> +        return -1;
> +    }
> +
>      parg->type = type;
>      parg->arg = arg;
>      parg->len_as_arg = len_as_arg;
>      parg->ls = ls;
>      *parse = parg;
>      return 0;
> -error:
> -    if (parg) {
> -        free(parg->format);
> -        free(parg);
> -    }
> -    return -1;
>  }
>  
>  static int parse_arg_format(struct tep_print_parse **parse,
> 
> 
> Regards,
> Markus


       reply	other threads:[~2023-03-13 16:16 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <94b6775c-406e-4b17-2984-84f1bb54f375@web.de>
2023-03-13 16:16 ` Steven Rostedt [this message]
     [not found]   ` <1e0fe72f-2dac-f825-7cd3-a5727654810a@web.de>
2023-03-13 22:33     ` [PATCH RFC] libtraceevent: Improve exception handling in parse_arg_add() Steven Rostedt

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=20230313121612.3b16fcf1@gandalf.local.home \
    --to=rostedt@goodmis.org \
    --cc=Markus.Elfring@web.de \
    --cc=dwagner@suse.de \
    --cc=julia.lawall@inria.fr \
    --cc=linux-trace-devel@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;
as well as URLs for NNTP newsgroup(s).