Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp2766780imj; Mon, 11 Feb 2019 08:09:53 -0800 (PST) X-Google-Smtp-Source: AHgI3IYJWNLichSNqrulsVnv9SmmGJYUovNdoD2PAZlfFe4r/5Qi1fFF9GzqvUEoIK4DNpT+z0/K X-Received: by 2002:aa7:85cc:: with SMTP id z12mr5927950pfn.196.1549901393406; Mon, 11 Feb 2019 08:09:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549901393; cv=none; d=google.com; s=arc-20160816; b=d1JOSmOCsTdZg8HvioSM3gCOUIIIkTJi3E9S7eCzl2Ah4cPGp2XhCukPXIrn2s01zy SHaHH4ZJd1pfD75Eztf9V6E66es9tHh30nEOfHGmc6I5wLgmrTML1rkOdy9wHWJiOhR+ oGTAC4Bt382+38zgxhehyl/2mQp3t0H2kwlnq3iClCMbQnuVdFxcrXAlSLHcVGv/s3BH HxybpOtl6vPEefNWOZy0xkTyFZSKp9lIXglPGGoRfBRuGJHXsxRszMrWNJQyrh9u5EB8 VZ2Esdwee5ZyhjFch5dqr2kf/qMu+NsFATLx1rsoGScy2jk+E9JmfwRi5vbNeMywTeA4 kx4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=nidf2SpUNrViKN9AuNguf2Tb95S5DwvBO/8XUCwGO8s=; b=hzeM+enf+s5+DpvZjvxgb/NyxEK4g8q1BJBtLZt/DEptUS8Flx2PDnzFHLHRmrYqs8 /9+TaScsFWVgCKb1TavMgfEEeRVoBz0dBLy4qUimmM1YD+U6h/heyyp+FgUFRm5Dfd1C j6/K01kxfctGPo1e3mCIPBlj9ZqkWY4CKMnPgVj+ymffTU3gCs5lmCa2T2HSvSAqWA+d GQUn/Vak5QSu7LXrd1gGlURF/9kWGULGsD/6lCbTfX9WzjbhjvD4AqMc07mpSonp52br JV+8/E9eCzGSOcvbI7rVHTHu3H30TCk3vu89HM74jARkBJkXxD+nOYFTLaxoPsgUnprZ zQyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=HwjTRHM6; 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 e63si9901251pgc.239.2019.02.11.08.09.36; Mon, 11 Feb 2019 08:09:53 -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; dkim=pass header.i=@kernel.org header.s=default header.b=HwjTRHM6; 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 S1729616AbfBKO0v (ORCPT + 99 others); Mon, 11 Feb 2019 09:26:51 -0500 Received: from mail.kernel.org ([198.145.29.99]:60720 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729608AbfBKO0t (ORCPT ); Mon, 11 Feb 2019 09:26:49 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1DEB920821; Mon, 11 Feb 2019 14:26:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1549895208; bh=57IGTE/o9VT6eHD3lmKZ+r73F4KKa94SOIwc2/ngDBI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HwjTRHM6kt5KxrZwxvPzj55RxoJ2evby4K1wC8vo1uGxb5+hq6MdZDs1zUyMbOM7h KU1pqJkRsI4q645Gsh6VMoR5J5ilL4UO14R4jEewTYxTcr862+dtyGuv7sBBzd43rn WZ/RYdCQmvGCobBMv9PvYKONdl/Yu4k/IPtGNvVw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nicholas Mc Guire , Linus Walleij , Sasha Levin Subject: [PATCH 4.20 129/352] pinctrl: sx150x: handle failure case of devm_kstrdup Date: Mon, 11 Feb 2019 15:15:56 +0100 Message-Id: <20190211141854.616086871@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190211141846.543045703@linuxfoundation.org> References: <20190211141846.543045703@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.20-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit a9d9f6b83f1bb05da849b3540e6d1f70ef1c2343 ] devm_kstrdup() may return NULL if internal allocation failed. Thus using label, name is unsafe without checking. Therefor in the unlikely case of allocation failure, sx150x_probe() simply returns -ENOMEM. Signed-off-by: Nicholas Mc Guire Fixes: 9e80f9064e73 ("pinctrl: Add SX150X GPIO Extender Pinctrl Driver") Signed-off-by: Linus Walleij Signed-off-by: Sasha Levin --- drivers/pinctrl/pinctrl-sx150x.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/pinctrl/pinctrl-sx150x.c b/drivers/pinctrl/pinctrl-sx150x.c index cbf58a10113d..4d87d75b9c6e 100644 --- a/drivers/pinctrl/pinctrl-sx150x.c +++ b/drivers/pinctrl/pinctrl-sx150x.c @@ -1166,7 +1166,6 @@ static int sx150x_probe(struct i2c_client *client, } /* Register GPIO controller */ - pctl->gpio.label = devm_kstrdup(dev, client->name, GFP_KERNEL); pctl->gpio.base = -1; pctl->gpio.ngpio = pctl->data->npins; pctl->gpio.get_direction = sx150x_gpio_get_direction; @@ -1180,6 +1179,10 @@ static int sx150x_probe(struct i2c_client *client, pctl->gpio.of_node = dev->of_node; #endif pctl->gpio.can_sleep = true; + pctl->gpio.label = devm_kstrdup(dev, client->name, GFP_KERNEL); + if (!pctl->gpio.label) + return -ENOMEM; + /* * Setting multiple pins is not safe when all pins are not * handled by the same regmap register. The oscio pin (present @@ -1200,13 +1203,15 @@ static int sx150x_probe(struct i2c_client *client, /* Add Interrupt support if an irq is specified */ if (client->irq > 0) { - pctl->irq_chip.name = devm_kstrdup(dev, client->name, - GFP_KERNEL); pctl->irq_chip.irq_mask = sx150x_irq_mask; pctl->irq_chip.irq_unmask = sx150x_irq_unmask; pctl->irq_chip.irq_set_type = sx150x_irq_set_type; pctl->irq_chip.irq_bus_lock = sx150x_irq_bus_lock; pctl->irq_chip.irq_bus_sync_unlock = sx150x_irq_bus_sync_unlock; + pctl->irq_chip.name = devm_kstrdup(dev, client->name, + GFP_KERNEL); + if (!pctl->irq_chip.name) + return -ENOMEM; pctl->irq.masked = ~0; pctl->irq.sense = 0; -- 2.19.1