Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp2739222imj; Mon, 11 Feb 2019 07:46:30 -0800 (PST) X-Google-Smtp-Source: AHgI3IZYjYhUcANrUPXh5dWoBIXC8elB6n0Ws+6NS7eyLETlxlzBJZT1MksPsHuFNQI+hB/AeZsy X-Received: by 2002:a63:2e06:: with SMTP id u6mr9719885pgu.71.1549899990834; Mon, 11 Feb 2019 07:46:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549899990; cv=none; d=google.com; s=arc-20160816; b=BNjSUzvbqYlz0HvOTYSx/g9USUl1MCxBD1Zi6hKuWMfYGlabiA+TuNXaAkZfa4W2vs 3NY+zOts9pwaDtC6ejB7NG6P6GS7EEVPYZq/pQW/D7XAHvlWz6iVPxxZXgk+pGsXa2kx QwfPfcOFpOusYsT669o4R3JdhHcyTQ1s+F0+6pWR3K7gVLHDYsSyQE3c6uMGPKqTn60s 3atiFawG5uG/vIqL7KPLtZLurIGJRyrK2OBmm1IkDyhr2YWLk3Mej8SMZDinYaFtvf6J Z1+KrdcIfdjYd2fNMQW5GWnXKyTqmxJ6FSYWRHj8bw+4Abuxo4XeITL88Ad4uDB4B8yR kdGA== 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=1d01vhQAZlt5xe/MLpjrfsIhV8EHOn7S7JpCNGElNds=; b=Xk06F3F8DswNYyvSGE9nIW/3R0Hn038arU0ki8E6lIg3VKqXMS98FMRd9bppe/xGpa 3Otg/txz4y8H836l4sauUQWGEfwgV44qnJy4RctDPOCjKKGXdrkF/ANXLcoezHUpW9vq a99O4nWW7sxI3gQFvcuvAaqFZveSMxHdwrCzWkWEMqqFfoT7eW9//OmJxkNV4XPLSASj vbE3H19i0EO5yv21MW0LIEsrwG6g4KWFUI+UEqu9m6ZBJFzu7x9ZvFgEbEAR/6bzyM9Y NnWNp5gg2E5vJZpjcRSPY09c+5EfT0QD5XvjNThB+ARF+1k4yKGnIki91FCf1vNw1TQ7 laZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=NvKfHkxt; 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 v11si3143327pfj.155.2019.02.11.07.46.14; Mon, 11 Feb 2019 07:46:30 -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=NvKfHkxt; 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 S1732675AbfBKOni (ORCPT + 99 others); Mon, 11 Feb 2019 09:43:38 -0500 Received: from mail.kernel.org ([198.145.29.99]:55826 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732660AbfBKOnf (ORCPT ); Mon, 11 Feb 2019 09:43:35 -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 48991222A1; Mon, 11 Feb 2019 14:43:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1549896214; bh=53AVhr0KbqVERHpyMvqp/5Osu9uTpmQ7cqoL0feonXw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NvKfHkxtiOROqCvFBzvg5LZGFf1d25BCKRgMReA8tPkjttHfOW/5uFUoVPojjNQr0 VEdha5juAvvpne0f3c5Z+yqCrpCWCNTV19JCCN3s765m5y1yPxJJR7DhDxKfmUjP23 jou2eZNPp9IuiZZ8Od4Oh1H/qMSKGSThamuLgYIY= 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.19 110/313] pinctrl: sx150x: handle failure case of devm_kstrdup Date: Mon, 11 Feb 2019 15:16:30 +0100 Message-Id: <20190211141901.219045294@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190211141852.749630980@linuxfoundation.org> References: <20190211141852.749630980@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.19-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