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 0E0B2C433EF for ; Tue, 29 Mar 2022 08:35:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232550AbiC2Igv (ORCPT ); Tue, 29 Mar 2022 04:36:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231997AbiC2Igv (ORCPT ); Tue, 29 Mar 2022 04:36:51 -0400 Received: from mxout02.lancloud.ru (mxout02.lancloud.ru [45.84.86.82]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BFA4823DE8F; Tue, 29 Mar 2022 01:35:05 -0700 (PDT) Received: from LanCloud DKIM-Filter: OpenDKIM Filter v2.11.0 mxout02.lancloud.ru BED922208DDD Received: from LanCloud Received: from LanCloud Received: from LanCloud Subject: Re: [PATCH v1] MIPS: ip22-gio: Add check for the return value of kzalloc() To: QintaoShen , CC: , , References: <1648454654-27200-1-git-send-email-unSimple1993@163.com> From: Sergey Shtylyov Organization: Open Mobile Platform Message-ID: <6dd8bcf0-20a1-0bab-b48e-ec1bac5c15f0@omp.ru> Date: Tue, 29 Mar 2022 11:35:01 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: <1648454654-27200-1-git-send-email-unSimple1993@163.com> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [192.168.11.198] X-ClientProxiedBy: LFEXT01.lancloud.ru (fd00:f066::141) To LFEX1907.lancloud.ru (fd00:f066::207) Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org Hello! On 3/28/22 11:04 AM, QintaoShen wrote: > Since the memory allocation function kzalloc() may return a NULL pointer, > the use of 'gio_dev' may lead to NULL pointer dereference. > > So it is better to check the return value of kzalloc(). > > Signed-off-by: QintaoShen > --- > arch/mips/sgi-ip22/ip22-gio.c | 6 +++++- > 1 file changed, 5 insertions(+), 1 deletion(-) > > diff --git a/arch/mips/sgi-ip22/ip22-gio.c b/arch/mips/sgi-ip22/ip22-gio.c > index dfc52f6..df7ca21 100644 > --- a/arch/mips/sgi-ip22/ip22-gio.c > +++ b/arch/mips/sgi-ip22/ip22-gio.c > @@ -363,7 +363,11 @@ 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); > - gio_dev->name = name; > + > + if (!gio_dev) Indented too little. And indent with tabs please, not spaces. > + return ; No need for space before ';'. [...] MBR, Sergey