From patchwork Wed Nov 22 09:35:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lu Yao X-Patchwork-Id: 168224 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2b07:b0:403:3b70:6f57 with SMTP id io7csp1203051vqb; Wed, 22 Nov 2023 01:36:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IGUmaGhiuhIMvv6NeHqg7wPKS8e66blkTddfQLAWcF9UUYMIiP6NeL6au7Bk1m58wmFMeeN X-Received: by 2002:a0d:d489:0:b0:5cb:7603:5f2c with SMTP id w131-20020a0dd489000000b005cb76035f2cmr1636443ywd.21.1700645811463; Wed, 22 Nov 2023 01:36:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700645811; cv=none; d=google.com; s=arc-20160816; b=JouzV3G/V8UZD68jHTBShySxXKiCc8ZM1AiFNc//k8xQD7VKxykn7Wyuwojs6x5C4x J8NJDTKo17fRX9BL4JhVYFgnB2SN78C0TI/gIJ7pw/sYRP/oloBDQJE/uQ87TFpsVffY AkGneR053e8hSXB3Nd3eARX5tSUeFc05UNCwePHxYNRvQl22zf+bTxPiqvbTrRSYXQS/ lcQQhZVdXMnJFmoe2xoMJwF79siZFEIEH8UvZ6Z4YCHBnoOHAYR4qFpBYDQ44ISOF/Pt PQW9rpPsCAhZk5h8kMSwg6XeLFd1/roqEQ5Dbs3tlXSeKgvHtfv7389+bIcZCs11kk3J gSWw== 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; bh=D4MBYEmrWo4ddY39CuyTjHXChclDj60my7lVW64pRkI=; fh=0I9Fs0hz9FnAYUJK30wLjFqYlKg7bITs598AIIhcbfk=; b=GNvm3bfBINregob46sQqDxQlpL6WWfEWJJcBiwAle8XP7RM44J6GCwP6nAZqX4uh3V 394YvTHu2A1Nd3fu9GlZJj1pYLJrLb9TFNd0Csd16k3O+f3m7jPR2OBwCqh0a1007L2z rJVF+k3vsJmg/xrQoXA4TgnHz84pXWOHrTbI3rPJDfXqFi32zR9JYzUdzRGt1N5YeSYl V9XHU2FjQbtHeyRt/hyRLs6mmUdmF02qVRQhiW6j+E/GrvoQPSRx22F6Rj3ulu4Ls8C2 JZ3kLgQCipCC9IHN04eUD0ajSbQW+1VPuG4vcVE6Xd0l/KI0nKRqxUdWk46Clw5azqu3 MIUA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id z12-20020a63e10c000000b005be00724141si11645019pgh.533.2023.11.22.01.36.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 01:36:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 74FC5808A8FD; Wed, 22 Nov 2023 01:35:31 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230181AbjKVJfb (ORCPT + 99 others); Wed, 22 Nov 2023 04:35:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35640 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229995AbjKVJfa (ORCPT ); Wed, 22 Nov 2023 04:35:30 -0500 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8DEAD56 for ; Wed, 22 Nov 2023 01:35:23 -0800 (PST) X-UUID: de93d3d6b16c4117a8e2d97be02e7a9a-20231122 X-CID-CACHE: Type:Local,Time:202311221730+08,HitQuantity:1 X-CID-O-RULE: Release_Ham X-CID-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.32,REQID:5f909ea2-bb5f-4f66-9788-b653b008008f,IP:15, URL:0,TC:0,Content:0,EDM:-30,RT:0,SF:-15,FILE:0,BULK:0,RULE:Release_Ham,AC TION:release,TS:-30 X-CID-INFO: VERSION:1.1.32,REQID:5f909ea2-bb5f-4f66-9788-b653b008008f,IP:15,UR L:0,TC:0,Content:0,EDM:-30,RT:0,SF:-15,FILE:0,BULK:0,RULE:Release_Ham,ACTI ON:release,TS:-30 X-CID-META: VersionHash:5f78ec9,CLOUDID:a188d2fc-4a48-46e2-b946-12f04f20af8c,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:44|66|24|17|19|102,TC:nil,Content:0, EDM:2,IP:-2,URL:0,File:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0, LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0 X-CID-BVR: 0,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR,TF_CID_SPAM_FAS,TF_CID_SPAM_FSD,TF_CID_SPAM_FSI X-UUID: de93d3d6b16c4117a8e2d97be02e7a9a-20231122 X-User: yaolu@kylinos.cn Received: from localhost.localdomain [(116.128.244.169)] by mailgw (envelope-from ) (Generic MTA) with ESMTP id 891554106; Wed, 22 Nov 2023 17:35:12 +0800 From: Lu Yao To: airlied@gmail.com, daniel@ffwll.ch Cc: alexander.deucher@amd.com, christian.koenig@amd.com, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Lu Yao Subject: [PATCH] drm/amdgpu: Fix cat debugfs amdgpu_regs_didt causes kernel null pointer Date: Wed, 22 Nov 2023 17:35:09 +0800 Message-Id: <20231122093509.34302-1-yaolu@kylinos.cn> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Wed, 22 Nov 2023 01:35:31 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783256382257312095 X-GMAIL-MSGID: 1783256382257312095 For 'AMDGPU_FAMILY_SI' family cards, in 'si_common_early_init' func, init 'didt_rreg' and 'didt_wreg' to 'NULL'. But in func 'amdgpu_debugfs_regs_didt_read/write', using 'RREG32_DIDT' 'WREG32_DIDT' lacks of relevant judgment. And other 'amdgpu_ip_block_version' that use these two definitions won't be added for 'AMDGPU_FAMILY_SI'. So, add null pointer judgment before calling. Signed-off-by: Lu Yao --- drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c index a53f436fa9f1..797d7d3bfd50 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c @@ -638,6 +638,11 @@ static ssize_t amdgpu_debugfs_regs_didt_read(struct file *f, char __user *buf, if (size & 0x3 || *pos & 0x3) return -EINVAL; + if (adev->didt_rreg == NULL) { + dev_err(adev->dev, "%s adev->didt_rreg is null!\n", __FUNC__); + return -EPERM; + } + r = pm_runtime_get_sync(adev_to_drm(adev)->dev); if (r < 0) { pm_runtime_put_autosuspend(adev_to_drm(adev)->dev); @@ -694,6 +699,11 @@ static ssize_t amdgpu_debugfs_regs_didt_write(struct file *f, const char __user if (size & 0x3 || *pos & 0x3) return -EINVAL; + if (adev->didt_wreg == NULL) { + dev_err(adev->dev, "%s adev->didt_wreg is null!\n", __FUNC__); + return -EPERM; + } + r = pm_runtime_get_sync(adev_to_drm(adev)->dev); if (r < 0) { pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);