From nobody Sat Feb 7 21:14:58 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A2985C433EF for ; Mon, 23 May 2022 17:04:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239222AbiEWREQ (ORCPT ); Mon, 23 May 2022 13:04:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239162AbiEWREG (ORCPT ); Mon, 23 May 2022 13:04:06 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74E4A54F81; Mon, 23 May 2022 10:04:04 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id CF335CE1710; Mon, 23 May 2022 17:04:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AE807C385AA; Mon, 23 May 2022 17:04:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1653325441; bh=HRk57lP6sF9mILCmLjJQ6o2/9oKk/pnufB31Sf1vFA0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ceiX76itaZ2wEtB09jjWzWHRo5FOj0gw0MmozbH74jp9mENt1AWOMVEyewe6y6FF/ 8LmaKalA+rNt7KjfiVPVyA37ZbO/le+J2el3LZ1M1VFVMakjxsrPg9VorbqUhqvLnU LkD9IrsQ4ssoDcPLOFqND5Frct1M1FlV6UIb0hzw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xiaoke Wang , Thomas Bogendoerfer , Sasha Levin Subject: [PATCH 4.9 04/25] MIPS: lantiq: check the return value of kzalloc() Date: Mon, 23 May 2022 19:03:22 +0200 Message-Id: <20220523165745.453623965@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220523165743.398280407@linuxfoundation.org> References: <20220523165743.398280407@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Xiaoke Wang [ Upstream commit 34123208bbcc8c884a0489f543a23fe9eebb5514 ] kzalloc() is a memory allocation function which can return NULL when some internal memory errors happen. So it is better to check the return value of it to prevent potential wrong memory access or memory leak. Signed-off-by: Xiaoke Wang Signed-off-by: Thomas Bogendoerfer Signed-off-by: Sasha Levin --- arch/mips/lantiq/falcon/sysctrl.c | 2 ++ arch/mips/lantiq/xway/gptu.c | 2 ++ arch/mips/lantiq/xway/sysctrl.c | 46 ++++++++++++++++++++----------- 3 files changed, 34 insertions(+), 16 deletions(-) diff --git a/arch/mips/lantiq/falcon/sysctrl.c b/arch/mips/lantiq/falcon/sy= sctrl.c index 82bbd0e2e298..714d92659489 100644 --- a/arch/mips/lantiq/falcon/sysctrl.c +++ b/arch/mips/lantiq/falcon/sysctrl.c @@ -169,6 +169,8 @@ static inline void clkdev_add_sys(const char *dev, unsi= gned int module, { struct clk *clk =3D kzalloc(sizeof(struct clk), GFP_KERNEL); =20 + if (!clk) + return; clk->cl.dev_id =3D dev; clk->cl.con_id =3D NULL; clk->cl.clk =3D clk; diff --git a/arch/mips/lantiq/xway/gptu.c b/arch/mips/lantiq/xway/gptu.c index 0f1bbea1a816..955d0d5cfbdb 100644 --- a/arch/mips/lantiq/xway/gptu.c +++ b/arch/mips/lantiq/xway/gptu.c @@ -124,6 +124,8 @@ static inline void clkdev_add_gptu(struct device *dev, = const char *con, { struct clk *clk =3D kzalloc(sizeof(struct clk), GFP_KERNEL); =20 + if (!clk) + return; clk->cl.dev_id =3D dev_name(dev); clk->cl.con_id =3D con; clk->cl.clk =3D clk; diff --git a/arch/mips/lantiq/xway/sysctrl.c b/arch/mips/lantiq/xway/sysctr= l.c index 95bec460b651..dd7c36a193e3 100644 --- a/arch/mips/lantiq/xway/sysctrl.c +++ b/arch/mips/lantiq/xway/sysctrl.c @@ -331,6 +331,8 @@ static void clkdev_add_pmu(const char *dev, const char = *con, bool deactivate, { struct clk *clk =3D kzalloc(sizeof(struct clk), GFP_KERNEL); =20 + if (!clk) + return; clk->cl.dev_id =3D dev; clk->cl.con_id =3D con; clk->cl.clk =3D clk; @@ -354,6 +356,8 @@ static void clkdev_add_cgu(const char *dev, const char = *con, { struct clk *clk =3D kzalloc(sizeof(struct clk), GFP_KERNEL); =20 + if (!clk) + return; clk->cl.dev_id =3D dev; clk->cl.con_id =3D con; clk->cl.clk =3D clk; @@ -372,24 +376,28 @@ static void clkdev_add_pci(void) struct clk *clk_ext =3D kzalloc(sizeof(struct clk), GFP_KERNEL); =20 /* main pci clock */ - clk->cl.dev_id =3D "17000000.pci"; - clk->cl.con_id =3D NULL; - clk->cl.clk =3D clk; - clk->rate =3D CLOCK_33M; - clk->rates =3D valid_pci_rates; - clk->enable =3D pci_enable; - clk->disable =3D pmu_disable; - clk->module =3D 0; - clk->bits =3D PMU_PCI; - clkdev_add(&clk->cl); + if (clk) { + clk->cl.dev_id =3D "17000000.pci"; + clk->cl.con_id =3D NULL; + clk->cl.clk =3D clk; + clk->rate =3D CLOCK_33M; + clk->rates =3D valid_pci_rates; + clk->enable =3D pci_enable; + clk->disable =3D pmu_disable; + clk->module =3D 0; + clk->bits =3D PMU_PCI; + clkdev_add(&clk->cl); + } =20 /* use internal/external bus clock */ - clk_ext->cl.dev_id =3D "17000000.pci"; - clk_ext->cl.con_id =3D "external"; - clk_ext->cl.clk =3D clk_ext; - clk_ext->enable =3D pci_ext_enable; - clk_ext->disable =3D pci_ext_disable; - clkdev_add(&clk_ext->cl); + if (clk_ext) { + clk_ext->cl.dev_id =3D "17000000.pci"; + clk_ext->cl.con_id =3D "external"; + clk_ext->cl.clk =3D clk_ext; + clk_ext->enable =3D pci_ext_enable; + clk_ext->disable =3D pci_ext_disable; + clkdev_add(&clk_ext->cl); + } } =20 /* xway socs can generate clocks on gpio pins */ @@ -409,9 +417,15 @@ static void clkdev_add_clkout(void) char *name; =20 name =3D kzalloc(sizeof("clkout0"), GFP_KERNEL); + if (!name) + continue; sprintf(name, "clkout%d", i); =20 clk =3D kzalloc(sizeof(struct clk), GFP_KERNEL); + if (!clk) { + kfree(name); + continue; + } clk->cl.dev_id =3D "1f103000.cgu"; clk->cl.con_id =3D name; clk->cl.clk =3D clk; --=20 2.35.1