Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp2208035pxb; Fri, 25 Mar 2022 13:04:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzPeY064Z0cPx3KnpZgMfSpVUDnp74RIzLyiinDfJ5hzwJCZHOZ4STLDSBCEfAT98NKbGzD X-Received: by 2002:a17:90b:3a84:b0:1c7:bc91:a870 with SMTP id om4-20020a17090b3a8400b001c7bc91a870mr11956395pjb.155.1648238672445; Fri, 25 Mar 2022 13:04:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648238672; cv=none; d=google.com; s=arc-20160816; b=G6M/WPShjF+ux57lwac18uWpzPEGBo6SuyB37ZOa0gYvtPjCw66kKyHG9mgwiybamo GIo+eefiwtW4A+aQ8KDNCjnP28wBXBOW3uB7+hqTlKNRf76mPPh8yVNfiePwvTDo35S0 1nDblHuEywofBqPz9vaenw3TImY6dsAa7hd8AZNRaFHkIztmTI52qXwYkEEHzWDw0e04 zWa3kaUrudGzz8H7C3oIfOsJLdrP3LwKscmqyR4fuOGQFJRyW4XkzJr5ik96lDLwkmMD jp3c1SwEqRSe062NzEJbKKa1tLDj/jhIlDkTNHoxWQE4GcqH1AZ3h6ZEbExckCnlUqu+ rPrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from :dkim-signature; bh=SYdtMX0fUBJBGCRkZrx91FiJtXR+g6Dfi9TegzBMeTM=; b=P+miWdS3oD5HSoW5WL1tfmGGeggLpp43aWyVxD3a6++U3OAkRLx8zVConf1Zwiqg7Y dw1Zk2UsJL6DH19Y6/WIJjFR7M7ypLgHPkm/LTvWpV/IaPFXtvh/lC6UNAYQRRG0pZKE ruptUCEQabae/6R2XeBD6/OvETRfS3LfxmtGasztvDUHOmUvpiX8dVblxntIcymB7OMl W+2D2rtpKuI9fWZR6vAgphk3kg0+NZFODLtAe6F4RfeFxz61MpfxcT6zFAxLuoGA27bI t9csJOu5PhuhtVj2TB4+P/bXjCDiWlluW4U1uZWXZk9NQ3ZHI5OqgZS9ewe98/1bqEjc FU+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=qdSVARpo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id ct27-20020a056a000f9b00b004fac7e6ea02si3357304pfb.355.2022.03.25.13.04.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Mar 2022 13:04:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=qdSVARpo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id EE1B43C1C95; Fri, 25 Mar 2022 11:55:56 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348394AbiCXI2N (ORCPT + 99 others); Thu, 24 Mar 2022 04:28:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242495AbiCXI2M (ORCPT ); Thu, 24 Mar 2022 04:28:12 -0400 Received: from m12-12.163.com (m12-12.163.com [220.181.12.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E76029BAF8 for ; Thu, 24 Mar 2022 01:26:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=SYdtMX0fUBJBGCRkZr x91FiJtXR+g6Dfi9TegzBMeTM=; b=qdSVARpouAfRPbGS+iy46sNTs3+sdaXlS8 FC1UgeHYkfoW6IvAoxmthn9A6gAw44Y/MsSgjgi6wH7kCt59QxrAxbSSlDhbEfa8 C5HaMRAu0SWQaHwu8lQ7F0FkiDChh6myl+Z5NiE5BVZ+qZWbivKFeqMZ/ljIF7lB lgVo2TGsA= Received: from localhost (unknown [159.226.95.33]) by smtp8 (Coremail) with SMTP id DMCowAD3_zc3KzxicLj8Bg--.28399S2; Thu, 24 Mar 2022 16:26:32 +0800 (CST) From: QintaoShen To: Felix.Kuehling@amd.com Cc: amd-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org, QintaoShen Subject: [PATCH v1] drm/amdkfd: Check for potential null return of kmalloc_array() Date: Thu, 24 Mar 2022 16:26:23 +0800 Message-Id: <1648110383-3533-1-git-send-email-unSimple1993@163.com> X-Mailer: git-send-email 2.7.4 X-CM-TRANSID: DMCowAD3_zc3KzxicLj8Bg--.28399S2 X-Coremail-Antispam: 1Uf129KBjvdXoW7GF4kWF17uF47Ar1kArWDurg_yoWftrg_Gr 15Xr9xAr4DCFn5Wry2vw4aqry0yr4rZ3WkXF18t3WfJryfZFyUC348XrWkZ3yfGa4DuFyD tw4DKF4fuFsF9jkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7sR_GYL3UUUUU== X-Originating-IP: [159.226.95.33] X-CM-SenderInfo: 5xqvxz5sohimizt6il2tof0z/xtbCbgjNH2BbCZsoFAAAsh X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 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