Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp3134423ybn; Fri, 27 Sep 2019 01:27:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqyDmf9yBFFGAgk9+ChSwV8d6h60ERVswBzx2cp2f3aHYSTYbuExuo8r9IEIHsfGQ9zMR+Rw X-Received: by 2002:a05:6402:a50:: with SMTP id bt16mr3106744edb.114.1569572857228; Fri, 27 Sep 2019 01:27:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569572857; cv=none; d=google.com; s=arc-20160816; b=FSCY1NjWeZI5VIVDeS4DMU5J6P8wh4wLRG54DYBTidh8u2vE+NmsfnXaKOh2LaW7cD LHELarRsdrLYx7zbnD43l04MGsQWiwB/v5OK/BR9BYaKi6AcHhDFy2PGGwilBN1L/YFw luj3/aZCtbcbTZyn5bYLcQD1IA58IHviB0k2Z+1+uQi0cr+t/reykyulS47ael0pis9y 3eKOZJy4pY9ufVJkfsfu4sqvhoLlCKI08OExrYX4Lu6MWGTw8cYWUavYCMo/FGnoFsXB wED6IVu81NiWM6GAP8SQMRGZKKtawKn2NHhZBMM3wo6x27OektobfInfymSMCZJ/tmyh y3kA== 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=vkwbocOo0h0B5mffPmx5xdALg0vyv/h/ESz5vd499WaH5oLfSv2W4GWFtWlj+meCq5 QSoFfGdN2k+Xs87Q7NbIt4qZpdQ4vrwVq8ftWBmHDqHhcFsZeMslRC1TldW6qjiexzU6 TaxL2sDpphpCMZF9CzyUNqla2qF7uMtdkWEsG4sU1jCsljQARz8TDyGF0zCISQ09G87A uA8gmOy/3RWhjl4GXUV2lmmYx2/NVSv6NEYeI1dSxgTOU7moyUey4SpvE6OhsLiZ8KlW uN4EViKflDb267VoGQcISCCEZMJqytGF/+0tG+32pTNDMhfdotyb04ABnxM90g2WhGN7 jv1Q== 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 n8si2338963ejh.169.2019.09.27.01.27.11; Fri, 27 Sep 2019 01:27:37 -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 S1726964AbfI0IYx (ORCPT + 99 others); Fri, 27 Sep 2019 04:24:53 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:40910 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726163AbfI0IYx (ORCPT ); Fri, 27 Sep 2019 04:24:53 -0400 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id A038A687A6A0D46E8C97; Fri, 27 Sep 2019 16:24:51 +0800 (CST) Received: from [127.0.0.1] (10.177.251.225) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.439.0; Fri, 27 Sep 2019 16:24:50 +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> Message-ID: <68211803-de9a-cae1-2627-6a5e5ae0853b@huawei.com> Date: Fri, 27 Sep 2019 16:24:47 +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: <4d308608-54e2-05fa-5a1a-9cb7b4986bd1@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