Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp2681791imj; Mon, 11 Feb 2019 06:58:45 -0800 (PST) X-Google-Smtp-Source: AHgI3Ibj1T6dmHLhGleh6G0SlfY/366+Kz03i7HUoZkfZAkDpeBuCSOjxBvoOCLpYoKrZhDY3FQO X-Received: by 2002:a62:1212:: with SMTP id a18mr38068739pfj.217.1549897124765; Mon, 11 Feb 2019 06:58:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549897124; cv=none; d=google.com; s=arc-20160816; b=lUof5hVnlRI10Ds04puRcmMzloIuLhMxok9cNBgEh2o9Rex3ooDQaH7pYfAdrL7UR8 ZRfF73MzKajPdETLyI3ag4kthmyROZFpzmbNOsEtyrYLtzUYzXVpXabU5JrOxb0C9nRV lz0SEUn1yThBhVuCEPfOcpUaTck4//nK0HB9P766XCP/UxVMd4OfR8i7z4fqExKzE4/f xb1p7Vd1vQfppQoycqY4C1Ia6xu+5ofc+dc8k8VgYMPc4JJwEfpLUDCk1kfDH/aGB1D2 BahYrecdCy89Y3G7gOT9089lsHil7PgZaY42WBgfFz1wepYDYSYx3m6uoueJ0Vo2pDqt 4t8Q== 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=GwiP426AVv2kulaD5NRRF0Eu2OfK3kE/mmmrHG8jFuE=; b=Az4KjDGX7GWEceh8M3Egh5Zdo4XFfmU+Zyg/L85bKJTePI6sV+i3A4iPiLuWJWvhdp HN3L+zBDij3zXMa4vq9TcQM+I4Mui4D2DXuZoXe5Z6VeUgGwi367xU11Q3xa1uVQiscS bauhaBjASoJA9Vr2SsQrfx28C5uYSb4Wo5buyVhhxAoP/6JcY5HOhJem3GjGx78ER0hL YF/vJX25j0ShdCvDguG/h29Y3YvbuK47Zeksdh7UCBGyLZKs2PliKjiz3Rh/eDBaEWTM l2ZQRpukua377msAjAc5c2+WYwIIK7QCsj8boFHBdysip0jav1GHSk0Zxc86o47lj7VC ynHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=b7ka8LvB; 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 v3si2014198pgr.191.2019.02.11.06.58.28; Mon, 11 Feb 2019 06:58:44 -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=b7ka8LvB; 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 S2389352AbfBKO50 (ORCPT + 99 others); Mon, 11 Feb 2019 09:57:26 -0500 Received: from mail.kernel.org ([198.145.29.99]:44768 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388835AbfBKO5V (ORCPT ); Mon, 11 Feb 2019 09:57:21 -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 B566A2229E; Mon, 11 Feb 2019 14:57:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1549897041; bh=8OCIOAXaxylSTZqze/oDBmDjrWo091/A3ZJ6mYd/Ncc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=b7ka8LvBIjQUaRnodLvtxwmpCo/hRLVw+6snZ93gIErk+4c5M8mzzeoHDv76nD681 mvLC/WHDh5sblsWNVQ7h3AxuyFmFqvtyEUJpRwvWV3OsZI31xx+OSHgtTmOK/Lwor+ DaMUjjG3oWy8/pCbcbUO6us2RbHVyL/o7gYietgw= 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.14 071/205] pinctrl: sx150x: handle failure case of devm_kstrdup Date: Mon, 11 Feb 2019 15:17:49 +0100 Message-Id: <20190211141833.373147740@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190211141827.214852402@linuxfoundation.org> References: <20190211141827.214852402@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.14-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 70a0228f4e7f..2d0f4f760326 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