From patchwork Fri Nov 15 22:33:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 179529 Delivered-To: patch@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp13126492ilf; Fri, 15 Nov 2019 14:34:15 -0800 (PST) X-Google-Smtp-Source: APXvYqzZnhg4GP7LHfYqxMfU6RYWPp/LcvHhfdz0r52v9bJCbLDzmTj82wxA10irISt5Zfd1DX4Z X-Received: by 2002:a17:906:938c:: with SMTP id l12mr4382538ejx.135.1573857255856; Fri, 15 Nov 2019 14:34:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573857255; cv=none; d=google.com; s=arc-20160816; b=ICFe8XEVTIVOEU2xBE2fbvXKq24E79kCf49qzRMJKTS6op1Lnxm0tFaHMTZ8Ia6ia+ EvH97ejJpdmFb1If/t0Y7w0yVysskH9UXKGOliUZBN21aNr3lyn9/4a+KW5E/IQAGQbf +5HWZhybnKkjAJMjJiH4grmyK86iCP2cL1DvjhofVeQQDwwUlc+fyt6zP18qa+I9gSjo N90menN6AwlvfJw9Jh+Z2AeArpXFqjSLKg5JCv1V/nDDKbZ0jLmLmHPNEIOlherz4OHc lt3Dt9PC0BE5PoDTgIYEB2t6wzZQFfCAKMcRLdii6CUw6s4NkDC0NmmRObmMI7DpFhF4 bZLA== 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=RCAvV+63fHypoFXOnsyRxH4xHTzRyP2HC/taWojKmLE=; b=pzcZEnFcT7TZPDsgGiscXx37J4nIufFDzIrYNt4PofLM7Vd5iB4APPrIUeEPdHH2kB /dewBwQRxBDE5d1ZGp2AQoNxfI/IjUB1y3tJwRx51dlX/WbQ5O0eUpvl6eTY/n7h+CF4 v0OhrSdq/61QMK8NKMEwH6VlwUx2bQ1ymuOueeuO/d55VmeiKLdPYLqRsUbmqUhWy4GI gomtYLoWBocaFfNDdrYfykZL7L7+b1IKQiEfLTmLLiqa7B3hjoxzHYYvDTmI8d5LDKED KSQtBxxpyvTgjIzDf0EegBMqxOulsaGLvLuWwzpjc3aMg8LO67dpp0fKiFtbu4fqW1Xr R3xQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cMafIXdS; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id gq14si6458339ejb.190.2019.11.15.14.34.15; Fri, 15 Nov 2019 14:34:15 -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=@linaro.org header.s=google header.b=cMafIXdS; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727354AbfKOWeL (ORCPT + 26 others); Fri, 15 Nov 2019 17:34:11 -0500 Received: from mail-pf1-f195.google.com ([209.85.210.195]:43213 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727348AbfKOWeK (ORCPT ); Fri, 15 Nov 2019 17:34:10 -0500 Received: by mail-pf1-f195.google.com with SMTP id 3so7322706pfb.10 for ; Fri, 15 Nov 2019 14:34:09 -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=RCAvV+63fHypoFXOnsyRxH4xHTzRyP2HC/taWojKmLE=; b=cMafIXdS6g1uj9flwmN+t7PFzSGyqKH/b0cq+G1THxzoFk+UYaUMhkK+sCXvoR+FRO T/JwOcWSRAaDWyQpMyfm6t8Zb6xoOLE3pEo2VEaHnfKiwlYUUFO3RDSGQagkVZ+iwFjP wmmcuLiR+iKDMK2bzVS9A3BLyV6YTliwZCITCbOSSg1eQn5ZOIEhEWr/kh5vqAomZ4ZQ cgRA8eugzOEYPUvEM8fNYj8/Yg/ARhoLFq31/vgr7hZNUdFh2ItkshREq+pM+lKJazBg bqbGPI4XSYbM8QdMhxpjnWpQ3YJz8+9wR7dpzxgu9Pvr/+j05k3lwfNTVW/WugA3V86p o+NA== 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=RCAvV+63fHypoFXOnsyRxH4xHTzRyP2HC/taWojKmLE=; b=XBXr206p1i/T7DJ7baL0364i/JRv3FQikyv8fKTapZDbr6WjvURTQS2Xqc1vWC7qrJ dXRm22pvrHmVv47MZCzTkNo3p0Db/deJ4CTg4+Uv/TMptPh+GRqtgWaGye35jKdou971 EIyfiGOY0G8emqWAi/Rg1Rh5XgBGnqc49GVnmC7cFpKsd5yITAnKDaWCp5Az9AqC0gPd d/hb4c/VdkiadSSMhsdy/XYO115OucslS1WyNIr2Q8zWQ38tw8yBV5Ofb8TdpnU0Ggbt r5VOdBbayObPgO5fhC8ZCBMnA0hUX7LD61b/Q0yE1wgOXVFddDC87z8+eQMGptI2KF7S +jkw== X-Gm-Message-State: APjAAAVb/au6v0wFUQ+Td7AKXxjeLgqPtekB2Egohzi58eIt/RBNQkxM +Si+Zlpo+BE1dfq/FkLC/TdW1Q== X-Received: by 2002:a62:1914:: with SMTP id 20mr19374168pfz.68.1573857249524; Fri, 15 Nov 2019 14:34:09 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id m15sm11699724pfh.19.2019.11.15.14.34.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2019 14:34:09 -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 14/20] pinctrl: stm32: fix memory leak issue Date: Fri, 15 Nov 2019 15:33:50 -0700 Message-Id: <20191115223356.27675-14-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191115223356.27675-1-mathieu.poirier@linaro.org> References: <20191115223356.27675-1-mathieu.poirier@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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,