Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1745331iob; Fri, 29 Apr 2022 11:48:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxBBS4186acvfxQGjojjhwz82Xm3GchUkrkWz+riiS1a/gByHzQb51T8zYqEHY57z3ERBgt X-Received: by 2002:a2e:9093:0:b0:24f:1098:4fc2 with SMTP id l19-20020a2e9093000000b0024f10984fc2mr353341ljg.79.1651258114091; Fri, 29 Apr 2022 11:48:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651258114; cv=none; d=google.com; s=arc-20160816; b=L4q/JETK0E6fGGBIQt5tR0aII0YmDvA6WNMqFOXM4H8PYodVzdzyobW6F0oobaO9bb 1+KCZvRk91Cnmj+Nfvl+NYzKa5h4bcKgDoq08CRS0xtEAJGkUNIA2nC8PqpCQDVBf9JR cQ25WFHKv061AixFmEVaICke32QSJMJFTsWG9NN0vZ+mrLyenxwQscgOfTYfYQtZIv21 Ki9zsJNktiq8ibqubDrKbWL2kRFaNcNoZIQEe1VtqQB9Qbqmys0O3DYtDFd3WVTxfn0N sVnNSpR0ObibAq0zUddrd2tEUI6hSR+Dqr3OKm7I/adIE8YkzVinxhYZ1MJeurbLQnqE DzRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=u9jjxzFqyEv8LBWVsrZtYT4OxlKeAvkfQsoOT8XO85M=; b=hNE8h7RSvphfG9YBdvmSMrHh7spdULzknyGpUFc3YGKhlyrMVSeo4i942PpJ5h5ow6 8A/X9hd5YPi5xROzAPhIVoSQl4NA5ux3PraoC43rC92hNK2gC+TNOKVbvbL9suwS+Zm/ on9mRMJssdrNlAJr8l4Lk6dXQ+B52OLdCQu56cdhK51PnpHiFReks8Y0T2ewf/yBX83L ATgKLyCwdx44U/BU5kC7aZsuUlm217xWqNwdgBdUBpk/5rOqCm69CV1VsYs+0cMbEG7h v2UxEUc9N7MX/KiElqDZwVy066U82W8J+L6iWQ/P99mAdX2yFce+a3rTTpgI+FoEyunM uZng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Eo9pYlKY; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u22-20020a05651c131600b0024db4174c03si7315649lja.607.2022.04.29.11.48.04; Fri, 29 Apr 2022 11:48:34 -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; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Eo9pYlKY; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348643AbiD1OzP (ORCPT + 99 others); Thu, 28 Apr 2022 10:55:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348639AbiD1OzH (ORCPT ); Thu, 28 Apr 2022 10:55:07 -0400 Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9A7F5D5E7; Thu, 28 Apr 2022 07:51:52 -0700 (PDT) Received: by mail-pj1-x1031.google.com with SMTP id d23-20020a17090a115700b001d2bde6c234so5980024pje.1; Thu, 28 Apr 2022 07:51:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=u9jjxzFqyEv8LBWVsrZtYT4OxlKeAvkfQsoOT8XO85M=; b=Eo9pYlKYZkJpqf31dxcbCDkgVISHZnUiOPR5gJATEANdzGnDNxlo7Yahv5R1ctQee5 bhsphKUBm5UdIl3TBHZtHHw8KW8AwPkGlZn1OfaZhzn/qjhFAd47hmnNY4VRyJ1kd3km UCuuoJEpezzIv4/nWOUTOvsiHjuUq16RoBvyw5pGTRCV2ncKp0ExCyStDmL+GBS5SWFz Bz7YgTdAdWJFoOUriJJvEHLbu+XJ9lDNE7fxqKvInyUi5DHD5btdg9Im39MbF9U6EzOR o2UIXa2E8oOO9eNFlULEYoj5w6ijpqiTJdTHzG1DUeZmGcAuENmSCNnPkDqW8UG99YXH L66Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=u9jjxzFqyEv8LBWVsrZtYT4OxlKeAvkfQsoOT8XO85M=; b=s5SJcOegtitazo+6lT+kPLcMEJbLN7Rf4A69knyB4s2RphQqetV5HDjzXOnreAqvgZ WkNlC+eU2/wP0mE4tLZnkpOTjRpjuLLxS7mmmH8vqIK41lHt8i+djwIfJWjLILXpTjuE OW706mpgKrFRRja1+p1o6J+jFqykdHAplNNHNFTvC7oQtho/5PD7QQnIwbVxEsfoy4Fn wEYiBQsQ3gktOoH/ORUqJOHQu9N2dKaQGzpqbPeScgnlg/0G6aAOenui0SG2nDaW4uEU jqg+gJVByeygb+Z0KwpDM/I6h4Bj+11AiKWQXmZsvZ9ilsRx0XU4B/GVonhnO/u2JOnl 84yA== X-Gm-Message-State: AOAM530AFm9VA70a+yCWkXSmQApV+Jh4H1NSF9IfLzBmjy1XeudIvS7q EGIoHKnWOKc58rliyJXSPuyZ5JPPO/Rn7NkbkzM= X-Received: by 2002:a17:90a:ec0e:b0:1d9:7f4d:23be with SMTP id l14-20020a17090aec0e00b001d97f4d23bemr22629798pjy.181.1651157512300; Thu, 28 Apr 2022 07:51:52 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Jeffrey Hugo Date: Thu, 28 Apr 2022 08:51:30 -0600 Message-ID: Subject: Re: [PATCH] iommu/msm: add a check for the return of kzalloc() To: xkernel.wang@foxmail.com Cc: Andy Gross , Bjorn Andersson , Joerg Roedel , Will Deacon , MSM , iommu@lists.linux-foundation.org, lkml Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,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 2:13 PM 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"); How do you reconcile this with chapter 14 of the coding style document? "These generic allocation functions all emit a stack dump on failure when used without __GFP_NOWARN so there is no use in emitting an additional failure message when NULL is returned." > + return; > + } > master->of_node = dev->of_node; > list_add(&master->list, &(*iommu)->ctx_list); > dev_iommu_priv_set(dev, master); > --