Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3705844imu; Mon, 28 Jan 2019 09:21:01 -0800 (PST) X-Google-Smtp-Source: ALg8bN5TRPIBj/k3EwShnBrW65I7rQ+ZuxAicaVbXfB/3vg4kqVryoO6zA0ltH/sSr2haxrxbZKr X-Received: by 2002:a62:3811:: with SMTP id f17mr23115548pfa.206.1548696061060; Mon, 28 Jan 2019 09:21:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548696061; cv=none; d=google.com; s=arc-20160816; b=baVyAE54ZKg8HUkrkh0yAYwsKg0Je4RoBzdS5W3tGdlOr6lulIpEF2yeMoIm99m7Ry n82qGX1BKUnOb3hVZ6ajVzaSzL1lNTOrH1OCTwd5PJ9LylHnFFe+Ksct2h8GrUSqaP8M kU+6wZ1hRzutQh368t7Y+YMtVCKvYLSyksDvVgnWyh//vKrxyYo5t7hlY03Jpd5R24ND ykG1h1EMGKA/iPdaejtpallp5GlX8smcnxnTAA1L+clDdWVDyMkyGYOl2DT/MTrGH9de +fkAtueNg7Dp5BXKPpxLr2jWvVhnaIeq9Xv+E+9v4K7s0TAcH37CQYat7IWsyy99rrXX f5Mw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=vIn0sLp+cLALE54dsrJPm8KIj21c2ErpPntD8YAgJc0=; b=fSzm4IZMyerH90/W11aMlk9C68AoMXPeW6kXQIIl5u50pLvKXDbnPsbr2bda0EYwm/ Qhufhkc0RkQoLL1VWOU5SWLQXK5lKTn6QtfW3qR2ArMneLl4TboIDTnjFOm4Lz0pJSLC xZvT1vEBuslzV9yPRLAc1Y45Dnt+/qfA7mTaHrDkLIonxuw1OV064WYYK8qWbgwiqnWT zNA0V3maDaZbIIpe1xCMSMJx1IfBp8sER9WWD4Nrnu6azlGIbwIoy5pIFOQSbenwTQIt zwRfsLdQh6OYkSoHVs8AEi6SX3DAv3k2NUBAM5Ro4aPkxkEVfT4H/eozz2d9DKWE2Wgm amOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="JhaCrVw/"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x6si22912717pgh.363.2019.01.28.09.20.46; Mon, 28 Jan 2019 09:21:01 -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="JhaCrVw/"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732039AbfA1RS7 (ORCPT + 99 others); Mon, 28 Jan 2019 12:18:59 -0500 Received: from mail.kernel.org ([198.145.29.99]:51136 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728490AbfA1QFA (ORCPT ); Mon, 28 Jan 2019 11:05:00 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id ADCD521738; Mon, 28 Jan 2019 16:04:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548691499; bh=Uwr4dWGAsV4+A0M6VpMaibSMQ0CMvPDgdj4xvIvbNFA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JhaCrVw/3ZlsTkvKnT4Re493PoJleCnyZNnrh+EBYYDWijprYRFNq8mhLQACzrHkL hgxU9NoEazQPMwn67fX/cntcJgcqkeUReEkSBzzcYW6rkqfRN7Cwv7XLHLFiiYddQx T3CDH/DeHVDQsjzWGYxIFMaXuaqvWD5zIt49xhYE= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Nicholas Mc Guire , Linus Walleij , Sasha Levin , linux-gpio@vger.kernel.org Subject: [PATCH AUTOSEL 4.19 117/258] pinctrl: sx150x: handle failure case of devm_kstrdup Date: Mon, 28 Jan 2019 10:57:03 -0500 Message-Id: <20190128155924.51521-117-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190128155924.51521-1-sashal@kernel.org> References: <20190128155924.51521-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Nicholas Mc Guire [ 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