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 CC092C433F5 for ; Thu, 28 Apr 2022 08:18:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344048AbiD1IV4 (ORCPT ); Thu, 28 Apr 2022 04:21:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344022AbiD1IVv (ORCPT ); Thu, 28 Apr 2022 04:21:51 -0400 Received: from theia.8bytes.org (8bytes.org [81.169.241.247]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1EFD298F7C for ; Thu, 28 Apr 2022 01:18:31 -0700 (PDT) Received: by theia.8bytes.org (Postfix, from userid 1000) id B9DF42FB; Thu, 28 Apr 2022 10:18:30 +0200 (CEST) Date: Thu, 28 Apr 2022 10:18:29 +0200 From: Joerg Roedel To: cgel.zte@gmail.com Cc: will@kernel.org, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Lv Ruyi , Zeal Robot Subject: Re: [PATCH] iommu: add null pointer check Message-ID: References: <20220329055322.2375563-1-lv.ruyi@zte.com.cn> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220329055322.2375563-1-lv.ruyi@zte.com.cn> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 29, 2022 at 05:53:22AM +0000, cgel.zte@gmail.com wrote: > From: Lv Ruyi > > kmem_cache_zalloc is a memory allocation function which can return NULL > when some internal memory errors happen. Add null pointer check to avoid > dereferencing null pointer. > > Reported-by: Zeal Robot > Signed-off-by: Lv Ruyi > --- > drivers/iommu/fsl_pamu_domain.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/drivers/iommu/fsl_pamu_domain.c b/drivers/iommu/fsl_pamu_domain.c > index 69a4a62dc3b9..43849c027298 100644 > --- a/drivers/iommu/fsl_pamu_domain.c > +++ b/drivers/iommu/fsl_pamu_domain.c > @@ -152,6 +152,10 @@ static void attach_device(struct fsl_dma_domain *dma_domain, int liodn, struct d > } > > info = kmem_cache_zalloc(iommu_devinfo_cache, GFP_ATOMIC); > + if (!info) { > + spin_unlock_irqrestore(&device_domain_lock, flags); > + return; > + } Such errors need to be propagated.