Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp4245750ybp; Mon, 14 Oct 2019 01:17:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqw6BGSG2l34Nknkkd5RJJTl2Y1qzxPPCekDLWXGSSjs0MA/dcQhX6nN6OpP9xbHvDqB8HsL X-Received: by 2002:a17:906:f0d2:: with SMTP id dk18mr26790134ejb.281.1571041078190; Mon, 14 Oct 2019 01:17:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571041078; cv=none; d=google.com; s=arc-20160816; b=l0TNDxmXHmBb6/LEOG33ZTUafnSYd55HKOeE56rtTf/WoALQrxpzD5Ru/nl88RIEvE oExdLIkqbpsrDxY0cGQyD9MQtro3CDywN3ecCHAB/Rtb37S/dug+RZTQ1pTyBcUWzUwU bVxJgVrHlXtnPz0C0nh3wxqwv6YSkN45kouYaGvsxzKruHIbrJ2sKZf3pdse60SL3bpH jl4iMNr1poBDOwGFLffPrwfesgjCnBZ+EA+Fq11CbcZBHFK/wlKwfJ+CtPuXUgiprFcH 2zDyI7tcqfdUlnV2hxJGJ3zzJAkHrh6RImyVZ99tSYI5WE99ojWlWQQ2hiIZDfq9JfNE KzKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:references:cc:to:from:subject; bh=1ZXZlpFeBff0W67ux6fUF+lDXWlsDZSDqZMaqBK+hy4=; b=DfUDRKRBUkjQSVz63FNp47RCWPApgHJcgOobcjiLMsSrzlfuIq9sLmGvEroIOCVlfT KOgT8q/HRtH66Nje6YJkTfmhP0Rl2hlCKW/WO14S6WK+WEAhwQ0KkgrM1qpi2PZ99zmb TvHN56BRFaX6foZRPF6gOxMN72kgrFq9G5uN150v0yVHzh81zEJqd40aEg7mmcjDo2bx Yp4YQdab4NfAPp2GXqKcGjQsmyLJr614n+Y0gKgH7EHDYBCCYQ0apDTGEvB6LVP8GRhP Buu0gs3y+EgLpuZv8hq56HsPbm9z1g3gSuIwtdVd9v9Dwys55pk+QzgMZ31jGaEPEn8j 2Wxw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id dt14si10968284ejb.168.2019.10.14.01.17.34; Mon, 14 Oct 2019 01:17:58 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730329AbfJNIQV (ORCPT + 99 others); Mon, 14 Oct 2019 04:16:21 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:59132 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729234AbfJNIQV (ORCPT ); Mon, 14 Oct 2019 04:16:21 -0400 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 3C4AB68D5D31D077D5B7; Mon, 14 Oct 2019 16:16:19 +0800 (CST) Received: from [127.0.0.1] (10.177.251.225) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.439.0; Mon, 14 Oct 2019 16:16:10 +0800 Subject: [PATCH 2/2] perf/ring_buffer: Matching the memory allocate and free, in rb_alloc() From: Yunfeng Ye To: , , , , , , CC: References: <4d308608-54e2-05fa-5a1a-9cb7b4986bd1@huawei.com> <68211803-de9a-cae1-2627-6a5e5ae0853b@huawei.com> Message-ID: <575c7e8c-90c7-4e3a-b41d-f894d8cdbd7f@huawei.com> Date: Mon, 14 Oct 2019 16:15:57 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: <68211803-de9a-cae1-2627-6a5e5ae0853b@huawei.com> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.177.251.225] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently perf_mmap_alloc_page() is used to allocate memory in rb_alloc(), but using free_page() to free memory in the failure path. It's better to use perf_mmap_free_page() instead. Signed-off-by: Yunfeng Ye --- kernel/events/ring_buffer.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/kernel/events/ring_buffer.c b/kernel/events/ring_buffer.c index abc145c..246c83a 100644 --- a/kernel/events/ring_buffer.c +++ b/kernel/events/ring_buffer.c @@ -754,6 +754,14 @@ static void *perf_mmap_alloc_page(int cpu) return page_address(page); } +static void perf_mmap_free_page(void *addr) +{ + struct page *page = virt_to_page(addr); + + page->mapping = NULL; + __free_page(page); +} + struct ring_buffer *rb_alloc(int nr_pages, long watermark, int cpu, int flags) { struct ring_buffer *rb; @@ -788,9 +796,9 @@ struct ring_buffer *rb_alloc(int nr_pages, long watermark, int cpu, int flags) fail_data_pages: for (i--; i >= 0; i--) - free_page((unsigned long)rb->data_pages[i]); + perf_mmap_free_page(rb->data_pages[i]); - free_page((unsigned long)rb->user_page); + perf_mmap_free_page(rb->user_page); fail_user_page: kfree(rb); @@ -799,14 +807,6 @@ struct ring_buffer *rb_alloc(int nr_pages, long watermark, int cpu, int flags) return NULL; } -static void perf_mmap_free_page(void *addr) -{ - struct page *page = virt_to_page(addr); - - page->mapping = NULL; - __free_page(page); -} - void rb_free(struct ring_buffer *rb) { int i; -- 2.7.4