From patchwork Wed Apr 22 13:17:09 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 6255991 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 7F58B9F389 for ; Wed, 22 Apr 2015 13:21:23 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9841520320 for ; Wed, 22 Apr 2015 13:21:21 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C019920165 for ; Wed, 22 Apr 2015 13:21:20 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1YkuXw-000485-OC; Wed, 22 Apr 2015 13:18:32 +0000 Received: from mail-pd0-x22b.google.com ([2607:f8b0:400e:c02::22b]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1YkuXg-000435-6K for linux-arm-kernel@lists.infradead.org; Wed, 22 Apr 2015 13:18:16 +0000 Received: by pdbqd1 with SMTP id qd1so274285993pdb.2 for ; Wed, 22 Apr 2015 06:17:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=zyD7fZN/mcFrbY6ktMhJSa/MLrvWTgLiJxiRCybxTsg=; b=D6hiK/ruyhkwjAeNZoyKxq5j9R98pJh23ii5GrroFxjxTbmaGCHNV1egvUQpZC8Q1w /eXO4mod3ifwNFAZjI7baLyiJKKfhUafNxy+ADJH8PEZJFShmDZNZ7NqfdKgZCHot43T BV59XPytZeEVU4t1g8ozfyioFPDVqFAzzdWGVm6VkP8O85agL1PkPKiFvEqyYTv3atx7 8j2SxclrDNgiltvhP2Ke2nbn4bkf1LvyJI8n7itcknLl7ot3wdRRyjuroFuFSPMMRSPL h0qUE4A+N2FZPFFhrwBBAzjOyMxt/Xv4STjtDdBit8vRC58XjL/NPupSsH7xK4VxkOg0 D7qw== X-Received: by 10.70.129.106 with SMTP id nv10mr6368560pdb.160.1429708674417; Wed, 22 Apr 2015 06:17:54 -0700 (PDT) Received: from localhost.localdomain ([125.130.175.98]) by mx.google.com with ESMTPSA id sz7sm5193014pab.22.2015.04.22.06.17.52 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 22 Apr 2015 06:17:53 -0700 (PDT) From: Krzysztof Kozlowski To: Kukjin Kim , linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RESEND PATCH v2 2/3] ARM: EXYNOS: Handle of_find_device_by_node and kstrdup failures Date: Wed, 22 Apr 2015 22:17:09 +0900 Message-Id: <1429708630-19810-2-git-send-email-k.kozlowski.k@gmail.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1429708630-19810-1-git-send-email-k.kozlowski.k@gmail.com> References: <1429708630-19810-1-git-send-email-k.kozlowski.k@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150422_061816_335983_5228C37D X-CRM114-Status: GOOD ( 11.57 ) X-Spam-Score: -0.8 (/) Cc: Krzysztof Kozlowski X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Krzysztof Kozlowski Prevent possible NULL pointer dereference of pointer returned by of_find_device_by_node(). Handle this by skipping such power domain. Additionally fail the init on kstrdup() failure. Such case is actually not fatal because the name for power domain allocated by kstrdup() is used only in printk. Still as a precaution handle this as an error condition. Signed-off-by: Krzysztof Kozlowski --- Changes since v1: None. --- arch/arm/mach-exynos/pm_domains.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/arch/arm/mach-exynos/pm_domains.c b/arch/arm/mach-exynos/pm_domains.c index 14622b5f4481..61c32ccc9f7a 100644 --- a/arch/arm/mach-exynos/pm_domains.c +++ b/arch/arm/mach-exynos/pm_domains.c @@ -126,6 +126,12 @@ static __init int exynos4_pm_init_power_domain(void) struct device *dev; pdev = of_find_device_by_node(np); + if (!pdev) { + pr_err("%s: failed to find device for node %s\n", + __func__, np->name); + of_node_put(np); + continue; + } dev = &pdev->dev; pd = kzalloc(sizeof(*pd), GFP_KERNEL); @@ -136,6 +142,12 @@ static __init int exynos4_pm_init_power_domain(void) } pd->pd.name = kstrdup(dev_name(dev), GFP_KERNEL); + if (!pd->pd.name) { + kfree(pd); + of_node_put(np); + return -ENOMEM; + } + pd->name = pd->pd.name; pd->base = of_iomap(np, 0); if (!pd->base) {