From patchwork Wed Jan 10 13:46:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandra Diupina X-Patchwork-Id: 13516180 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 960D5C4707C for ; Wed, 10 Jan 2024 13:47:16 +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=EQ0XuuWeMmwfgOkq3BUub0S5Zpf7I91n8xHUoKhdFAo=; b=oaEmY32/NekAar 54JMixRN68qHwfNPfDjAYjEx+4JnirFS059PjdywLbckm5L28FOniYu0Bk2LH3OVEsJkY82N6fSJ8 2joImeqspzLyPBlF0PGAWFwI+LRjW1B2kGEh+jUQ7krGbrHlpNlZdNMaERbURILruonvJQqFIdC1R B76LYoCkDOMcjlgoct/26XEp5dI9FtDmEtKzveBoV9izX+EKio4aSU5MfdOTtC3fLVyfS5RfPveU/ q73S8Q4lbdgHsRPwVTxnFRzP1MHKFC4nrCIFJ5CpHOXQotZggwRNLGJzBEjire/2TVWyljWIGUM9G zFHhNNSYk0vBRz1+3Eww==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rNYuz-00C4s9-1D; Wed, 10 Jan 2024 13:46:53 +0000 Received: from mail.astralinux.ru ([217.74.38.119]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rNYuw-00C4oO-0A for linux-arm-kernel@lists.infradead.org; Wed, 10 Jan 2024 13:46:52 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.astralinux.ru (Postfix) with ESMTP id C7B1B18692DF; Wed, 10 Jan 2024 16:46:34 +0300 (MSK) Received: from mail.astralinux.ru ([127.0.0.1]) by localhost (rbta-msk-vsrv-mail01.astralinux.ru [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id gVFb5WEP5ieC; Wed, 10 Jan 2024 16:46:34 +0300 (MSK) Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.astralinux.ru (Postfix) with ESMTP id 7D93F18692D1; Wed, 10 Jan 2024 16:46:34 +0300 (MSK) X-Virus-Scanned: amavisd-new at astralinux.ru Received: from mail.astralinux.ru ([127.0.0.1]) by localhost (rbta-msk-vsrv-mail01.astralinux.ru [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id lEysMdup5VIp; Wed, 10 Jan 2024 16:46:34 +0300 (MSK) Received: from rbta-msk-lt-302690.astralinux.ru (unknown [10.177.234.199]) by mail.astralinux.ru (Postfix) with ESMTPSA id 4CE9C18659DD; Wed, 10 Jan 2024 16:46:33 +0300 (MSK) From: Alexandra Diupina To: Nishanth Menon Cc: Alexandra Diupina , Tero Kristo , Santosh Shilimkar , Michael Turquette , Stephen Boyd , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, lvc-project@linuxtesting.org Subject: [PATCH] clk: keystone: sci-clk: check devm_kmalloc_array() return value Date: Wed, 10 Jan 2024 16:46:21 +0300 Message-Id: <20240110134621.17209-1-adiupina@astralinux.ru> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240110_054650_287035_D4EA3CA3 X-CRM114-Status: UNSURE ( 6.74 ) X-CRM114-Notice: Please train this message. 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 devm_kmalloc_array() may return NULL, so check return value to avoid null pointer dereferencing Found by Linux Verification Center (linuxtesting.org) with SVACE. Fixes: 3c13933c6033 ("clk: keystone: sci-clk: add support for dynamically probing clocks") Signed-off-by: Alexandra Diupina --- drivers/clk/keystone/sci-clk.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/clk/keystone/sci-clk.c b/drivers/clk/keystone/sci-clk.c index 35fe197dd303..a2fa24e4f88a 100644 --- a/drivers/clk/keystone/sci-clk.c +++ b/drivers/clk/keystone/sci-clk.c @@ -459,6 +459,9 @@ static int ti_sci_scan_clocks_from_fw(struct sci_clk_provider *provider) tmp_clks = devm_kmalloc_array(dev, max_clks + 64, sizeof(sci_clk), GFP_KERNEL); + if (!tmp_clks) + return -ENOMEM; + memcpy(tmp_clks, clks, max_clks * sizeof(sci_clk)); if (max_clks) devm_kfree(dev, clks);