Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp3440548pxb; Mon, 4 Apr 2022 17:05:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzAXB/B+9AHbkSnwIs8CWBceXCLUC95LvyahnVIdJybXtEpCSetkeGfmiUbq+kT4BAx9ETU X-Received: by 2002:a17:902:7e0e:b0:156:498d:437 with SMTP id b14-20020a1709027e0e00b00156498d0437mr761265plm.44.1649117136467; Mon, 04 Apr 2022 17:05:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649117136; cv=none; d=google.com; s=arc-20160816; b=nE4rKWbArnZ22YIWaH+v6EO3J4vJIvhtg/7eigyCU4wv5liuDt4OdRhkn1Yx1GK4/c n0NUZ8guxFzYgbi7mkLfIp6dFVphERtFFuAnLdrNqLV+eI4hLFLXq66K8x0ZnV3unqp+ QlC9c3F232uvuz4SGQEjePF0CB4mOlwU+AT9k6u81SRkrZpn0OfoKRhXNsVWTTXbvllR TnZL60DjmaP9aLNh/BiRN/Z9cKWlVVFBLTDXMHA9pY0Srgbwo0qiUhTqVQq6p2usptF5 xEN5BCtfNsFICnLQ2b/mlR7t4wXdKCdLDQovxJo21D422YdrsfWsD0/L9pmLuV9Em8pI TV9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=e3rwhB1mUhFaCfEgLZjUcCjNm+5f5fkFkvdLOTF0xYk=; b=UnJfJrM1ryyvH5j5myXEYi1DVYCeGq6aUQMHpMmjeYAOtWwTxuE11SoLmTaCkBB4RS eKN+dMqqOK2W3gNxh0slZj0xYi7guzKjUvHm4UrPd4csMUrNmpnlohDg/tw/CAzGGeNJ 3Lo6XB7aKEx5/dr6lC5HEy8SF03CyeX8rvqrdE3xGMMdmwc496ma+/u+4u4CimBc49jz pRKEvR5HPXYC2hTKTl9/sZL4kwDaP9nHGBxgrkoq342ejlIh7rMBp3JkKqvuv/iDUX8U TNa20Ru8m2XBCtTJwULycKceRNroaTmfbbCgkw4uothvmXt7NMeejNMQlztWa7uq4C/7 D70w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=P0iFhoyl; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id s20-20020a056a00195400b004fa3a8dff84si12475845pfk.59.2022.04.04.17.05.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Apr 2022 17:05:36 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=P0iFhoyl; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8C826522D2; Mon, 4 Apr 2022 16:40:13 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233326AbiDDXDe (ORCPT + 99 others); Mon, 4 Apr 2022 19:03:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348056AbiDDXCW (ORCPT ); Mon, 4 Apr 2022 19:02:22 -0400 Received: from mail-lj1-x230.google.com (mail-lj1-x230.google.com [IPv6:2a00:1450:4864:20::230]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 33E146C4A0 for ; Mon, 4 Apr 2022 15:22:07 -0700 (PDT) Received: by mail-lj1-x230.google.com with SMTP id q14so14740732ljc.12 for ; Mon, 04 Apr 2022 15:22:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=e3rwhB1mUhFaCfEgLZjUcCjNm+5f5fkFkvdLOTF0xYk=; b=P0iFhoylKXhVCWdgWMTjMyf65xZiqKqiiqn4536XFm7K4P9Ta0r/nlJa2ZwiC+a12n LSLuT9brEn/BUEFFC5GWAnVhrlfeyA9hIGXUnG9WJiMuq/PLyfQCGF2C66gRnkEK/+/W e0WoLN8Qs1s2zXNPwroDh68ftRZkYO04Dps0QAibdvREzehBAOAGVoxowB38OcI3ESLx IlDiri9w8Pk3RUThqxIFl288Atk6Wf21f7tUH9BmnEH5Aa2eAj6/ATlfCL13xk9EIcr8 /Ri3gOybzV17/GnsQmzrsdw3NOaikndrXmGL+yF/PWgFm3YtmhHclJJPI4kygMXUTLX7 0EYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=e3rwhB1mUhFaCfEgLZjUcCjNm+5f5fkFkvdLOTF0xYk=; b=H3hlnmkldLIsM6g1wyH5log8eCKJ2G+7+WxEE9FWhC8G6gkfDT29dyWlU6A3ZH6Ih0 wrbKSFG4pMreMQ/REVhYYNzU5Ambn73dyb/ojOuknn8ZPmChp3vHf8RYVemY6acIPTKY jDV6CozRzupGMh1NCyVMSCFEpTBILIUAKeLDal45w8dETrhQbuEr2VPbSrnd0eEadFIO 9RP3XR0mHULDlihHVB3tGPg52pLVFwwSBIGGAji6HgFhdiG6lbLFIq0VRGEkYTbjNxKY uxhd8EmLfdRh1j04+1pwn2j7m+CnNNQONDu0B+1VWBwfWfg+5jGe5k6Ct6Mne2Wyeecy SkaQ== X-Gm-Message-State: AOAM532boqShY9zguo29p9ZDWpklSMzAC4Acvufhz8ZoFCC8nhfCnxPg itoZI66RHRvcVXcET4U/8r0= X-Received: by 2002:a2e:9c96:0:b0:249:5f27:591a with SMTP id x22-20020a2e9c96000000b002495f27591amr172674lji.11.1649110925028; Mon, 04 Apr 2022 15:22:05 -0700 (PDT) Received: from noname.. ([2a02:2698:8c2a:1093:6d9:f5ff:fecb:a8ab]) by smtp.googlemail.com with ESMTPSA id v10-20020a2ea44a000000b002493831631csm1181068ljn.14.2022.04.04.15.22.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Apr 2022 15:22:04 -0700 (PDT) From: Grigory Vasilyev To: Rodrigo Siqueira , Melissa Wen Cc: Grigory Vasilyev , Felix Kuehling , Alex Deucher , =?UTF-8?q?Christian=20K=C3=B6nig?= , "Pan, Xinhui" , David Airlie , Daniel Vetter , amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH] drm/amdkfd: Fix potential NULL pointer dereference Date: Tue, 5 Apr 2022 01:21:32 +0300 Message-Id: <20220404222132.12740-1-h0tc0d3@gmail.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 In the amdgpu_amdkfd_get_xgmi_bandwidth_mbytes function, the peer_adev pointer can be NULL and is passed to amdgpu_xgmi_get_num_links. In amdgpu_xgmi_get_num_links, peer_adev pointer is dereferenced without any checks: peer_adev->gmc.xgmi.node_id . Signed-off-by: Grigory Vasilyev --- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c index be1a55f8b8c5..1a1006b18016 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c @@ -541,11 +541,10 @@ int amdgpu_amdkfd_get_xgmi_bandwidth_mbytes(struct amdgpu_device *dst, struct amdgpu_device *adev = dst, *peer_adev; int num_links; - if (adev->asic_type != CHIP_ALDEBARAN) + if (!src || adev->asic_type != CHIP_ALDEBARAN) return 0; - if (src) - peer_adev = src; + peer_adev = src; /* num links returns 0 for indirect peers since indirect route is unknown. */ num_links = is_min ? 1 : amdgpu_xgmi_get_num_links(adev, peer_adev); -- 2.35.1