From patchwork Thu Sep 27 14:51:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 10618121 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E3C7F16B1 for ; Thu, 27 Sep 2018 14:52:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CD2062B9A7 for ; Thu, 27 Sep 2018 14:52:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BF2092B9A2; Thu, 27 Sep 2018 14:52:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3484D2B9A2 for ; Thu, 27 Sep 2018 14:52:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=eO01PSK8umLaMBHMb/CxMwuYTO8L1tCA7hsK/OhvQ6I=; b=AOUY3W0ngsJR77wKEiAiz4uSAn Ptf3sO3ByasTnVTykibWkBmZsbBAjiN6hKc4nLSU7dXiOcyXTOkPuZUJUxpj+7H7H2jiStC63yu80 LzVooNuho4iPaIOQjhvhksSYG+U9CbzXh223haWDYPbyjMdCw9CpuF49T566pad9upUAhzxvjBdNP 5OY46M9OJF85XmXSW5LTFG/8zNzgZjo8uK+2R2L5K9icy2SJ57EEA3Z/YSTG9FmH1rXt9SnUUG2+G UIuWsgVq577rHMpjsEcEAkyEGkb91ATCX6nOivr1vea3palYOBd9hd8fmNfUv7I2NrzWtnUtLo4rP qBnFYPJQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1g5Xem-0006aX-0u; Thu, 27 Sep 2018 14:52:44 +0000 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1g5XeQ-0006Yu-5s for linux-arm-kernel@lists.infradead.org; Thu, 27 Sep 2018 14:52:23 +0000 Received: by mail-wr1-x444.google.com with SMTP id y8-v6so2955279wrh.7 for ; Thu, 27 Sep 2018 07:51:51 -0700 (PDT) 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=LqqPzQb5rQKmQSK7Lm4nztokxHt2+EweWXTUlu6+fsA=; b=G9Q61Zw7AvfgvRicmMgoe0AStVH40izkd7SM/8qLl8TRaLFgDpRHnjAPlSV1DMdCKg lSJ4gx/mqrNoVFTQ+unVTgrjq1rf0j1F6byP6YE0jMN/w8ngEny4i40cJT+GSsO3snO5 PPx/gZucA4Du4MaqnS8RLiF/t2AgbcyPHIMD8= 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=LqqPzQb5rQKmQSK7Lm4nztokxHt2+EweWXTUlu6+fsA=; b=rSTL7NQ08zi3LdFr78jyEF0YRjaqO7jMpwxT+3EPkbLTrieUMyP9VC30UoFxlc9d0u k3yqnkyv+Oj0jy36fGIw1D7r0oyBITfOjVB/2hCpvzoQ5LldKfkIbbZYjXrzBS+xL5x4 Zcjf2ifposlRQUzmjF1Y4sEeotLb40n9dxs3HJWHFZjhoReSuuIK7YXmqGkMpKobED+3 UZL4TIr35aYgu+i6V1wdoHTLSzvxtdid1NzKKsOM6aW9DwEstRb+sQaMY9Z9Pft1dZLf BCL7eBaYnykpBWbhHSw66dNmjeL0u+m7IImQrCUkhh0yituohVADOjWA+1cnhYS0/Q0M 8r6Q== X-Gm-Message-State: ABuFfojrOOiXhHJQL8iayvbSE7+YNa+huZg4lQ+UipZ233MK3+wG/sRS VgoigJLv+MbtAT+x5hNLdscMHQ== X-Google-Smtp-Source: ACcGV61nkJsXQrtq+1tFBSBPJQu8hmPkaDLT7xWt8w1vX1rgs4BCKfblKTcOYXCIrpRWk+v8yQnFog== X-Received: by 2002:adf:ef0a:: with SMTP id e10-v6mr948078wro.292.1538059909962; Thu, 27 Sep 2018 07:51:49 -0700 (PDT) Received: from localhost.localdomain (30.216.136.77.rev.sfr.net. [77.136.216.30]) by smtp.gmail.com with ESMTPSA id p11-v6sm2398023wrd.74.2018.09.27.07.51.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 27 Sep 2018 07:51:49 -0700 (PDT) From: Daniel Lezcano To: tglx@linutronix.de Subject: [PATCH] clocksource/drivers/timer-atmel-pit: Properly handle error cases Date: Thu, 27 Sep 2018 16:51:35 +0200 Message-Id: <1538059895-10049-1-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180927_075222_220956_A336037E X-CRM114-Status: GOOD ( 14.01 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alexandre Belloni , "open list:CLOCKSOURCE, CLOCKEVENT DRIVERS" , stable@vger.kernel.org, "moderated list:ARM/Microchip AT91 SoC support" , mingo@kernel.org, Dan Carpenter MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Alexandre Belloni The smatch utility reports a possible leak: smatch warnings: drivers/clocksource/timer-atmel-pit.c:183 at91sam926x_pit_dt_init() warn: possible memory leak of 'data' Ensure data is freed before exiting with an error. Reported-by: Dan Carpenter Signed-off-by: Alexandre Belloni Cc: stable@vger.kernel.org Signed-off-by: Daniel Lezcano --- drivers/clocksource/timer-atmel-pit.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/drivers/clocksource/timer-atmel-pit.c b/drivers/clocksource/timer-atmel-pit.c index ec8a437..2fab18f 100644 --- a/drivers/clocksource/timer-atmel-pit.c +++ b/drivers/clocksource/timer-atmel-pit.c @@ -180,26 +180,29 @@ static int __init at91sam926x_pit_dt_init(struct device_node *node) data->base = of_iomap(node, 0); if (!data->base) { pr_err("Could not map PIT address\n"); - return -ENXIO; + ret = -ENXIO; + goto exit; } data->mck = of_clk_get(node, 0); if (IS_ERR(data->mck)) { pr_err("Unable to get mck clk\n"); - return PTR_ERR(data->mck); + ret = PTR_ERR(data->mck); + goto exit; } ret = clk_prepare_enable(data->mck); if (ret) { pr_err("Unable to enable mck\n"); - return ret; + goto exit; } /* Get the interrupts property */ data->irq = irq_of_parse_and_map(node, 0); if (!data->irq) { pr_err("Unable to get IRQ from DT\n"); - return -EINVAL; + ret = -EINVAL; + goto exit; } /* @@ -227,7 +230,7 @@ static int __init at91sam926x_pit_dt_init(struct device_node *node) ret = clocksource_register_hz(&data->clksrc, pit_rate); if (ret) { pr_err("Failed to register clocksource\n"); - return ret; + goto exit; } /* Set up irq handler */ @@ -236,7 +239,8 @@ static int __init at91sam926x_pit_dt_init(struct device_node *node) "at91_tick", data); if (ret) { pr_err("Unable to setup IRQ\n"); - return ret; + clocksource_unregister(&data->clksrc); + goto exit; } /* Set up and register clockevents */ @@ -254,6 +258,10 @@ static int __init at91sam926x_pit_dt_init(struct device_node *node) clockevents_register_device(&data->clkevt); return 0; + +exit: + kfree(data); + return ret; } TIMER_OF_DECLARE(at91sam926x_pit, "atmel,at91sam9260-pit", at91sam926x_pit_dt_init);