From patchwork Thu Nov 28 16:49:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 180453 Delivered-To: patch@linaro.org Received: by 2002:a92:3001:0:0:0:0:0 with SMTP id x1csp373812ile; Thu, 28 Nov 2019 08:50:45 -0800 (PST) X-Google-Smtp-Source: APXvYqzPjCvatrAGoBIGqlLs6OIr5iU/IQ/SHtia8vgIThEFyNhuGG8ywVFqj8uZmi4Xhu17gDLJ X-Received: by 2002:aa7:cac7:: with SMTP id l7mr39714036edt.196.1574959845778; Thu, 28 Nov 2019 08:50:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574959845; cv=none; d=google.com; s=arc-20160816; b=Sj9Hg1qInPOvXCl0yBc5uXUl6D50rTTtN40NZCfJyOP3PQ8QO8JfRs7F8T8ZHAdV10 ANwvUiAPYPIVm5D4sN2mzMue+bBBXvTkjw7T/hXg5eJ9k0XfaZDbU2GWSr/FSu0szrtG duS0ve2jIF/PBPBjV/OITTAdmPTc7oWYe4Tmr5V+3r7S7id50CgFASzULXhCp5ZFAyNa hWUMvrgFqVfh7ld+4iu89W3uj+h2U4X+5cVW8v9usJjX9TG1ic8KxTlHZ+GLFenQevEh YQ1zi8o9HU8iC0JzBFeT8cRFAGS8+zabkIbTKDmsPxkQnI+pMGgxVJQsvkmxgrLZqXZS 3xyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=nEtPBscm61+nPEVWvbJjdtfKlHF1+Tw29QLFNNlqSXc=; b=QO3aJcvQrvg1QXAoNVhZdsu59tvTZqXlwL8LshaZPesKq1YwMtY3FGPcxnHRgqSMeK 72tPL5KM1OHszdi0b8cPbpqX/M/rueydC4W6vw3w5lTreBXkG/h2I8bEyoqk+qWoaMip iib7ABX3EdJaw96KQvjdNm+8qMJeoq5ILVd1Wzp0dJ1U5w46aGwKWBdAkJduQi3oM4cN wXmLRTmyabZpVvcsfQK3BWu9R+fWceUIsI8+l0WFYJT+icvqgY30gI55Zlo1uYoyBBwP WGbts/4OdwQGN3RVrIGz6BEpXB9l1rvh1D5JHp+plhO+3OeXEs+J7FvMqgwStuCFL6V6 99Dg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Jq5l6POX; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id dc21si12388590ejb.101.2019.11.28.08.50.45; Thu, 28 Nov 2019 08:50:45 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of stable-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=@linaro.org header.s=google header.b=Jq5l6POX; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727104AbfK1Qun (ORCPT + 15 others); Thu, 28 Nov 2019 11:50:43 -0500 Received: from mail-pg1-f195.google.com ([209.85.215.195]:46813 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727079AbfK1QuR (ORCPT ); Thu, 28 Nov 2019 11:50:17 -0500 Received: by mail-pg1-f195.google.com with SMTP id k1so4771167pga.13 for ; Thu, 28 Nov 2019 08:50:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=nEtPBscm61+nPEVWvbJjdtfKlHF1+Tw29QLFNNlqSXc=; b=Jq5l6POXhKBLihg38Usaui6t0nqV5sQvbWbI6rSgNIYk6n8WGDMMVkP1LG1/2x4qCG UCyeQoB/AbodwEeK9haGNGeVGO8BzgnQuR/VI/1+k7mg0XhxfCHBQ2Jew9pOj0wEvAwy 2WnWtwe73c5FU0NnojZiurA8804vygmxVRyse2+b5ZsZ7WpuLU2PEcTZyZGnx12XnU6r Cmmwe5RWxdl12kf8dT8BkmTrdBhlYSRqHUThpLcxcOwXlRELSCzdl/hd9EzIozpCZQzy eRYJ+rCcOw9gzunEYkOpG2M7cv3cPrz3S8v7jfLhGslUmsAe6+SS9DEnP4dTHmNwFXTb sW7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=nEtPBscm61+nPEVWvbJjdtfKlHF1+Tw29QLFNNlqSXc=; b=B6rCxL3ng+mCqGXvz66depga2RiKIKN5mdWSEVMHZg6xWOtT0smVMMq6pDyCEpmmwr loHTvKCFe8Ik4vy2ddbIWzo3la9eVjeFF5ECoO5DPbqMGLMz1c3HTM2wCt6QUA8Xcp1Z L5T5MMQZ1JbSKPR+eMRmwLGb7WocaVwiN9AqJZxvTgRTke6z6Wt/0PGuLjfQCRih0QSu PQe/rIY+8EjhAuxoAlsM8v9lxFqI4xSYz30JotpIhSA4FtD9SOAx8kH0xuAKZydMl8Up p7ZUidRLyUrzb7uniAhbTTjEMP2wlkovXFietxyMnpKv4R6+wqz4TXu7Ksz9saLxU+LN rEFA== X-Gm-Message-State: APjAAAX0pXcaJfg5lLQADBiZhwSWsuSodeZA1WIuXCX1CvQngerH/1BQ TqLK6JnsIxb+EnNCdmXlA78/tdE6Tgs= X-Received: by 2002:a63:5017:: with SMTP id e23mr12224287pgb.32.1574959815274; Thu, 28 Nov 2019 08:50:15 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id a15sm2450343pfh.169.2019.11.28.08.50.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Nov 2019 08:50:14 -0800 (PST) From: Mathieu Poirier To: stable@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [stable 4.19][PATCH 12/17] pinctrl: stm32: fix memory leak issue Date: Thu, 28 Nov 2019 09:49:57 -0700 Message-Id: <20191128165002.6234-13-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191128165002.6234-1-mathieu.poirier@linaro.org> References: <20191128165002.6234-1-mathieu.poirier@linaro.org> Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Alexandre Torgue commit cd8c9b5a49576bf28990237715bc2cb2210ac80a upstream configs is allocated by pinconf_generic_parse_dt_config(), pinctrl_utils_add_map_configs() duplicates configs so it can and has to be freed to prevent memory leaks. Signed-off-by: Alexandre Torgue Signed-off-by: Linus Walleij Cc: stable # 4.19 Signed-off-by: Mathieu Poirier --- drivers/pinctrl/stm32/pinctrl-stm32.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) -- 2.17.1 diff --git a/drivers/pinctrl/stm32/pinctrl-stm32.c b/drivers/pinctrl/stm32/pinctrl-stm32.c index a9bec6e6fdd1..14dfbbd6c1c3 100644 --- a/drivers/pinctrl/stm32/pinctrl-stm32.c +++ b/drivers/pinctrl/stm32/pinctrl-stm32.c @@ -410,7 +410,7 @@ static int stm32_pctrl_dt_subnode_to_map(struct pinctrl_dev *pctldev, unsigned int num_configs; bool has_config = 0; unsigned reserve = 0; - int num_pins, num_funcs, maps_per_pin, i, err; + int num_pins, num_funcs, maps_per_pin, i, err = 0; pctl = pinctrl_dev_get_drvdata(pctldev); @@ -437,41 +437,45 @@ static int stm32_pctrl_dt_subnode_to_map(struct pinctrl_dev *pctldev, if (has_config && num_pins >= 1) maps_per_pin++; - if (!num_pins || !maps_per_pin) - return -EINVAL; + if (!num_pins || !maps_per_pin) { + err = -EINVAL; + goto exit; + } reserve = num_pins * maps_per_pin; err = pinctrl_utils_reserve_map(pctldev, map, reserved_maps, num_maps, reserve); if (err) - return err; + goto exit; for (i = 0; i < num_pins; i++) { err = of_property_read_u32_index(node, "pinmux", i, &pinfunc); if (err) - return err; + goto exit; pin = STM32_GET_PIN_NO(pinfunc); func = STM32_GET_PIN_FUNC(pinfunc); if (!stm32_pctrl_is_function_valid(pctl, pin, func)) { dev_err(pctl->dev, "invalid function.\n"); - return -EINVAL; + err = -EINVAL; + goto exit; } grp = stm32_pctrl_find_group_by_pin(pctl, pin); if (!grp) { dev_err(pctl->dev, "unable to match pin %d to group\n", pin); - return -EINVAL; + err = -EINVAL; + goto exit; } err = stm32_pctrl_dt_node_to_map_func(pctl, pin, func, grp, map, reserved_maps, num_maps); if (err) - return err; + goto exit; if (has_config) { err = pinctrl_utils_add_map_configs(pctldev, map, @@ -479,11 +483,13 @@ static int stm32_pctrl_dt_subnode_to_map(struct pinctrl_dev *pctldev, configs, num_configs, PIN_MAP_TYPE_CONFIGS_GROUP); if (err) - return err; + goto exit; } } - return 0; +exit: + kfree(configs); + return err; } static int stm32_pctrl_dt_node_to_map(struct pinctrl_dev *pctldev,