Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2440950imu; Wed, 21 Nov 2018 11:40:00 -0800 (PST) X-Google-Smtp-Source: AFSGD/Wt1jlHk7oEXvR5pcFY78yCQW6IAs1fyojb7rPEIU793jMOlsJjzo4jm7oEkNBybY6Owi4k X-Received: by 2002:a63:b4c:: with SMTP id a12mr7281067pgl.131.1542829200434; Wed, 21 Nov 2018 11:40:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542829200; cv=none; d=google.com; s=arc-20160816; b=KmKGPdg8+ESiIWa+jAWSB6mNNJ6W5l3SHbvQhkHXd4cXbwWiOwTnsKdmCQf4hSp9P2 GpWrZ/jp+fOBcuF89NjL68OhaSp5t+yJBHRjTDBZdUV0c/l6p2OC8cHh/dyUGMgK8Kfz 3EEZa3pTyC0ILJ9ejbSbmW2ykFR5agR7Rp9ZesP47WGCXnX5AjrBXdUXRvJMP61DWmRi THCNGgoqibSicNWv6jslmDl02iwI5TUMvfoLoyoDjOz5TB00o8xJMtrC8YnZYTMvZsNq 2/ILFG26gDQ+YauY0ab9ymxN1tUnlT2++yL57HbaERSKaCsIGAd0VajJddhgDVQj8ozx 7qvg== 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-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=fvvF7Van23wj03QnaPCQ2rBLKlnfXkxoA2CrN+LFOaQ=; b=s/RtiMRExUjjHcLU1WauGnxdqiu6A1VPFfeqVLlue0mCY7gPbXFZCCibOLbSxL59ge Iq/O/a2KNs9sBL3HdtJV6jwTrmsRYdVbcYBQegdfUWnpfQoQWCrMPv2td2akcqrd9l/F 35mZUF2sQB3vpEy7v9IszwNCX6ANQp6wIuDEyNGjBSBdUvILaQ3gSKDh5NhuGSjq4Zxg K68/HMh0v5IhwnVACFwbXBP9kkl/h4LyWq1buiztWtAf/1RCkLRowlBPkcvOtgEQYz19 l6+odQV0JxTnvKh8TbpbE6Zi4cbowM4lwScP+1o2QXPtsVStYdJeYrOBiknGpjGbHRmx xJJA== 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 9si1842894pfq.129.2018.11.21.11.39.45; Wed, 21 Nov 2018 11:40:00 -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 S1730505AbeKVDop (ORCPT + 99 others); Wed, 21 Nov 2018 22:44:45 -0500 Received: from 178.115.242.59.static.drei.at ([178.115.242.59]:58536 "EHLO mail.osadl.at" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725995AbeKVDop (ORCPT ); Wed, 21 Nov 2018 22:44:45 -0500 X-Greylist: delayed 461 seconds by postgrey-1.27 at vger.kernel.org; Wed, 21 Nov 2018 22:44:43 EST Received: by mail.osadl.at (Postfix, from userid 1001) id 6A58F5C06C6; Wed, 21 Nov 2018 17:01:16 +0000 (UTC) Date: Wed, 21 Nov 2018 18:01:16 +0100 From: Nicholas Mc Guire To: Bartosz Golaszewski Cc: hofrat@osadl.org, Linus Walleij , matthias.bgg@gmail.com, sergio.paracuellos@gmail.com, linux-gpio , LKML , arm-soc , linux-mediatek@lists.infradead.org Subject: Re: [PATCH] gpio: mt7621: handle failure of devm_kasprintf() Message-ID: <20181121170116.GA10656@osadl.at> References: <1542818142-27800-1-git-send-email-hofrat@osadl.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: 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 Wed, Nov 21, 2018 at 05:43:43PM +0100, Bartosz Golaszewski wrote: > ??r., 21 lis 2018 o 17:39 Nicholas Mc Guire napisa??(a): > > > > kasprintf() may return NULL on failure of internal allocation thus the > > assigned label is not safe if not explicitly checked. On error > > mediatek_gpio_bank_probe() returns negative values so -ENOMEM in the > > (unlikely) failure case should be fine here. > > > > Signed-off-by: Nicholas Mc Guire > > Fixes: 4ba9c3afda41 ("gpio: mt7621: Add a driver for MT7621") > > --- > > > > Problem located with experimental coccinelle script > > > > Patch was compile tested with: omega2p_defconfig, SOC_MT7621=y, > > GPIOLIB=y, GPIO_MT7621=y > > > > Patch is against 4.20-rc3 (localversion-next is next-20181121) > > > > drivers/gpio/gpio-mt7621.c | 4 ++++ > > 1 file changed, 4 insertions(+) > > > > diff --git a/drivers/gpio/gpio-mt7621.c b/drivers/gpio/gpio-mt7621.c > > index d72af6f..42f0c67 100644 > > --- a/drivers/gpio/gpio-mt7621.c > > +++ b/drivers/gpio/gpio-mt7621.c > > @@ -244,6 +244,10 @@ mediatek_gpio_bank_probe(struct device *dev, > > rg->chip.of_xlate = mediatek_gpio_xlate; > > rg->chip.label = devm_kasprintf(dev, GFP_KERNEL, "%s-bank%d", > > dev_name(dev), bank); > > + if (!rg->chip.label) { > > + dev_err(dev, "Could not allocate label\n"); > > No need for an error message here, an -ENOMEM says enough. > I just thought its more consistent with the rest of the code - and as it is a highly unlikely event it would probably be hard to pinpoint as some of the other functions can return -ENOMEM (but with a message). ....and the call site of mediatek_gpio_bank_probe() actually currently ignores the return value so the -ENOMEM would go unnoticed which is a bug as well - patch for that a bit later. anyway fine with me - I?ll send a V2 and drop the dev_err() here. thx! hofrat > Bart > > > + return -ENOMEM; > > + } > > > > ret = devm_gpiochip_add_data(dev, &rg->chip, mtk); > > if (ret < 0) { > > -- > > 2.1.4 > >