From patchwork Sat May 14 02:47:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 12849640 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C8F89C433F5 for ; Sat, 14 May 2022 02:55:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230131AbiENCzU (ORCPT ); Fri, 13 May 2022 22:55:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230096AbiENCzT (ORCPT ); Fri, 13 May 2022 22:55:19 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D61D834A024 for ; Fri, 13 May 2022 19:48:01 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id CD5CCB8324D for ; Sat, 14 May 2022 02:47:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6886BC385AA; Sat, 14 May 2022 02:47:58 +0000 (UTC) Received: from rostedt by gandalf.local.home with local (Exim 4.95) (envelope-from ) id 1nphoz-005XM5-AZ; Fri, 13 May 2022 22:47:57 -0400 From: Steven Rostedt To: linux-trace-devel@vger.kernel.org Cc: "Steven Rostedt (Google)" Subject: [PATCH 03/26] trace-cmd: Simplify add_guest() Date: Fri, 13 May 2022 22:47:33 -0400 Message-Id: <20220514024756.1319681-4-rostedt@goodmis.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220514024756.1319681-1-rostedt@goodmis.org> References: <20220514024756.1319681-1-rostedt@goodmis.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org From: "Steven Rostedt (Google)" Simplify the function add_guest by using a local variable to point to the array element instead of dereferencing the array every time. Link: https://lore.kernel.org/linux-trace-devel/20220428150635.789051-3-rostedt@goodmis.org Signed-off-by: Steven Rostedt (Google) --- tracecmd/trace-vm.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/tracecmd/trace-vm.c b/tracecmd/trace-vm.c index 47f8d96a4015..7a91038d75dc 100644 --- a/tracecmd/trace-vm.c +++ b/tracecmd/trace-vm.c @@ -56,18 +56,22 @@ bool trace_have_guests_pid(void) static struct trace_guest *add_guest(unsigned int cid, const char *name) { + struct trace_guest *guest; + guests = realloc(guests, (guests_len + 1) * sizeof(*guests)); if (!guests) die("allocating new guest"); - memset(&guests[guests_len], 0, sizeof(struct trace_guest)); - guests[guests_len].name = strdup(name); - if (!guests[guests_len].name) + + guest = &guests[guests_len++]; + + memset(guest, 0, sizeof(*guest)); + guest->name = strdup(name); + if (!guest->name) die("allocating guest name"); - guests[guests_len].cid = cid; - guests[guests_len].pid = -1; - guests_len++; + guest->cid = cid; + guest->pid = -1; - return &guests[guests_len - 1]; + return guest; } static struct tracefs_instance *start_trace_connect(void)