From patchwork Sat Sep 24 15:57:14 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: huajun li X-Patchwork-Id: 116227 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 44386B6F77 for ; Sun, 25 Sep 2011 01:57:22 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751773Ab1IXP5Q (ORCPT ); Sat, 24 Sep 2011 11:57:16 -0400 Received: from mail-fx0-f46.google.com ([209.85.161.46]:37651 "EHLO mail-fx0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751705Ab1IXP5P (ORCPT ); Sat, 24 Sep 2011 11:57:15 -0400 Received: by mail-fx0-f46.google.com with SMTP id 4so4732097fxe.19 for ; Sat, 24 Sep 2011 08:57:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:cc:content-type; bh=xESslgqcDAonbLcB30dxS+YUfNPAeKas/4s874jJA7c=; b=TxYwV1hcETYzRgTh5Jo4vNneBgTtVXMdvnDAznlXh1vddwyABmw4GYtTrIf6xVT4JA 1L4KJPXmGp4kkFPL2mUmfUAxJyDTlwvht1SZ/oCDK5mcxHBxpILXLjwPK6zVEc+kxqyg 4E2SCcZ150ruT1BcvHrn2EfnRlapR8l2LBq8M= MIME-Version: 1.0 Received: by 10.223.47.207 with SMTP id o15mr7149146faf.88.1316879834438; Sat, 24 Sep 2011 08:57:14 -0700 (PDT) Received: by 10.223.114.195 with HTTP; Sat, 24 Sep 2011 08:57:14 -0700 (PDT) Date: Sat, 24 Sep 2011 23:57:14 +0800 Message-ID: Subject: [PATCH 2/2] net: Fix potential memory leak From: Huajun Li To: David Miller Cc: netdev , Huajun Li Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org While preparing flow caches, once fail may cause potential memory leak , fix it. Signed-off-by: Huajun Li --- net/core/flow.c | 19 ++++++++++++++++++- 1 files changed, 18 insertions(+), 1 deletions(-) diff --git a/net/core/flow.c b/net/core/flow.c index ba3e617..2dcaa03 100644 --- a/net/core/flow.c +++ b/net/core/flow.c @@ -420,7 +420,7 @@ static int __init flow_cache_init(struct flow_cache *fc) for_each_online_cpu(i) { if (flow_cache_cpu_prepare(fc, i)) - return -ENOMEM; + goto err; } fc->hotcpu_notifier = (struct notifier_block){ .notifier_call = flow_cache_cpu, @@ -433,6 +433,23 @@ static int __init flow_cache_init(struct flow_cache *fc) add_timer(&fc->rnd_timer); return 0; +err: + if (fc->percpu) { + free_percpu(fc->percpu); + fc->percpu = NULL; + } + + /* + * Check each possible CPUs rather than online ones because they may be + * offline before the notifier is registered. + */ + for_each_possible_cpu(i) { + struct flow_cache_percpu *fcp = per_cpu_ptr(fc->percpu, i); + kfree(fcp->hash_table); + fcp->hash_table = NULL; + } + + return -ENOMEM; } static int __init flow_cache_init_global(void)