Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp4291093rwb; Sun, 7 Aug 2022 20:31:41 -0700 (PDT) X-Google-Smtp-Source: AA6agR4vcp7gc/pmm2SYcyRYmWJcFZ687r14TeHTbX/BsgsZztfBU2HJdz9fOvk2t6I8DkKcNJTx X-Received: by 2002:a05:6402:4024:b0:43d:2067:f068 with SMTP id d36-20020a056402402400b0043d2067f068mr16549570eda.258.1659929501015; Sun, 07 Aug 2022 20:31:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659929501; cv=none; d=google.com; s=arc-20160816; b=c7ifztCwOYm9OMvitX/BnRPLf0o/jCNqcUEuXH+JsiEpM30xUabQWBQYWZ9UeyNzx3 GkffSstXuxMFU8Nv8BGSMFXfwOEbiIgVNN2eXmL4BS4UKd/u3hOEw4szuZItC0MkwEJB f0ukMQezxZeZgkstMt+TCXNM8BLsQ7h0ch14HFAG+wQ6BcjRfIbDRARlBTweFF5LzS7p xMikcpViH+E38FOm2mCnfsiybGvBUPlPFuHj5tpHjLOH2qzE0wWLmQAt45JkMBxcoWnz xptO05ezX3H8R80ezn1B+CpQKL+y4zua7DSlpRyeVhVGtdA8uM93aYbr7cH/SpLJ7DWE EWdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=O10e4f89X47Ind7IOvarTPJ2k5gxmqsKR8G7YqYX1Cg=; b=UHoL65Ej9CEfFfoYHcou8wiqBAxOvOlfmUVSGrfnOA2I8762Zni9eVmxmW2c+CyBOL S0zBUHvqLqkO2oFm8TE+QwWI14KSVJmbxxsaDkghUxY0Ww5iRysxWiHhPb4XjfmxDvuq kIyDJtozqrcYZgjkpPrV4eg4okA/ih5pIVQdbSRfsJom2FMKV0ugUEq52sp1NAeExuV/ /7hvVMO9jIjLxigQsP7qiMJSqRafgZ6vdrBBYVF90kVeIt+Bd8Ap5fw4STzeAClPcdU4 rXLfpU26WSJDbRXLZuz2HyDNqsJ/x6S+n/nVNL/iRUga9SHPjj6lvsMvW6pmOOKkPyjK +F8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=N7edtCxv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z20-20020aa7c654000000b0043be95ef714si5059505edr.437.2022.08.07.20.31.15; Sun, 07 Aug 2022 20:31:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=N7edtCxv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244111AbiHHCn7 (ORCPT + 99 others); Sun, 7 Aug 2022 22:43:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242185AbiHHClk (ORCPT ); Sun, 7 Aug 2022 22:41:40 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1BD8225E3 for ; Sun, 7 Aug 2022 19:41:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=O10e4f89X47Ind7IOvarTPJ2k5gxmqsKR8G7YqYX1Cg=; b=N7edtCxvgsKuafmwDdeWT0yPZ2 FB3MJMFhR12jcCZEHcTZcus9815lmWGogVyh8sutkUHiE0kE4vbmkm5R7nG8Xuu+aXml0uVTPcFtx 6mZXoP0+8H17Szl7f8trEwkAfnR4viPXlkZG9LqRSJIZPahVAkzKHT4AKMKBh64nc/3+QRWXIc9vU /yC2B3mbwSyyiYsZDKNQu/BiAggV1x0aHDnMEsNLObEf+ayUJGRNKMcYcw1yI4m5aTWb5td/NZYID uM3vCfk3ZZxbqa8+bULyt6g8e50Sc1lb1o7U1TdogvlEXSL6CizBYaKVCgIiq2DFoGGiieusYqp0X LmjsFJ9A==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1oKshy-00DVSl-Sz; Mon, 08 Aug 2022 02:41:34 +0000 From: "Matthew Wilcox (Oracle)" To: linux-kernel@vger.kernel.org, pmladek@suse.com, Kent Overstreet Cc: Steven Rostedt , Ingo Molnar Subject: [PATCH v5 28/32] tracing: trace_events_synth: Convert to printbuf Date: Mon, 8 Aug 2022 03:41:24 +0100 Message-Id: <20220808024128.3219082-29-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220808024128.3219082-1-willy@infradead.org> References: <20220808024128.3219082-1-willy@infradead.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kent Overstreet This converts from seq_buf to printbuf. This code was using seq_buf for building up dynamically allocated strings; the conversion uses printbuf's heap allocation functionality to simplify things (no longer need to calculate size of the output string). Also, alphabetize the #includes. Signed-off-by: Kent Overstreet Cc: Steven Rostedt Cc: Ingo Molnar --- kernel/trace/trace_events_synth.c | 51 ++++++++++--------------------- 1 file changed, 16 insertions(+), 35 deletions(-) diff --git a/kernel/trace/trace_events_synth.c b/kernel/trace/trace_events_synth.c index 5e8c07aef071..720c75429c8f 100644 --- a/kernel/trace/trace_events_synth.c +++ b/kernel/trace/trace_events_synth.c @@ -5,13 +5,14 @@ * Copyright (C) 2015, 2020 Tom Zanussi */ -#include #include -#include +#include #include +#include +#include +#include #include #include -#include #include /* for gfp flag names */ @@ -611,7 +612,7 @@ static struct synth_field *parse_synth_field(int argc, char **argv, const char *prefix = NULL, *field_type = argv[0], *field_name, *array; struct synth_field *field; int len, ret = -ENOMEM; - struct seq_buf s; + struct printbuf buf; ssize_t size; if (!strcmp(field_type, "unsigned")) { @@ -654,28 +655,16 @@ static struct synth_field *parse_synth_field(int argc, char **argv, goto free; } - len = strlen(field_type) + 1; - - if (array) - len += strlen(array); - - if (prefix) - len += strlen(prefix); - - field->type = kzalloc(len, GFP_KERNEL); - if (!field->type) - goto free; - - seq_buf_init(&s, field->type, len); + buf = PRINTBUF; if (prefix) - seq_buf_puts(&s, prefix); - seq_buf_puts(&s, field_type); + prt_str(&buf, prefix); + prt_str(&buf, field_type); if (array) - seq_buf_puts(&s, array); - if (WARN_ON_ONCE(!seq_buf_buffer_left(&s))) + prt_str(&buf, array); + if (buf.allocation_failure) goto free; - s.buffer[s.len] = '\0'; + field->type = buf.buf; size = synth_field_size(field->type); if (size < 0) { @@ -687,23 +676,15 @@ static struct synth_field *parse_synth_field(int argc, char **argv, goto free; } else if (size == 0) { if (synth_field_is_string(field->type)) { - char *type; - - len = sizeof("__data_loc ") + strlen(field->type) + 1; - type = kzalloc(len, GFP_KERNEL); - if (!type) - goto free; - - seq_buf_init(&s, type, len); - seq_buf_puts(&s, "__data_loc "); - seq_buf_puts(&s, field->type); + buf = PRINTBUF; + prt_str(&buf, "__data_loc "); + prt_str(&buf, field->type); - if (WARN_ON_ONCE(!seq_buf_buffer_left(&s))) + if (buf.allocation_failure) goto free; - s.buffer[s.len] = '\0'; kfree(field->type); - field->type = type; + field->type = buf.buf; field->is_dynamic = true; size = sizeof(u64); -- 2.35.1