From mboxrd@z Thu Jan 1 00:00:00 1970 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 95763C433FE for ; Wed, 30 Mar 2022 19:00:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350276AbiC3TCP (ORCPT ); Wed, 30 Mar 2022 15:02:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350284AbiC3TCM (ORCPT ); Wed, 30 Mar 2022 15:02:12 -0400 Received: from elvis.franken.de (elvis.franken.de [193.175.24.41]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9649013E1D; Wed, 30 Mar 2022 12:00:26 -0700 (PDT) Received: from uucp (helo=alpha) by elvis.franken.de with local-bsmtp (Exim 3.36 #1) id 1nZdYO-0003Qd-00; Wed, 30 Mar 2022 21:00:24 +0200 Received: by alpha.franken.de (Postfix, from userid 1000) id 9EA7DC2EE6; Wed, 30 Mar 2022 20:34:01 +0200 (CEST) Date: Wed, 30 Mar 2022 20:34:01 +0200 From: Thomas Bogendoerfer To: xkernel.wang@foxmail.com Cc: linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] mips: sgi-ip22: add a check for the return of kzalloc() Message-ID: <20220330183401.GA18042@alpha.franken.de> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Mar 25, 2022 at 06:57:18PM +0800, xkernel.wang@foxmail.com wrote: > From: Xiaoke Wang > > kzalloc() is a memory allocation function which can return NULL when > some internal memory errors happen. So it is better to check it to > prevent potential wrong memory access. > > Signed-off-by: Xiaoke Wang > --- > arch/mips/sgi-ip22/ip22-gio.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/arch/mips/sgi-ip22/ip22-gio.c b/arch/mips/sgi-ip22/ip22-gio.c > index dfc52f6..38d12f4 100644 > --- a/arch/mips/sgi-ip22/ip22-gio.c > +++ b/arch/mips/sgi-ip22/ip22-gio.c > @@ -363,6 +363,8 @@ static void ip22_check_gio(int slotno, unsigned long addr, int irq) > printk(KERN_INFO "GIO: slot %d : %s (id %x)\n", > slotno, name, id); > gio_dev = kzalloc(sizeof *gio_dev, GFP_KERNEL); > + if (!gio_dev) > + return; > gio_dev->name = name; > gio_dev->slotno = slotno; > gio_dev->id.id = id; > -- applied to mips-next. Thomas. -- Crap can work. Given enough thrust pigs will fly, but it's not necessarily a good idea. [ RFC1925, 2.3 ]