Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp5060171imw; Tue, 19 Jul 2022 20:09:23 -0700 (PDT) X-Google-Smtp-Source: AGRyM1v4FSP29CSZxshK7sNcvsXTKfTYOyVXxnlf674qhL7p3U+I0GNO0Mp+lKpbp9emK0lXaScL X-Received: by 2002:a17:907:2722:b0:72b:6d79:1a46 with SMTP id d2-20020a170907272200b0072b6d791a46mr33689788ejl.713.1658286563435; Tue, 19 Jul 2022 20:09:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658286563; cv=none; d=google.com; s=arc-20160816; b=mexeEzDvfYgKB8BfCZTbcnGV4QFbWsoqJNtBtv6x9xoQ7heLo0D0u2eVKPnDmG62RX mXJn+ZwMpM8C5T06YorBIqwqgFE3VtB6qm3FJO68oPRvgVD5wAehQjj3Wz/DfPSXSTwL dNWVGf9xBKuTKh4oVnsJd2gyeoBjdIPO+T2gmKPOp+C6Oe58VfbsURd5W3Yy1O1SekqX cUgX+1cV8/uIMmyyXNP7/u/8qTDfRSiJw+khL0K5vB6xeTK7HEVPV0Mqwvpzv62Lms4i gLudhZ4vmIALOYHmAYb7iAA2Ncx+/UvJSZCcsh0lPi9SDUgTCTd8R4Y33BlECgDKu/kn lu4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :mime-version:user-agent:date:message-id:subject:from:cc:to; bh=+YD4tHHgtjMNGQhahIDAFakUgFGVrA3FtQcmXLxV850=; b=kDu+KRCgYwyEkErOF/aFT5jo6h08nrDEvnzjeNlSvP9+51rJzFY71KV1PY+gS6K+LG 7P8b10hnc/5OUgZFBf14liJ05cms29+GKKRk/FxOjBd+maYp+N37dz8+TNDYbXx/1enK vnScUdz9kFbIezCUGI/oHgdOS3O8Dt/+Yo01jycbxQXfLSsB905AnVU2fxtZZ6KvZ1ah sevF5cRFrzS6Exv7yeV613boukPMulftCmEad1Ntog9X2FQ7GJogiT5JcUn14A7N1i1y p/CtIG2W/HCpGGRU0yzORhikU4Y3Vziszx/F+e4OO5EBkHAV30t++J+h/0AtwSv3pNdc BQEg== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d25-20020a056402401900b00435c2425755si906038eda.103.2022.07.19.20.08.57; Tue, 19 Jul 2022 20:09:23 -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; 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; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240025AbiGTCq6 (ORCPT + 99 others); Tue, 19 Jul 2022 22:46:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49530 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238823AbiGTCq4 (ORCPT ); Tue, 19 Jul 2022 22:46:56 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D7F96FA04 for ; Tue, 19 Jul 2022 19:46:56 -0700 (PDT) Received: from dggemv704-chm.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4Lng3t1TdzzVg4s; Wed, 20 Jul 2022 10:43:06 +0800 (CST) Received: from kwepemm600003.china.huawei.com (7.193.23.202) by dggemv704-chm.china.huawei.com (10.3.19.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Wed, 20 Jul 2022 10:46:50 +0800 Received: from [127.0.0.1] (10.174.177.249) by kwepemm600003.china.huawei.com (7.193.23.202) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Wed, 20 Jul 2022 10:46:49 +0800 To: "linux-kernel@vger.kernel.org" , , CC: linfeilong , Louhongxiang From: Zhiqiang Liu Subject: [PATCH] tracing: use free_trace_buffer in allocate_trace_buffers Message-ID: <65f0702d-07f6-08de-2a07-4c50af56a67b@huawei.com> Date: Wed, 20 Jul 2022 10:46:48 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.177.249] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemm600003.china.huawei.com (7.193.23.202) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS 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 In allocate_trace_buffers(), if allocating tr->max_buffer fails, we can directly call free_trace_buffer to free tr->array_buffer. Signed-off-by: Zhiqiang Liu --- kernel/trace/trace.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index b8dd54627075..883c8e9987f6 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -9101,6 +9101,16 @@ allocate_trace_buffer(struct trace_array *tr, struct array_buffer *buf, int size return 0; } +static void free_trace_buffer(struct array_buffer *buf) +{ + if (buf->buffer) { + ring_buffer_free(buf->buffer); + buf->buffer = NULL; + free_percpu(buf->data); + buf->data = NULL; + } +} + static int allocate_trace_buffers(struct trace_array *tr, int size) { int ret; @@ -9113,10 +9123,7 @@ static int allocate_trace_buffers(struct trace_array *tr, int size) ret = allocate_trace_buffer(tr, &tr->max_buffer, allocate_snapshot ? size : 1); if (MEM_FAIL(ret, "Failed to allocate trace buffer\n")) { - ring_buffer_free(tr->array_buffer.buffer); - tr->array_buffer.buffer = NULL; - free_percpu(tr->array_buffer.data); - tr->array_buffer.data = NULL; + free_trace_buffer(&tr->array_buffer); return -ENOMEM; } tr->allocated_snapshot = allocate_snapshot; @@ -9131,16 +9138,6 @@ static int allocate_trace_buffers(struct trace_array *tr, int size) return 0; } -static void free_trace_buffer(struct array_buffer *buf) -{ - if (buf->buffer) { - ring_buffer_free(buf->buffer); - buf->buffer = NULL; - free_percpu(buf->data); - buf->data = NULL; - } -} - static void free_trace_buffers(struct trace_array *tr) { if (!tr) -- 2.33.0