From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 187FFA0540; Wed, 6 Jul 2022 11:05:55 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id AD9C240A7F; Wed, 6 Jul 2022 11:05:54 +0200 (CEST) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by mails.dpdk.org (Postfix) with ESMTP id 7148740691 for ; Wed, 6 Jul 2022 11:05:53 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657098353; x=1688634353; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=MxnH2JBNVF2yplFNfaIr0fkE9DvNb5gk4mnm4F81wlM=; b=nQWS11apKp6ZKxCPF02C58A3uEthdx3eait3gBGC4rqoAadEkXzeA8Em oXIaBEQ9Bk9dTR6VRAYiiaG9HgbCFoTwYInSCOL35r5TVuaRh6URdqgPm IM+31g6V85wbY+ZbGoAD+cJ/1rTTvAXr/EcdGGz0ZdHMVWtfD8BnpIMVz Rnr6kO0X9Mg0mE61SgAd42tzRWZagfawxK3lKuIharjJfCSJtcphE3/xz wrV8Ueklw25A8O6zyX7Kh7Rz51rmCQYF1p/lA3lFbO4LMHd96PiD0K9H2 s4+Zd4dnfMeArMjWN80rY4GGNn+rHHL3UQP2sXb7pdPOCc4RGioyRYX6u g==; X-IronPort-AV: E=McAfee;i="6400,9594,10399"; a="370007421" X-IronPort-AV: E=Sophos;i="5.92,249,1650956400"; d="scan'208";a="370007421" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Jul 2022 02:05:52 -0700 X-IronPort-AV: E=Sophos;i="5.92,249,1650956400"; d="scan'208";a="543315981" Received: from bricha3-mobl.ger.corp.intel.com ([10.55.133.37]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-SHA; 06 Jul 2022 02:05:51 -0700 Date: Wed, 6 Jul 2022 10:05:47 +0100 From: Bruce Richardson To: Thomas Monjalon Cc: Shiqi Liu <835703180@qq.com>, dev@dpdk.org Subject: Re: [PATCH] raw/ioat: Check for the NULL pointer after calling malloc Message-ID: References: <7856744.uz5P2jW1tq@thomas> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <7856744.uz5P2jW1tq@thomas> X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org On Tue, Jul 05, 2022 at 09:43:34PM +0200, Thomas Monjalon wrote: > 27/06/2022 19:52, 835703180@qq.com: > > From: Shiqi Liu <835703180@qq.com> > > > > As the possible failure of the malloc(), the not_checked and > > checked could be NULL pointer. > > Therefore, it should be better to check it in order to avoid > > the dereference of the NULL pointer. > > > > Fixes: b7aaf417f93 ("raw/ioat: add bus driver for device scanning automatically") > > > > Signed-off-by: Shiqi Liu <835703180@qq.com> > > --- > > --- a/drivers/raw/ioat/idxd_bus.c > > +++ b/drivers/raw/ioat/idxd_bus.c > > @@ -301,6 +301,10 @@ dsa_scan(void) > > IOAT_PMD_DEBUG("%s(): found %s/%s", __func__, path, wq->d_name); > > > > dev = malloc(sizeof(*dev)); > > + if (dev == NULL) { > > + closedir(dev_dir); > > + return ENOMEM; > > Isn't it supposed to be a negative value? > Yes, I missed that on my review. Reading the definition of what the bus "scan" method is to return it indicates <0 on error. /Bruce