Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2248668imm; Mon, 28 May 2018 04:44:59 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqSnFttoNAGLVBm05dCl1ieXNS1HAI9QKkWvadKtxNBR8GvaGVK5xXpK4Ku0HdBnk0yu3w0 X-Received: by 2002:a62:8345:: with SMTP id h66-v6mr13324517pfe.0.1527507899491; Mon, 28 May 2018 04:44:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527507899; cv=none; d=google.com; s=arc-20160816; b=umW5g5LpBnmn42yleRqqvbjVBEedEm5yr9l0nZcrYQiCCreGlxf8clRqD0DB/4g1r/ wdOSsfNm4Z7vRMGDErP4llPVugrF/SF/Boz6ScLQs1KfZ2+DWoLiM0WhzDh0la1c0WFt 2qR99sEwGtERIqStrzxA3exy+dvWM7X3vNh3BmLleg/W+i/X9KxVuseDuoka/2IiWiHb i+c2qGwOpTI0DGIofJeMMcgwAYU/MBMDNPlyjF/lrzj6usRMY4f+ivA1yNbW4ZsfL7KM lJHzLXAd0hoy1hA898R06nSmggo39lunYUA6g3N910PfSv0J23wsEfdeQD+ytfpUbfov CyOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=uNh2FWUi88dL/IpK+eW2oqRz8yc1FqFE9NCvRO2E6rA=; b=ptNYNSHflvU/2mZ4LLUrUI9zeoidRTs1mk7FC6hNoieeAWz34wWPzTLbipIGKXS15g bnIJZRSCwqkj7tJWkaFLjP2phXqfccBSKl+2w/iMWPXLMbJ+z4a0VbrFZF0bvlfXO3g9 J7k5GCd6YdiEhXy9HqQR/yOOp6WvuWqkG1UDHEsYH51Uj6kjKcO2DgiOkUsCC6LjZNz+ cdKQUgmIqn5g7rdxSm9W+6wza+/L4r7f/LKNyalNBzufqW/D3LgFURVFpdlQXJKhPwaI seoGdkC5gBdekKH5oWWum83b0Nh6QcRrJT6veCs4nRUgCMxxc0Dk86B9rLA8ZSoVxGsC hkRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=EuWnmDis; 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 m10-v6si13380013pgv.513.2018.05.28.04.44.44; Mon, 28 May 2018 04:44:59 -0700 (PDT) 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=EuWnmDis; 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 S1424162AbeE1LoD (ORCPT + 99 others); Mon, 28 May 2018 07:44:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:59426 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1423188AbeE1LL0 (ORCPT ); Mon, 28 May 2018 07:11:26 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (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 E66E320845; Mon, 28 May 2018 11:11:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527505885; bh=kdeMQatyG9A1m9Tx0+CIXFR6cJxHb+7jBCWh+RdFaxI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EuWnmDisoBe3qxyjJWrJAJ7m72kn2L+jtb14DY+QgWzwmeukb7jiUSSivudIYp4Yl e3W8JtMg6bakILwy3JPLWc3AwfUkLepYYt9OjYbaMc3yLX6tsA8m+CeCHkgp0hLSaZ H3VXmiDPiJj4HZnYDpckyIygHyj1VraTuRm5AaeQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Christophe JAILLET , Mark Brown , Sasha Levin Subject: [PATCH 4.16 164/272] regulator: gpio: Fix some error handling paths in gpio_regulator_probe() Date: Mon, 28 May 2018 12:03:17 +0200 Message-Id: <20180528100254.594185441@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180528100240.256525891@linuxfoundation.org> References: <20180528100240.256525891@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.16-stable review patch. If anyone has any objections, please let me know. ------------------ From: Christophe Jaillet [ Upstream commit ed8cffda27dea6fd3dafb3ee881c5a786edac9ca ] Re-order error handling code and gotos to avoid leaks in error handling paths. Fixes: 9f946099fe19 ("regulator: gpio: fix parsing of gpio list") Signed-off-by: Christophe JAILLET Signed-off-by: Mark Brown Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/regulator/gpio-regulator.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) --- a/drivers/regulator/gpio-regulator.c +++ b/drivers/regulator/gpio-regulator.c @@ -271,8 +271,7 @@ static int gpio_regulator_probe(struct p drvdata->desc.name = kstrdup(config->supply_name, GFP_KERNEL); if (drvdata->desc.name == NULL) { dev_err(&pdev->dev, "Failed to allocate supply name\n"); - ret = -ENOMEM; - goto err; + return -ENOMEM; } if (config->nr_gpios != 0) { @@ -292,7 +291,7 @@ static int gpio_regulator_probe(struct p dev_err(&pdev->dev, "Could not obtain regulator setting GPIOs: %d\n", ret); - goto err_memstate; + goto err_memgpio; } } @@ -303,7 +302,7 @@ static int gpio_regulator_probe(struct p if (drvdata->states == NULL) { dev_err(&pdev->dev, "Failed to allocate state data\n"); ret = -ENOMEM; - goto err_memgpio; + goto err_stategpio; } drvdata->nr_states = config->nr_states; @@ -324,7 +323,7 @@ static int gpio_regulator_probe(struct p default: dev_err(&pdev->dev, "No regulator type set\n"); ret = -EINVAL; - goto err_memgpio; + goto err_memstate; } /* build initial state from gpio init data. */ @@ -361,22 +360,21 @@ static int gpio_regulator_probe(struct p if (IS_ERR(drvdata->dev)) { ret = PTR_ERR(drvdata->dev); dev_err(&pdev->dev, "Failed to register regulator: %d\n", ret); - goto err_stategpio; + goto err_memstate; } platform_set_drvdata(pdev, drvdata); return 0; -err_stategpio: - gpio_free_array(drvdata->gpios, drvdata->nr_gpios); err_memstate: kfree(drvdata->states); +err_stategpio: + gpio_free_array(drvdata->gpios, drvdata->nr_gpios); err_memgpio: kfree(drvdata->gpios); err_name: kfree(drvdata->desc.name); -err: return ret; }