Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp8171414imu; Tue, 4 Dec 2018 04:15:48 -0800 (PST) X-Google-Smtp-Source: AFSGD/XelP54/B9ebDmnRLN2/Jhzf8LkIQ+hxMJX5Qf0xgS7To2MDNIATwfeMkmmMZMFH5GRwlKU X-Received: by 2002:a63:504d:: with SMTP id q13mr16878366pgl.319.1543925748218; Tue, 04 Dec 2018 04:15:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543925748; cv=none; d=google.com; s=arc-20160816; b=CrTXnMvHhBYtU2yxJHaMYVRmh7+rVkGLYMXYmhkoUFHfVpfVA/Fnu4/JaOc62DYmv3 j0L3avKUc3py2kWvSW3JPpuCF3XfJhdpiq2Z3DWI/UgbRezYhYMoXVra6mfYjxQ0/l+k QCpN33RrWIepWgwIrNxFPWm+MA8gkv7gX2Qw1y9fXNQUQ/hArT8tzIYLV+wn26kPcTJf BHlSOeSqj7Eh1jhX+ZahT2dO4d3QDFV9bRS5vACZMgDz0/sBW5kx86wpPFCHg7xpjlCC OAwEU8KnAsuQq6f4djVDgNxQACT1TfTWQOivpGySakRNnn0YJn01S+kaH1ERkxkL+DKw m+4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=0Gs/5UMFz1Hi1GR/+6AZ2u15VQ1ZWQHWk6x8L8/4Y40=; b=ZULl/E68N1fR5oj0XjnS0L6MkNpbqsh/dwP2KPXb+BnngACIrt5ckPWe0O55DZ26p7 L29uChXPd7VREYicp2JujYcbXCanopLWLuxcGKs76WLkDDoigykHm4jKh/adviH1T8kK SSW1uvKSxSLj4wgANv2EnofTPwOBaScbK0JpnVkXR0xl0WDAOejqnC8+xI6e08bvNRwN NXkSiq7FHrm0SUmUym6bFULBBoqv7WKofojB0xBdlKQ+Y4NwAu1wBCSGiA9fL4Kqzi/U FnDNfXkMGiYTiXNnOk6bA/TC4bPAl2OoRiXSeR0OeWYGpAtk0VU82c00RqB1xov82sM4 uXSw== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j12si15538748pgq.26.2018.12.04.04.15.32; Tue, 04 Dec 2018 04:15:48 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726226AbeLDMN5 (ORCPT + 99 others); Tue, 4 Dec 2018 07:13:57 -0500 Received: from 178.115.242.59.static.drei.at ([178.115.242.59]:37813 "EHLO mail.osadl.at" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726143AbeLDMN5 (ORCPT ); Tue, 4 Dec 2018 07:13:57 -0500 Received: by mail.osadl.at (Postfix, from userid 1001) id 768415C0FF8; Tue, 4 Dec 2018 12:13:18 +0000 (UTC) Date: Tue, 4 Dec 2018 13:13:18 +0100 From: Nicholas Mc Guire To: Peter Rosin Cc: Nicholas Mc Guire , Wolfram Sang , "linux-i2c@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH] i2c: mux: demux-pinctrl: handle failure case of devm_kstrdup() Message-ID: <20181204121318.GB28201@osadl.at> References: <1543658470-20887-1-git-send-email-hofrat@osadl.org> <549eba3a-28b9-e4b0-f680-8fb51b160879@axentia.se> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <549eba3a-28b9-e4b0-f680-8fb51b160879@axentia.se> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Dec 04, 2018 at 11:16:59AM +0000, Peter Rosin wrote: > Hi! > > This patch looks like a good idea. However, a nitpick below. > > On 2018-12-01 11:01, Nicholas Mc Guire wrote: > > devm_kstrdup() may return NULL if internal allocation failed. > > Thus using name, value is unsafe without being checked. As > > i2c_demux_pinctrl_probe() can return -ENOMEM in other cases > > a dev_err() message is included to make the failure location > > clear. > > > > Signed-off-by: Nicholas Mc Guire > > Fixes: e35478eac030 ("i2c: mux: demux-pinctrl: run properly with multiple instances") > > --- > > > > Problem located with experimental coccinelle script > > > > Q: The use of devm_kstrdup() seems a bit odd while technically not wrong, > > personally I think devm_kasprintf() would be more suitable here. > > > > Patch was compile tested with: multi_v7_defconfig > > (implies I2C_DEMUX_PINCTRL=y) > > > > Patch is against 4.20-rc4 (localversion-next is next-20181130) > > > > drivers/i2c/muxes/i2c-demux-pinctrl.c | 6 ++++++ > > 1 file changed, 6 insertions(+) > > > > diff --git a/drivers/i2c/muxes/i2c-demux-pinctrl.c b/drivers/i2c/muxes/i2c-demux-pinctrl.c > > index 035032e..c466999 100644 > > --- a/drivers/i2c/muxes/i2c-demux-pinctrl.c > > +++ b/drivers/i2c/muxes/i2c-demux-pinctrl.c > > @@ -244,6 +244,12 @@ static int i2c_demux_pinctrl_probe(struct platform_device *pdev) > > > > props[i].name = devm_kstrdup(&pdev->dev, "status", GFP_KERNEL); > > props[i].value = devm_kstrdup(&pdev->dev, "ok", GFP_KERNEL); > > + if (!props[i].name || !props[i].value) { > > + dev_err(&pdev->dev, > > + "chan %d name, value allocation failed\n", i); > > Please drop this memory allocation failure message. You should get such a > message from devm_kstrdup. > hm...tried to figure out where that message would be comming from - but I could not find any point in the call tree that would issue such a message ? devm_kstrdup() -> devm_kmalloc() -> alloc_dr() --> kmalloc_track_caller() (non-NUMA) | -> __kmalloc_node() | -> __do_kmalloc_node() `-> __kmalloc_node_track_caller() (NUMA) -> __do_kmalloc_node() __do_kmalloc_node() seems like it simply returns NULL but issues no failure message. Am I overlooking something ? thx! hofrat > Cheers, > Peter > > > + err = -ENOMEM; > > + goto err_rollback; > > + } > > props[i].length = 3; > > > > of_changeset_init(&priv->chan[i].chgset); > > >