From patchwork Tue Aug 4 14:36:46 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 503631 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 087DB1402C4 for ; Wed, 5 Aug 2015 00:37:55 +1000 (AEST) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id E255F1A1D0B for ; Wed, 5 Aug 2015 00:37:54 +1000 (AEST) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lists.ozlabs.org (Postfix) with ESMTP id 834271A076F for ; Wed, 5 Aug 2015 00:36:56 +1000 (AEST) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga103.fm.intel.com with ESMTP; 04 Aug 2015 07:36:55 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.15,609,1432623600"; d="scan'208";a="535836162" Received: from black.fi.intel.com ([10.237.72.157]) by FMSMGA003.fm.intel.com with ESMTP; 04 Aug 2015 07:36:52 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id A1B3216B; Tue, 4 Aug 2015 17:36:51 +0300 (EEST) From: Andy Shevchenko To: Benjamin Herrenschmidt , linuxppc-dev@lists.ozlabs.org, Michael Ellerman Subject: [PATCH 2/5] powerpc/pseries: fix a potential memory leak Date: Tue, 4 Aug 2015 17:36:46 +0300 Message-Id: <1438699009-112794-2-git-send-email-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.4.6 In-Reply-To: <1438699009-112794-1-git-send-email-andriy.shevchenko@linux.intel.com> References: <1438699009-112794-1-git-send-email-andriy.shevchenko@linux.intel.com> X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Andy Shevchenko MIME-Version: 1.0 Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" In case we have a full node name like /foo/bar and /foo is not found the parent_path left unfreed. So, free a memory before return to a caller. Signed-off-by: Andy Shevchenko --- arch/powerpc/platforms/pseries/of_helpers.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/arch/powerpc/platforms/pseries/of_helpers.c b/arch/powerpc/platforms/pseries/of_helpers.c index 1cbd896..2f363e3 100644 --- a/arch/powerpc/platforms/pseries/of_helpers.c +++ b/arch/powerpc/platforms/pseries/of_helpers.c @@ -15,7 +15,7 @@ */ struct device_node *pseries_of_derive_parent(const char *path) { - struct device_node *parent = NULL; + struct device_node *parent; char *parent_path = "/"; size_t parent_path_len = strrchr(path, '/') - path + 1; @@ -30,9 +30,7 @@ struct device_node *pseries_of_derive_parent(const char *path) strlcpy(parent_path, path, parent_path_len); } parent = of_find_node_by_path(parent_path); - if (!parent) - return ERR_PTR(-EINVAL); if (strcmp(parent_path, "/")) kfree(parent_path); - return parent; + return parent ? parent : ERR_PTR(-EINVAL); }