Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp8310814imu; Tue, 4 Dec 2018 06:28:28 -0800 (PST) X-Google-Smtp-Source: AFSGD/V2CcIHgHzhFg4eiNG4Cw9em3O4VRyDh+uQCzKRMe01D94E4XupNxX3sd0l3/PeypUTRbgb X-Received: by 2002:a62:29c3:: with SMTP id p186mr20595522pfp.117.1543933708528; Tue, 04 Dec 2018 06:28:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543933708; cv=none; d=google.com; s=arc-20160816; b=zlQEphv/uggw/iBMTiFrPa/vmONerL9aIGy0EDfvoBg/qo8v0dwXyt9DbjpuQVAQM2 AYBQeZNs1l8T/9QoObEN8rV3pnj5KUgJxxiA9F4DAMXGyQpx2pLYSXJ2SPdajxfuzZnQ 9RJfYO7GClrZctMAN3s4+jmz2vVOgZxSXRjOGv3V10678AX2J9Y2rlFzy16s4UM6a69D zpN5g7RzMA2kPY+7o3POU4kq/fBARnnNR9VmPY5SN/yL5Hj0HEvvu43t35rYCSgWOwnb k4gy/DjMSjS2mIguzkj72WkA2RexRmw+lC2kOADu0DRcWwjUPN/4IraiFa4Arvk078Dd sELg== 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=BG04oj6GcPnxVJy/sQpjPiluXRDxDImTUzIj58iR6BA=; b=hRGLF6+HTvODyIT05nZ+Yl6wYd6mcQwYZWwcwc5OZyXky6zZLHDqtu8o89F0uANIJN dTr9+Dfdd0yKgUn0ihNTNn50uoOSBaWadJ0Wrr0V4vQnL5S0XbhLPDPjzhhoWv7r8GpX 0x7TR4Fq5eo8Q84WWb2/QDo3DqPWordUXMUoXkJHs0cbm1rAnrjuAkBR0DClcfZbYedD mPy0Xfy1BtoP/hxZpUjtZBca48ZrVQQr+R1NFErN9IINAH9JD8l6mr+Ua8ShhHS7cfl7 kH9PYb/FNZ7TH5jD97FgsZ/EOXV6f3zlvUFUoj3cej/raYOdZ9Iy3B5KpY+tfn5Ryie+ 7WNg== 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 m32si1225207pld.86.2018.12.04.06.28.13; Tue, 04 Dec 2018 06:28:28 -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 S1726720AbeLDOZp (ORCPT + 99 others); Tue, 4 Dec 2018 09:25:45 -0500 Received: from 178.115.242.59.static.drei.at ([178.115.242.59]:37927 "EHLO mail.osadl.at" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725956AbeLDOZo (ORCPT ); Tue, 4 Dec 2018 09:25:44 -0500 Received: by mail.osadl.at (Postfix, from userid 1001) id BD8F85C0FF8; Tue, 4 Dec 2018 14:25:04 +0000 (UTC) Date: Tue, 4 Dec 2018 15:25:04 +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: <20181204142504.GA16001@osadl.at> References: <1543658470-20887-1-git-send-email-hofrat@osadl.org> <549eba3a-28b9-e4b0-f680-8fb51b160879@axentia.se> <20181204121318.GB28201@osadl.at> <2c43e965-9a12-0367-fb23-bedfaaed4f68@axentia.se> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2c43e965-9a12-0367-fb23-bedfaaed4f68@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 01:49:11PM +0000, Peter Rosin wrote: > On 2018-12-04 13:13, Nicholas Mc Guire wrote: > > 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 ? > > Well, I don't know the details, but checkpatch will warn about simple > error messages on devm_kstrdup failure (if I read the checkpatch source > correctly). But in this case there are two parallel conditions in the > if and hence checkpatch stumbles, but gist is the same, you should not > sprinkle messages on memory allocation failure. > not in this case - atleast checkpatch --strict on the original patch did not issue any complaint to that ends. But yes - you are right that the intent in checkpatch is clear and this should not be carrying a failure message. thx! hofrat