Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1877572pxb; Fri, 25 Mar 2022 07:14:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzJObGLn++Q6A7WRTnw0ZpQKNYsIoprO3bm4Kfe+KFnKRpT65ZxEw+0bo1HZg50PhVBqaJJ X-Received: by 2002:a62:1ad3:0:b0:4fa:9adc:7680 with SMTP id a202-20020a621ad3000000b004fa9adc7680mr10519513pfa.25.1648217667046; Fri, 25 Mar 2022 07:14:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648217667; cv=none; d=google.com; s=arc-20160816; b=Jd2YbPDBp/JRltagfwgVIZK7waHavvZN+L5v4odHQuSSTY3v/Ar80G3oui89pX6xql wwtuBUjfXSayKyIMav/17r1n68UdTHs7cCLArKKHeA8patwYB3hihEfdWWotp4zs7fae ULT+BLOoCvIb1DglspCEO/8bDLZ46uUwBdgeXmB2zilZCFmsMyCAEzxp5fTRAi5pd/6A cC4shIJu1KxMl2dz+iDcoX74WCxWbkbIuGy1/Q84o3BbkqCvTQYm90+yrtcO8hKwivIT MKDgSvL7WQzp7SlKy1OXBqXEG+Ah8sFLrQ6SRn3zWa49tkKcahn9bHI30clAYj2BpcEE 2JUg== 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=pSDOl4RxPS3vwyxqajmQzws6vv0+qNWYgNjBfF6MJdA=; b=c5k4YfEEOpbRNsWhOUgPL+RAUrfnkyhWRbmtyXcUsXJL78lAU1ToU0ydXBqeUE9Hmo fHQkbWJ7xn80JSNIQlrFPcNDKOHDZO5MoaVDWKqtbvQUTCI3LnHjqtfMCwTDqBRSAyFU pjf08lXl7lpthN1AkglDVIK8r+7xmfj7HZYUlDwW+wToRxgqsJXk++WnD4cFrL57bzl7 cSQ2ESxGEXwkY8nBWX023E7BHZBEUwyi18Sh96SZJdHOFMonFAURmySEWMBgP8qPLtie AQWHKxSEJZe4092fBJSgN12Rc7p+12envLmwNfsR7gTqqyDrw+peE9iMBPWubVqDhfZ7 Z+ag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="M/fjEFAg"; 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 o1-20020a639a01000000b003865aa9f223si2254102pge.806.2022.03.25.07.14.13; Fri, 25 Mar 2022 07:14:27 -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="M/fjEFAg"; 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 S1353621AbiCXTxy (ORCPT + 99 others); Thu, 24 Mar 2022 15:53:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352951AbiCXTwx (ORCPT ); Thu, 24 Mar 2022 15:52:53 -0400 Received: from mail-oi1-x236.google.com (mail-oi1-x236.google.com [IPv6:2607:f8b0:4864:20::236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F26B2A7771 for ; Thu, 24 Mar 2022 12:51:20 -0700 (PDT) Received: by mail-oi1-x236.google.com with SMTP id t21so1103177oie.11 for ; Thu, 24 Mar 2022 12:51:20 -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=pSDOl4RxPS3vwyxqajmQzws6vv0+qNWYgNjBfF6MJdA=; b=M/fjEFAgiHj+BzsOVIXD82r8Ii2g8/s3VpSIXQR4zlmIZcAD0IkMUr+xPROHHPknNI dr7E95zOmFbRwstcOpTFjgkUKi7TvXSb8zjVJ+87LPI+Ovj+pNG9umxoKi0JJYR+2ZqH H+hQe+5easlTGLQo61UyGbxLJo1g426f4C9eBnBF/zjc7LEmnQJWiRsmwlbqWfJ1s5nm HeZJbX3G80U0Pi76oSMosL4FkMOeEdROwBIarfq2JMlUpH2bh34vFXr8o++pDEZFMJuN VKSOMW8UxGtJaLGe5gHS9uH5DxaO7AHfn8cXU7Iz0m1U0GcK4jJv0up0vPsYb/HTlfRA lF+Q== 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=pSDOl4RxPS3vwyxqajmQzws6vv0+qNWYgNjBfF6MJdA=; b=CnKq4MWwbRbhYKFh58fll2drInjCwd5lbFucSiznYiJyenGMy1sG0RwbRdEmgMxGSM gUiiKi+pIXriIUdNPNyfI5qnK93ybKLeLHPJgKGfXPkPIFoAaWkaNWCx6z+YbzTBg+/N MCHa9L/yUO/qSoRlsnj7JcvoGM7o97t4QmBCfysnIkfGv3auFlLABsn7U36sXawdc2sT oMd8NxTUuncydHuK6AILAoxJxItUNISD/iu5VDCcunHKYCQz6UrSCD+tXH+BMG/0dAb7 Re7jQCs7UpNuj5YICDErt6mqwutDOb/zXYHmD6vEDH9t3dnnFKeQjb739lkhcEq4zunF yL4g== X-Gm-Message-State: AOAM533HGTymQQivva0xcaU4yDlLl6/OdyACvJwdLm24mHn8eTibLxJr B2zGn8bqabzfWr0PLfwFCkwHuzh4DR/FTw9mOqw= X-Received: by 2002:a05:6808:df1:b0:2ec:b193:ad6c with SMTP id g49-20020a0568080df100b002ecb193ad6cmr7765124oic.200.1648151480357; Thu, 24 Mar 2022 12:51:20 -0700 (PDT) MIME-Version: 1.0 References: <1648110383-3533-1-git-send-email-unSimple1993@163.com> In-Reply-To: <1648110383-3533-1-git-send-email-unSimple1993@163.com> From: Alex Deucher Date: Thu, 24 Mar 2022 15:51:09 -0400 Message-ID: Subject: Re: [PATCH v1] drm/amdkfd: Check for potential null return of kmalloc_array() To: QintaoShen Cc: "Kuehling, Felix" , LKML , amd-gfx list 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,T_SCC_BODY_TEXT_LINE 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 Applied. Thanks! Alex On Thu, Mar 24, 2022 at 9:46 AM QintaoShen wrote: > > As the kmalloc_array() may return null, the 'event_waiters[i].wait' would lead to null-pointer dereference. > Therefore, it is better to check the return value of kmalloc_array() to avoid this confusion. > > Signed-off-by: QintaoShen > --- > drivers/gpu/drm/amd/amdkfd/kfd_events.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_events.c b/drivers/gpu/drm/amd/amdkfd/kfd_events.c > index deeccce..64f4a51 100644 > --- a/drivers/gpu/drm/amd/amdkfd/kfd_events.c > +++ b/drivers/gpu/drm/amd/amdkfd/kfd_events.c > @@ -749,6 +749,8 @@ static struct kfd_event_waiter *alloc_event_waiters(uint32_t num_events) > event_waiters = kmalloc_array(num_events, > sizeof(struct kfd_event_waiter), > GFP_KERNEL); > + if (!event_waiters) > + return NULL; > > for (i = 0; (event_waiters) && (i < num_events) ; i++) { > init_wait(&event_waiters[i].wait); > -- > 2.7.4 >