Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754741AbbKRDWP (ORCPT ); Tue, 17 Nov 2015 22:22:15 -0500 Received: from mailgw01.mediatek.com ([210.61.82.183]:56239 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1753324AbbKRDWO (ORCPT ); Tue, 17 Nov 2015 22:22:14 -0500 X-Listener-Flag: 11101 Message-ID: <1447816929.14382.0.camel@mtksdaap41> Subject: Re: [PATCH] pinctrl: mediatek: fix a memleak when do dt maps. From: Yingjoe Chen To: Hongzhou Yang CC: Linus Walleij , Matthias Brugger , Axel Lin , Maoguang Meng , Colin Ian King , , , , , , Sascha Hauer , Date: Wed, 18 Nov 2015 11:22:09 +0800 In-Reply-To: <1447799622-3340-1-git-send-email-hongzhou.yang@mediatek.com> References: <1447799622-3340-1-git-send-email-hongzhou.yang@mediatek.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.2.3-0ubuntu6 Content-Transfer-Encoding: 7bit MIME-Version: 1.0 X-MTK: N Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3154 Lines: 110 On Tue, 2015-11-17 at 14:33 -0800, Hongzhou Yang wrote: > configs will kmemdup to dup_configs in pictrl util function. > So configs need to be freed. > > Signed-off-by: Hongzhou Yang > Reviewed-by: Daniel Kurtz > Reviewed-by: Matthias Brugger > --- > Fix a memleak issue. > According to Yingjoe's comment, add return checek for pinconf_generic_parse_dt_config. Reviewed-by: Yingjoe Chen Joe.C > drivers/pinctrl/mediatek/pinctrl-mtk-common.c | 27 ++++++++++++++++--------- > 1 file changed, 17 insertions(+), 10 deletions(-) > > diff --git a/drivers/pinctrl/mediatek/pinctrl-mtk-common.c b/drivers/pinctrl/mediatek/pinctrl-mtk-common.c > index 5c71727..8db7cdf 100644 > --- a/drivers/pinctrl/mediatek/pinctrl-mtk-common.c > +++ b/drivers/pinctrl/mediatek/pinctrl-mtk-common.c > @@ -509,6 +509,9 @@ static int mtk_pctrl_dt_subnode_to_map(struct pinctrl_dev *pctldev, > > err = pinconf_generic_parse_dt_config(node, pctldev, &configs, > &num_configs); > + if (err) > + return err; > + > if (num_configs) > has_config = 1; > > @@ -520,21 +523,23 @@ static int mtk_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 < 0) > - goto fail; > + goto exit; > > for (i = 0; i < num_pins; i++) { > err = of_property_read_u32_index(node, "pinmux", > i, &pinfunc); > if (err) > - goto fail; > + goto exit; > > pin = MTK_GET_PIN_NO(pinfunc); > func = MTK_GET_PIN_FUNC(pinfunc); > @@ -543,20 +548,21 @@ static int mtk_pctrl_dt_subnode_to_map(struct pinctrl_dev *pctldev, > func >= ARRAY_SIZE(mtk_gpio_functions)) { > dev_err(pctl->dev, "invalid pins value.\n"); > err = -EINVAL; > - goto fail; > + goto exit; > } > > grp = mtk_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 = mtk_pctrl_dt_node_to_map_func(pctl, pin, func, grp, map, > reserved_maps, num_maps); > if (err < 0) > - goto fail; > + goto exit; > > if (has_config) { > err = pinctrl_utils_add_map_configs(pctldev, map, > @@ -564,13 +570,14 @@ static int mtk_pctrl_dt_subnode_to_map(struct pinctrl_dev *pctldev, > configs, num_configs, > PIN_MAP_TYPE_CONFIGS_GROUP); > if (err < 0) > - goto fail; > + goto exit; > } > } > > - return 0; > + err = 0; > > -fail: > +exit: > + kfree(configs); > return err; > } > -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/