Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp9926014imu; Wed, 5 Dec 2018 12:44:36 -0800 (PST) X-Google-Smtp-Source: AFSGD/VYsUsRGYy9LS37hWllwEoT+/tEyFk3oyArMB5fdNI6CB0DAPKx3uYvrfb4mAXa5TDEVJ89 X-Received: by 2002:a17:902:2a66:: with SMTP id i93mr25167610plb.113.1544042676770; Wed, 05 Dec 2018 12:44:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544042676; cv=none; d=google.com; s=arc-20160816; b=Yjpu5PTax6232cpwG1Pi03ICYm3CyX/DHo84RmZYWQP1Bzng0OuqHl+UbMjM9qAjF2 bOheM96J62T8Na5DBX6Er/nE60Sk+b8TuLN5ONhNM0aLH1e8n+lKkVuAIIKpRgu5iN1c EVR+/RwhUr4/6GTrQxiDEvwX4LDGTi7xSlwGIPXxk9cU4G5cwth9AMvpqp5zhFmxYVFn GfSjxdgypCkF/rX0zZh+e5HPoK9Xj/IYYbOstzne6GUGVJ1mxY6w6sC3RlqN60oqTkAc tl0Xf2Ur6W268hK15FDiFmcC/JxCM/8pDyr6Qk+z6tAqr20B9Yj7iJH3v+S2s7pHII8B SFsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version; bh=WtfdFOrHLEdBRRSKnZ3mtxk3yR28RHuLiNsARcqEx70=; b=WN3bkSuS/Pc31gdPrVil3L8bhL8JgxXyN2M+oY5CR7maRMoR/pwqAaZ4lJMThY8vvl Ks7fVshhOMwVIJTiS7P630FTfzyUyPEhYqnuky069breBzDvswmyWfbf8A0jtO5Y0MXI Pu3+bTVcdr/qNiIG9nxbiEf4ru6Lw1MWB8urLhl8FqJZLU4pEYs0DXx11EqeU6tT/B5x mHekW4Xlx/r6Uw4+RcgXZnkATyaLA+tZPxkkiWlY/2DtzwiZxf8FQuvbTyHjHJNYF1yu da/cfmUIhGnkUwJM2F4ppejbytMX540SVZqcdU8ZXkbIKnsyxetTB1SeJA6w8v0GG5ao v4hA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r18si19452420pgo.9.2018.12.05.12.44.21; Wed, 05 Dec 2018 12:44:36 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728616AbeLEUnJ (ORCPT + 99 others); Wed, 5 Dec 2018 15:43:09 -0500 Received: from mail-oi1-f196.google.com ([209.85.167.196]:34738 "EHLO mail-oi1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727257AbeLEUnI (ORCPT ); Wed, 5 Dec 2018 15:43:08 -0500 Received: by mail-oi1-f196.google.com with SMTP id h25so18807713oig.1 for ; Wed, 05 Dec 2018 12:43:08 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=WtfdFOrHLEdBRRSKnZ3mtxk3yR28RHuLiNsARcqEx70=; b=qIJOMeyAjwK4ny9cRniRFVBmghUOr6xEwo8ITBRHeZrMBgoENOPYS2ikR87C26hFvv u/jbqJIB4RnRIspV5S9SCdmgt7F+5p8WnHlDbXp5J8XJuY1qChzmsodFWSjvzhUifxJZ JqgU5+t39/xFhygPw8d7yzocTxeYB3u6FCcCOskEKiZcuNegP6Trju7XArJmO1BVTFj1 jH99I+UAq/Qt5o3KuOnF/fBWgakxcE64nnEAR6jiS/S1jM6CggrtH5pebwQolh7s/t47 iAYFf9iPS9TcWYK3kEzRufoIG2+r444fkoKWaOzAjvpzk4SwSZavyZBnFw5xe0egpIuS OtSA== X-Gm-Message-State: AA+aEWYqvdXkzGtSWKkFdNgNdF2q1UWKWPdYRz4i0BbNOBKWQd4AKxMA urNgWyOmU6JaOgOIB/hiazQ2eCnVj+0= X-Received: by 2002:aca:7c5:: with SMTP id 188mr14913341oih.313.1544042587742; Wed, 05 Dec 2018 12:43:07 -0800 (PST) Received: from mail-oi1-f178.google.com (mail-oi1-f178.google.com. [209.85.167.178]) by smtp.gmail.com with ESMTPSA id h7sm8321309otb.45.2018.12.05.12.43.06 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Dec 2018 12:43:07 -0800 (PST) Received: by mail-oi1-f178.google.com with SMTP id x23so18770337oix.3 for ; Wed, 05 Dec 2018 12:43:06 -0800 (PST) X-Received: by 2002:aca:654a:: with SMTP id j10mr15212756oiw.301.1544042586603; Wed, 05 Dec 2018 12:43:06 -0800 (PST) MIME-Version: 1.0 References: <1543741258-17433-1-git-send-email-hofrat@osadl.org> In-Reply-To: <1543741258-17433-1-git-send-email-hofrat@osadl.org> From: Li Yang Date: Wed, 5 Dec 2018 14:42:55 -0600 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC PATCH] soc: fsl: guts: handle devm_kstrdup() failure To: hofrat@osadl.org Cc: linuxppc-dev , "moderated list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE" , lkml Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Dec 2, 2018 at 3:07 AM Nicholas Mc Guire wrote: > > 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. I think your assumption is correct. Do you want to send a new and better version? :) > > 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); > -- > 2.1.4 >