From patchwork Mon Oct 9 08:39:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacky Bai X-Patchwork-Id: 13413079 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BF1CCE95A8E for ; Mon, 9 Oct 2023 08:35:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=mLwDgLoWZO5ByjcVbj5QvGJEfd0P+q/lsyLx2EEk4UU=; b=1lmBkbwWScSbmm zhx/ZZcSFe1E5EfVBu50ZiaW8+7s5xmVssXh8S53EZziH+3UGD0P+pFSI/MSw6WkHOySPvqEaGArB GqZjM/co/z3R2mNkn3mAj4Su46wfdx/007JhG/HesFUNfGwuZ2A4et7gqJekzc8BDgjWcJlNTZASc tHWKwMxAnbRS2zNFqD1hdif8cHoeoSyYqbclEo/DCBR5HGoRiW6RUiLSYHpJTT+a6QE13qLvA+MBl ssN6ueGWoqH8UgsTE4Rbj21fkkPbR/zz48HpwVAOulmNZ1ioJloVIeAQnhD7jZ4PU8o9MyX488x9u dztVNjvRoUIAbvZCwaNw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qplit-009yw1-1T; Mon, 09 Oct 2023 08:34:43 +0000 Received: from mail-am6eur05on20614.outbound.protection.outlook.com ([2a01:111:f400:7e1b::614] helo=EUR05-AM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qpliq-009yva-0B for linux-arm-kernel@lists.infradead.org; Mon, 09 Oct 2023 08:34:41 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DqKaAFwfwNs3vQZOhER3mBqqN/coDbJZ4G3DAyHNoARk4z+mtFTGzuxSEybe9Ejy+D7bOeZGH1x1ossqTPYuA8euQS8LsoLnFKykwyYo8QXmm2kgOXE6x13KW3LFKZwujqg0/3xITBGcTnvZSPMH6Dp4Ti5j8mL3AG4NhrVqnH5qmd8gUgSUx7C8euJDBJZDlI8tItjgqzQgDshqb5clUCSHk9v3zm/zqSJLyO6lXSmIea/YqkMK+zQzfiNMfTOlfrhVfzkrGgGUf5Ir5O+IPHNe8GiXvLxZZP5pw/K8q8pxpPr5FoDlv71AU67L1DQw+rIs+SVxpRPP7KMJyx2nWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=YoF8aupz/AcSacNYrbukHwKdqRU3oulbzRoOf75ciQ0=; b=jjV4cfMeHm2eWyqmepJky5x3+1L14Gu7SzMhD183Zb8iVP2kwm6U3Wq+EpSCTHG7M1OKc3uXx2cTtXOJ7dxY+GeEgvGqfpOHY9WoYF1wKXrvmwhAf0DDfujxhzs3sYiMvLXbTwc7MUbGlU1reTU7CHYMlqah/B+dut3GJ1CzCW2GH/HoYykSXFJvYt6foT/xOVzMUNsFlB1iBWfFFQQp/DbX2E7TGkVfNYpVAXah3kQOsH1TZMVIu9fohUOsfN1j4E3nBb1RcreafNOI+gY81/2F6DCRBkFLVYPAiYDGgjFmxU6u/saov5UPZQmknjp8SPmnxSiKR7XWYxThPkzRdA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=YoF8aupz/AcSacNYrbukHwKdqRU3oulbzRoOf75ciQ0=; b=DCjW34fXyu6DeWGepwAEfPBDK+BRGLLEfOCI4uXvQ0xIWj3MzZnAUCbvUtSC1Bk9O4paODrWvHcX3VYGp7RY+T1cessN1hn5cMEAzrmTK7XioRSCoF6itIjQXI7+f5DwHj7bN+lkPlAB0gs43gBZGDQ4auWI1psXSau1iNqIqO8= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AS8PR04MB8642.eurprd04.prod.outlook.com (2603:10a6:20b:429::24) by PAXPR04MB9187.eurprd04.prod.outlook.com (2603:10a6:102:221::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.43; Mon, 9 Oct 2023 08:34:32 +0000 Received: from AS8PR04MB8642.eurprd04.prod.outlook.com ([fe80::258e:61b0:da64:d168]) by AS8PR04MB8642.eurprd04.prod.outlook.com ([fe80::258e:61b0:da64:d168%5]) with mapi id 15.20.6863.032; Mon, 9 Oct 2023 08:34:32 +0000 From: Jacky Bai To: daniel.lezcano@linaro.org, tglx@linutronix.de, shawnguo@kernel.org Cc: kernel@pengutronix.de, festevam@gmail.com, linux-imx@nxp.com, linux-arm-kernel@lists.infradead.org Subject: [PATCH] clocksource: timer-imx-gpt: fix potential memory leak Date: Mon, 9 Oct 2023 16:39:22 +0800 Message-Id: <20231009083922.1942971-1-ping.bai@nxp.com> X-Mailer: git-send-email 2.34.1 X-ClientProxiedBy: SI1PR02CA0006.apcprd02.prod.outlook.com (2603:1096:4:1f7::11) To AS8PR04MB8642.eurprd04.prod.outlook.com (2603:10a6:20b:429::24) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR04MB8642:EE_|PAXPR04MB9187:EE_ X-MS-Office365-Filtering-Correlation-Id: 3205324f-4530-449d-37ef-08dbc8a28f75 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: toXFFx/cFXdj+CrhAKl1PbTaa54G5ufmJw8HxgSWE+WnupbH+t/mUbb1piruqL/wKtYNeDqcAVTNkFx54Z4oBJrG4clSMrA0ggCnuCFCMjBEDkHWhL8H1cltMIjhZYnxUvdN8//XDP1emeRKUBHt13AJFeM2iWo+pnG8JldMsNbZmcXPISXv5p3btYgp6yzdmCF11VRChg0+EkZsgsLImz82waLr0JU7TcVB91zMehDdPJAKLgYa+ipjBt717dbcmcfgYys4IF6jJ87ql70xXPfxA9BsKOUvuR5xABZL7VmcuExLki80QS/7ylryPemxiysM3qbFyXocw0iA7VEz7vQSDMOg9cR0/2pM8u6/U4pRxm8qGW7yP4hB/fWUtYAhfVBj2RudNEgNO1LhHlVFrmb/W0pO4ll40/bg6x+3/LbYlqVxf18ozWWrrtM3M7aaWJ7dk4NnO0sJz2yoyagdzw9CIBY7vSRJNSoSolEM8k2Aaxm14d+qx/pBH8naEsQ64SCRJw6jmU+xKsCJpfWn89/P2k3Tzj5OoqpYZESVI5J280dgXoO/yvxoe7dpH7cGHY1qm7f4u71WZMyJmxzqvBqLpe+lG5Jt+7KlVU+Jygl+8cEWOSRBYjc7tNeieRDs X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AS8PR04MB8642.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(39860400002)(136003)(376002)(346002)(396003)(366004)(230922051799003)(1800799009)(186009)(451199024)(64100799003)(6512007)(52116002)(1076003)(478600001)(6506007)(6486002)(2616005)(26005)(83380400001)(2906002)(5660300002)(66556008)(66476007)(4326008)(8936002)(8676002)(66946007)(316002)(41300700001)(38100700002)(36756003)(38350700002)(86362001)(6666004);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: D3KPnQFyxNWd9xgNkhxrB5BLfFzf6IEF+51rdXWhk5xtM0cQEqjSNfGFdM7nT6zEppiQqT0688Ubud0cTUW59NQHaMl0BN99Id6YSe8AoC49vsFGDeL4+XDHVoKIik2lwyH0F7U68yF5QQqd9tafwp1pmbKDYTW9B6utEWXe2av+oFgr5+P2uSS/S1UNQLlrLbxY6UtKQzBDfvUZW5Q0Ci4DkypdkU0jBdzsFFHJFqPY5Scuw8SXHcUlO26+yyY1K17u0mykf5kgQPsEFad+FbqGQbbUmsQl7/YcEwMHQGVVx7nYLiye8hFlUmDQ4Zw2jSC8dX8V7ekg9cmQxLNTQf3yYn8dJr0hIslX9cgQu/3XoYkZTPTf5oncrbIA1/PHpY24/e1rDFwHjg2S1b3H5qcwObW8muu+SrWElsqSkdT1AO+uadFaIYN7bhzbKWI1HKPOuCRPU3IKHQyFcBiMzXBbugU+ci46esLge2wjVCSF3zEshWlPIeoVoLaMpUyV/KXufxztyUUSP/8S10AhJwVE7HmqCFnW6cG3Kogt46tpsEQwMVQuG/Fbp3DYREzArtEGOKGfV1FlRj5HBsCosujKRpwopqtv2WlTCNJqNhHpMq3sSzTb5B8CrIx7nXIn5E7iu1ZyIBEYQZLG/5zI4y0Y8/8VPxuwe+ZtdhCZW7G25uIuhzSjW5GUyjFazoP+PSKLYTEks9a+okxHxtPRs1I88iwFFYTKcD+QZzU+Wb7iT5kBHrYvhndr1XkwSiD+lV+ubkfolDgw2tl854Ct38ciy0cqKpRdZkf3P32v3rYpBmwhWjsSql++oAM//+shi4pXauN52lIVpujTAqdS+JNqg1pbvhKBM87JsJQMGBOunAyJS9HRx7/7iARTzz/BHKsnBfhtFSEcX6+JK+PJA1UaXquFaBAwMdMQANGR/TsIFF57EnGLYlJ1SsYSiG2nFBfkSQoOaB3r1fnoTUSblhs5gUYPGk70s1AMzMpb5X0UPjCr0s45AArDZmvVdkPzqy1VnS5kN6dAwyJNl3JHSVK9dATfmYfvGNYl7senokeJcz920Z3FqoxVjWWRmwpSuzMvGUMcmifDqrkS0OdFQSnlqSokl7Ol4rfcIutK+JKfe0L+JrvpWe3h+lPRskbCVilGMAQgV5iaCktbmw+Bnf6E6mDxZbwU1AnAM8fzPhNuiIyE+icbouVtXwJfofJ+jeY+6FqR5/WIp06IXFXjuTLM6v2LyrYbDQlNAELqJ5kWvQmMk8W8KjeZOmMYb7chGKtNmyBUltX9Ba0gLvFtbxxMspxSFsOYBlS1Sy02DU1mo4rs+H2DVbhqv+gfjq3wknXL+0pz9FQ8KTyJ6NpkQ/Fz7bVYQEFv8whjtc7ClEleciycoXlxJSMog8EbD7iraj75ZDxqPh4Xv3u4P6Ytoxq77sAEvqs3XtBJYoAZ/0aTd+6TCG9k5o1Q5GlyJO/SCRdd2mbGtnjJFKQxI0yBQ8FsSrYXq8+0uDBZ++KWseFGsT7ovtMFmKCTRXqT9xAv/+3xgNK/Cf8TNFI36Dw4slKNCpV18SipeAAOlIqpKQKeoV7993oqKtASHTkhd4/V X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3205324f-4530-449d-37ef-08dbc8a28f75 X-MS-Exchange-CrossTenant-AuthSource: AS8PR04MB8642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Oct 2023 08:34:32.4740 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: PUdtbWZFlMYKfDdpmuNhWPirTOS8DF5+UPpdQyW2kvGK5Utyw2wKiw0AbDhQTHbyzMpLI7ZPiyOOf0w/ZpTyXA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR04MB9187 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231009_013440_119850_65537255 X-CRM114-Status: GOOD ( 12.41 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Fix coverity Issue CID 250382: Resource leak (RESOURCE_LEAK). Add kfree when error return. Signed-off-by: Jacky Bai Reviewed-by: Peng Fan --- drivers/clocksource/timer-imx-gpt.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/drivers/clocksource/timer-imx-gpt.c b/drivers/clocksource/timer-imx-gpt.c index 28ab4f1a7c71..6a878d227a13 100644 --- a/drivers/clocksource/timer-imx-gpt.c +++ b/drivers/clocksource/timer-imx-gpt.c @@ -434,12 +434,16 @@ static int __init mxc_timer_init_dt(struct device_node *np, enum imx_gpt_type t return -ENOMEM; imxtm->base = of_iomap(np, 0); - if (!imxtm->base) - return -ENXIO; + if (!imxtm->base) { + ret = -ENXIO; + goto err_kfree; + } imxtm->irq = irq_of_parse_and_map(np, 0); - if (imxtm->irq <= 0) - return -EINVAL; + if (imxtm->irq <= 0) { + ret = -EINVAL; + goto err_kfree; + } imxtm->clk_ipg = of_clk_get_by_name(np, "ipg"); @@ -452,11 +456,15 @@ static int __init mxc_timer_init_dt(struct device_node *np, enum imx_gpt_type t ret = _mxc_timer_init(imxtm); if (ret) - return ret; + goto err_kfree; initialized = 1; return 0; + +err_kfree: + kfree(imxtm); + return ret; } static int __init imx1_timer_init_dt(struct device_node *np)