From patchwork Sun Dec 2 09:00:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Mc Guire X-Patchwork-Id: 1006473 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4373XK21ndz9sD4 for ; Sun, 2 Dec 2018 21:00:17 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=osadl.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 4373XK0Dr5zDqg9 for ; Sun, 2 Dec 2018 21:00:17 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=osadl.org X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=osadl.org (client-ip=62.245.132.105; helo=www.osadl.org; envelope-from=hofrat@osadl.org; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=osadl.org X-Greylist: delayed 3116 seconds by postgrey-1.36 at bilbo; Sun, 02 Dec 2018 20:58:40 AEDT Received: from www.osadl.org (www.osadl.org [62.245.132.105]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4373VS3JffzDqQW for ; Sun, 2 Dec 2018 20:58:39 +1100 (AEDT) Received: from debian01.hofrr.at (178.115.242.59.static.drei.at [178.115.242.59]) by www.osadl.org (8.13.8/8.13.8/OSADL-2007092901) with ESMTP id wB2942Us005968; Sun, 2 Dec 2018 10:04:02 +0100 From: Nicholas Mc Guire To: Li Yang Subject: [RFC PATCH] soc: fsl: guts: handle devm_kstrdup() failure Date: Sun, 2 Dec 2018 10:00:58 +0100 Message-Id: <1543741258-17433-1-git-send-email-hofrat@osadl.org> X-Mailer: git-send-email 2.1.4 X-Spam-Status: No, score=-1.9 required=6.0 tests=BAYES_00 autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on www.osadl.org X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Nicholas Mc Guire Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" devm_kstrdup() may return NULL if internal allocation failed. soc_dev_attr.machine should be checked (although its only use in pr_info() would be safe even with a NULL). Therefor in the unlikely case of allocation failure, fsl_guts_probe() returns -ENOMEM as this allocating failing is an indication of something more serious going wrong at system level. As machine is from the device tree which I assume to be RO - if that assumption is always correct - a better alternative would be to use devm_kstrdup_const() here. That would then simply copy the reference to the RO data and not perform any allocation at all. Signed-off-by: Nicholas Mc Guire Fixes: a6fc3b698130 ("soc: fsl: add GUTS driver for QorIQ platforms") --- Problem located by experimental coccinelle script Patch was compile tested with: multi_v7_defconfig (implies FSL_GUTS=y) Patch is against 4.20-rc4 (localversion-next is next-20181130) drivers/soc/fsl/guts.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/soc/fsl/guts.c b/drivers/soc/fsl/guts.c index 302e0c8..a0c751b 100644 --- a/drivers/soc/fsl/guts.c +++ b/drivers/soc/fsl/guts.c @@ -156,8 +156,11 @@ static int fsl_guts_probe(struct platform_device *pdev) if (of_property_read_string(root, "model", &machine)) of_property_read_string_index(root, "compatible", 0, &machine); of_node_put(root); - if (machine) + if (machine) { soc_dev_attr.machine = devm_kstrdup(dev, machine, GFP_KERNEL); + if (!soc_dev_attr.machine) + return -ENOMEM; + } svr = fsl_guts_get_svr(); soc_die = fsl_soc_die_match(svr, fsl_soc_die);