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: 147724 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp2107670lji; Thu, 27 Sep 2018 07:51:54 -0700 (PDT) X-Google-Smtp-Source: ACcGV60gb0bqErWEBdm+i5dcY/4oXipPJvhmPmOoSGhdL2qydX5vdbfJPRRyUfuDZ2U7B1tZPEax X-Received: by 2002:a17:902:b212:: with SMTP id t18-v6mr11666968plr.136.1538059914186; Thu, 27 Sep 2018 07:51:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538059914; cv=none; d=google.com; s=arc-20160816; b=B/zaeKeER6mrl6U7ulao78268ZO8LW8vMMbzU2O/DxRUw6Zce5Gib/ZezX8fFVZY14 CvaAHz9mqhFpqS9fcrsk0Y2zvomoKcwLtJIhvbtBbRMMEuvU45DmAefNN6Yf82v2rofw 7NZkqxw5MFKZ9wlKNi0oRgxel7StQXxZ3X9SNx4PLIDWTH0goP8ewXrZz0xBz94jhU/Q z8yfvP8dtF68rAT+Ag5EhjgwKXZyLE8X0pgEnKrRj5Lw1UK3NKJ/08mIxaPVT5+MaoEh APV1kebbuaqD5jaaoTeOaRFhaYUyRzOqkqwCW5dy8W0Mye2SUWhHByOz5mxVwgWbQR5O UrKA== 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=LqqPzQb5rQKmQSK7Lm4nztokxHt2+EweWXTUlu6+fsA=; b=0sVeEP2HplMiVrL8hRU43dXZeqwv6l8uzF11DP5b1FxV2rbtjs5pn3SIGa3Fh6HhXH av4ObavX/eQ4324+7TKLM6E17fBZq/d0cY+O5m5xV4d0f3oASnkGFme/8IYJvjYVFl0Q EZVNchVgwaWHLq2jSN7BazH3w0AOS/FftNZUvtv9dQwJMaXTjgsLmf82xH4pEoNhceOj GNHxLSBkJ49U3lkf1J3KoMxOtjNGDCj5xQJf6Pw03NMu5VH7ekTqBdpAhEWWY1cFC7ub FC+PZf8e9NrHBrnirX/zKJq9ZONi7D3q+ALcrxggVEkzn+mRuk1TdiuLWzPNQHwhfMj3 xGPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=G9Q61Zw7; 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 o10-v6si2299161pgf.680.2018.09.27.07.51.53; Thu, 27 Sep 2018 07:51:54 -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=@linaro.org header.s=google header.b=G9Q61Zw7; 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 S1728431AbeI0VK3 (ORCPT + 32 others); Thu, 27 Sep 2018 17:10:29 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:32854 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728413AbeI0VK2 (ORCPT ); Thu, 27 Sep 2018 17:10:28 -0400 Received: by mail-wr1-f65.google.com with SMTP id f10-v6so2986025wrs.0 for ; Thu, 27 Sep 2018 07:51:50 -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=BHRNDykXriWsQYpgSCAr7Z6Pj3S4RdzQ+2EaNG2p8GXHSKulney4dYWgV6KaObVmma dh3ZwrK0RvHavg6LfMkGQnkjlYR194k0xB8DvpT65HHBr5qNaV8krQU1IKjz7b3E4+YU QaKPrmiNnmoBFqI4O4Gebz+18PYKqIC43qiFxPq/JzVOUKUC3G7xsI+Xj7uwVZ3wAdsm e0vObkKXG3L9G1JQCA3bRtT3YosVIUd03p/5rX9Uri14kLw8RzDV2dnfMcFiHlgMaShN WV41GPOfP8zJPTAOI+Zg0mfiJbwPy+ZsTtgYZPtb0KV3g54DjxeXkwQLFsPQrH/jgwjV y0gA== X-Gm-Message-State: ABuFfoipSgJ74pVfroxStzvFyiMmVgXFZCTbITT+PiszePLhO4stpX0Z Kz+ctJonAPS0nmXCgjAh5zuUBg== 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 Cc: mingo@kernel.org, Alexandre Belloni , stable@vger.kernel.org, Dan Carpenter , Nicolas Ferre , linux-kernel@vger.kernel.org (open list:CLOCKSOURCE, CLOCKEVENT DRIVERS), linux-arm-kernel@lists.infradead.org (moderated list:ARM/Microchip (AT91) SoC support) 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: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(-) -- 2.7.4 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);