Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp474803iob; Thu, 28 Apr 2022 06:36:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzczz7kniwJqBb8uSxHa9AdQvwfcvROOJpvo3RiTpQ5bqUlf+oqeZgZ2NVwGd1JV7eQEoqN X-Received: by 2002:a05:6512:39d1:b0:471:ea64:da81 with SMTP id k17-20020a05651239d100b00471ea64da81mr21206183lfu.61.1651152996893; Thu, 28 Apr 2022 06:36:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651152996; cv=none; d=google.com; s=arc-20160816; b=TS/H8SbAgZDnt/DqBFsBjJq9L3El507CgeFMczXIExRUOjLfkSfs5B6CP6TPBJqMTo j3Uh4GgeRKlQb5n4lZOyzVXQE9apZbFgd4jlnrIJCr90c7GZ4p8+fcfPFGZl9DIZ3hkn /qfQHrfFl/Z2ucd44phFEkpSMI8qLgb9HufrAuD2uwShmtcHWbCTHNlH0FLVD/Cn3g7h b6kFmHdLCysEnEIQZR1I672pZH7oOZ9YOqAQrJ6d5vN9SbZ8hJPuvJcrmzbGO9FiGckq hKj9mq18Clq6O25+0DMs1HuhMQMy/oNrruWOMH5VhykOwr7ABjBlX/Y5XWsNzU/E8cln eThg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=QsQ3LrolJ60Tiat+Kezv2wSLNxCSekG12285bsSfglw=; b=fq9xEl1lnbUdtfed/kLmnrtPAO33aJEm6bX9kfFQnZmlCH5SjS43RYzWlukpKTtBGw W6pGt30oNVcmf7xcwP50aSpjo5rX9zMJoVkRSwpkuJKQ4TYTqqYAE08OI2nlrj3uOqxi 5/V5jC/DHgUf8Ph1zoDegAZti1LMp0FHY1kc5abOqKHOXiJMe0fcYVG+m95chFLqI5B9 bVX4VRyT3W3p/GPVHVJtWM1J2bb37TfSpr6/fBRJGjlcWuFAt3t3arrWLQwY4e3EiykH sygzS2/SmfgHfSlASHeE3A4WmDQF+KJ9meUlelkHBSMkDTY/6msJqk4qYSMczqBycQ/F Cm7Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=8bytes.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s6-20020a195e06000000b0044a1d17609csi4102480lfb.264.2022.04.28.06.36.07; Thu, 28 Apr 2022 06:36:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=8bytes.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343758AbiD1IHR (ORCPT + 99 others); Thu, 28 Apr 2022 04:07:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34458 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229769AbiD1IHO (ORCPT ); Thu, 28 Apr 2022 04:07:14 -0400 Received: from theia.8bytes.org (8bytes.org [IPv6:2a01:238:4383:600:38bc:a715:4b6d:a889]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 297EA92330; Thu, 28 Apr 2022 01:04:01 -0700 (PDT) Received: by theia.8bytes.org (Postfix, from userid 1000) id C205F452; Thu, 28 Apr 2022 10:03:59 +0200 (CEST) Date: Thu, 28 Apr 2022 10:03:58 +0200 From: Joerg Roedel To: xkernel.wang@foxmail.com Cc: agross@kernel.org, bjorn.andersson@linaro.org, will@kernel.org, linux-arm-msm@vger.kernel.org, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] iommu/msm: add a check for the return of kzalloc() Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Mar 25, 2022 at 10:08:01AM +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 > --- > drivers/iommu/msm_iommu.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/drivers/iommu/msm_iommu.c b/drivers/iommu/msm_iommu.c > index 3a38352..697ad63 100644 > --- a/drivers/iommu/msm_iommu.c > +++ b/drivers/iommu/msm_iommu.c > @@ -597,6 +597,10 @@ static void insert_iommu_master(struct device *dev, > > if (list_empty(&(*iommu)->ctx_list)) { > master = kzalloc(sizeof(*master), GFP_ATOMIC); > + if (!master) { > + dev_err(dev, "Failed to allocate iommu_master\n"); > + return; > + } This is not enough, if the error happens it also need to be propagated to the caller. Regards, Joerg