From patchwork Tue Aug 11 11:23:08 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 505937 X-Patchwork-Delegate: michael@ellerman.id.au 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 829B21401AD for ; Tue, 11 Aug 2015 21:29:29 +1000 (AEST) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 6880D1A2C18 for ; Tue, 11 Aug 2015 21:29:29 +1000 (AEST) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lists.ozlabs.org (Postfix) with ESMTP id 891291A1C07 for ; Tue, 11 Aug 2015 21:23:45 +1000 (AEST) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga102.jf.intel.com with ESMTP; 11 Aug 2015 04:23:43 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.15,652,1432623600"; d="scan'208";a="766359392" Received: from black.fi.intel.com ([10.237.72.157]) by fmsmga001.fm.intel.com with ESMTP; 11 Aug 2015 04:23:41 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 9CA912F1; Tue, 11 Aug 2015 14:23:10 +0300 (EEST) From: Andy Shevchenko To: Benjamin Herrenschmidt , linuxppc-dev@lists.ozlabs.org, Michael Ellerman , Segher Boessenkool Subject: [PATCH v2 4/5] powerpc/pseries: handle nodes without '/' Date: Tue, 11 Aug 2015 14:23:08 +0300 Message-Id: <1439292189-78925-4-git-send-email-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1439292189-78925-1-git-send-email-andriy.shevchenko@linux.intel.com> References: <1439292189-78925-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 node without '/' strrchr() returns NULL which might lead to crash. Replace strrchr() by kbasename() and modify condition to avoid such behaviour. Suggested-by: Segher Boessenkool Signed-off-by: Andy Shevchenko --- arch/powerpc/platforms/pseries/of_helpers.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/powerpc/platforms/pseries/of_helpers.c b/arch/powerpc/platforms/pseries/of_helpers.c index 8c6b05a..4417afe 100644 --- a/arch/powerpc/platforms/pseries/of_helpers.c +++ b/arch/powerpc/platforms/pseries/of_helpers.c @@ -17,14 +17,14 @@ struct device_node *pseries_of_derive_parent(const char *path) { struct device_node *parent; char *parent_path = "/"; - size_t parent_path_len = strrchr(path, '/') - path + 1; + const char *tail = kbasename(path); /* reject if path is "/" */ if (!strcmp(path, "/")) return ERR_PTR(-EINVAL); - if (strrchr(path, '/') != path) { - parent_path = kstrndup(path, parent_path_len, GFP_KERNEL); + if (tail > path + 1) { + parent_path = kstrndup(path, tail - path, GFP_KERNEL); if (!parent_path) return ERR_PTR(-ENOMEM); }