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 6F97AC433F5 for ; Tue, 12 Apr 2022 01:04:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240864AbiDLBHE (ORCPT ); Mon, 11 Apr 2022 21:07:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345187AbiDLA63 (ORCPT ); Mon, 11 Apr 2022 20:58:29 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74CFB3389B; Mon, 11 Apr 2022 17:51:08 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 36EDDB819B4; Tue, 12 Apr 2022 00:51:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CF8D0C385AA; Tue, 12 Apr 2022 00:51:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1649724666; bh=e/J7Zh0cwREkQWVg11hQDdBOpmm8Zvf+QbJOy6b0NLM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=o8EXH3q/Y/ZXIVmFsK8CvigqwFutfcGz+Y0AJLQTXNbDGGOhe0TI550pEa9MXmJHs 2GC6TApGfEB1OSc1+Ei4Tkwo2qGYm5GAyHXHpZUuH5FUwl7UJMo9bHwf/W03X4p1Gi c5QNOsyT5s1hl9zoSbZS71FGm+iFYmw2UHxxdCdqiGKj/jFKtZxViNf26b/eI1+Sc9 wryTKCMHxwmsPBg4hNKWI9oYuFKPOoMUT/c3W949euYN5V8QN3UC3AS8WzChbkT4HT ULYe9nrjCjT+uPTSZUbJB0ZBS1wrzjmFveGm55YbIZLmrSg2oT2PiefbWoI2r/1e7i m36EjGiT118hw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: QintaoShen , Alex Deucher , Sasha Levin , Felix.Kuehling@amd.com, christian.koenig@amd.com, Xinhui.Pan@amd.com, airlied@linux.ie, daniel@ffwll.ch, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Subject: [PATCH AUTOSEL 5.4 05/21] drm/amdkfd: Check for potential null return of kmalloc_array() Date: Mon, 11 Apr 2022 20:50:24 -0400 Message-Id: <20220412005042.351105-5-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220412005042.351105-1-sashal@kernel.org> References: <20220412005042.351105-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: QintaoShen [ Upstream commit ebbb7bb9e80305820dc2328a371c1b35679f2667 ] 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 Signed-off-by: Alex Deucher Signed-off-by: Sasha Levin --- 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 d674d4b3340f..adbb2fec2e0f 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_events.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_events.c @@ -532,6 +532,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.35.1