Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1614437ybv; Fri, 21 Feb 2020 00:18:57 -0800 (PST) X-Google-Smtp-Source: APXvYqzEKy0xzrfH1TNP/LwCt8rdJ4OYzYKYG8yxPf98nulvOfXE6wXQUcUDzbWLBKLQnaTlZ0u6 X-Received: by 2002:a9d:12a8:: with SMTP id g37mr27318819otg.261.1582273136888; Fri, 21 Feb 2020 00:18:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582273136; cv=none; d=google.com; s=arc-20160816; b=xlp+K/yBg2UEB+Uy4rxEgjbLyopUB+2JanHcaODHjrhhZfihdqHPNCdAnjxTTUttUY yzLCDc3F91DzVyMwmYQjv0yNYjnqNRMktrHAKyFyiE+QL+wxD7vpTxMFJ1gRstBYf3mh qysy/s3tB5rTdJz33JZx07hQnWCh7xQIU+vW6F7NlV1QkJX7UX4kOYJPANqkcWwFY200 7StilUauXuB1tRC176SDL864kM0/4LeMLwDLXh1cEeinGiXgZsOaNjOMddiO9wPF4Og3 +/HwH1mZkJvYmRNtEGKZQI8U59K74efZ90PiZNTyQZ3wVAW+K8SQpGSv+N3QEV+zFQ+S Qjtw== 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=4zAskSBErTPhN7h4MyCHvYypYLR9wJLFYEhclB8J0FU=; b=FmHLrQ/ckf9xNzPIP9Euyhn696sKG/x+bF+dmLvrgpX57WPLXiYpbn0E5XJXcLXYAe Ec2oE+hc3Rnv0sPkLGNmNs2SljqL3MNbFc6MOj2dO+ZuUssrUOQW4g41ePtX6NBBp7aU lOVTCWlfQZaFrTVGHQfP1n+HNef+pB0wI81QUbhDhnJ1c1m/S3f7/L53pXNuReTHENNo r3k2jBOg0HChvGz1McBZrMebpTu8R3N+E2bLpYh2A9wwy321mcuBYVjRhhuz/HyQLuBf xDwElVEMD+bxzyoHTbd1cXA6fRp1y9sqNq9QsygnC68BSK2kqa0aNhv+yRnd3enLP6UR yndQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="IxZN/l1D"; 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 d5si444301oij.139.2020.02.21.00.18.44; Fri, 21 Feb 2020 00:18:56 -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="IxZN/l1D"; 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 S2387773AbgBUISE (ORCPT + 99 others); Fri, 21 Feb 2020 03:18:04 -0500 Received: from mail.kernel.org ([198.145.29.99]:55706 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387739AbgBUISA (ORCPT ); Fri, 21 Feb 2020 03:18:00 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.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 2F0292468A; Fri, 21 Feb 2020 08:17:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582273079; bh=Uy+uU0lTHozrOu7Zp3nMGr4SJBMZzKyAgAl9QYPUfTE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IxZN/l1Dqgwp/n9TxiSKBbMveJKURM6EdUEiY9vQQqqpeRmm8JwlEkD2tqLHAcds5 gn1mD+ywoUzXxhrsyewWPitenYsgvVwp6/PsChOUY+rE/yQvVHieUk9+MHEIy4TaeX SgwwJVxpXTzczQ4iiEgJ9g1MLxAyUJZ4rNwZAxI4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Thierry Reding , Sasha Levin Subject: [PATCH 4.19 038/191] pwm: omap-dmtimer: Simplify error handling Date: Fri, 21 Feb 2020 08:40:11 +0100 Message-Id: <20200221072256.150152720@linuxfoundation.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200221072250.732482588@linuxfoundation.org> References: <20200221072250.732482588@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Uwe Kleine-König [ Upstream commit c4cf7aa57eb83b108d2d9c6c37c143388fee2a4d ] Instead of doing error handling in the middle of ->probe(), move error handling and freeing the reference to timer to the end. This fixes a resource leak as dm_timer wasn't freed when allocating *omap failed. Implementation note: The put: label was never reached without a goto and ret being unequal to 0, so the removed return statement is fine. Fixes: 6604c6556db9 ("pwm: Add PWM driver for OMAP using dual-mode timers") Signed-off-by: Uwe Kleine-König Signed-off-by: Thierry Reding Signed-off-by: Sasha Levin --- drivers/pwm/pwm-omap-dmtimer.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/drivers/pwm/pwm-omap-dmtimer.c b/drivers/pwm/pwm-omap-dmtimer.c index f45798679e3c0..2d585c101d52e 100644 --- a/drivers/pwm/pwm-omap-dmtimer.c +++ b/drivers/pwm/pwm-omap-dmtimer.c @@ -301,15 +301,10 @@ static int pwm_omap_dmtimer_probe(struct platform_device *pdev) goto put; } -put: - of_node_put(timer); - if (ret < 0) - return ret; - omap = devm_kzalloc(&pdev->dev, sizeof(*omap), GFP_KERNEL); if (!omap) { - pdata->free(dm_timer); - return -ENOMEM; + ret = -ENOMEM; + goto err_alloc_omap; } omap->pdata = pdata; @@ -342,13 +337,28 @@ put: ret = pwmchip_add(&omap->chip); if (ret < 0) { dev_err(&pdev->dev, "failed to register PWM\n"); - omap->pdata->free(omap->dm_timer); - return ret; + goto err_pwmchip_add; } + of_node_put(timer); + platform_set_drvdata(pdev, omap); return 0; + +err_pwmchip_add: + + /* + * *omap is allocated using devm_kzalloc, + * so no free necessary here + */ +err_alloc_omap: + + pdata->free(dm_timer); +put: + of_node_put(timer); + + return ret; } static int pwm_omap_dmtimer_remove(struct platform_device *pdev) -- 2.20.1