Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp6051001pxb; Mon, 8 Nov 2021 02:17:21 -0800 (PST) X-Google-Smtp-Source: ABdhPJzy7SWO+LXjssJqIpK+gZYBAiMb2jtqntxI1bLZlwUz7EFk2M2ECUqWNhaAchTDGBO9onm7 X-Received: by 2002:a50:d8cf:: with SMTP id y15mr107090669edj.66.1636366640952; Mon, 08 Nov 2021 02:17:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636366640; cv=none; d=google.com; s=arc-20160816; b=jHtMaHT3WhsW/3/FpsVeBbVGotDqLXT16ItlS2w3Hl+Psk+nSachfZMkwoul+GO+Ic fESElP03TV2JYUVOVImbIViNBWHmRZqHfUgo1FlSUXOIoZMuOXl1xZCgSHDaoRuf6qK+ mq3IQuDINBISqTkkCfnli98ARe9njjfQjdeqFaJihDIO3ugFjlRzONSZU8m868t6gAQj dhKj3R6oCmuGAyq1IAKVdsNplKyI45QRP9wsK0/xqT2NRE2oR0LzZaRbZ7GXI3REZkAI MJxfvs9QwsbEGQEZRk5IAfdAVw5VtyW3qkJT6WA3oNLBd81GDVLMqO9D5qH49vS4Tkw+ uh3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=1tdqGQE0yB6/FDR2k8LU0CY75sXD4hVBQDy0/56DCDY=; b=jC9HhAvLYwHvDqNy326vvPGKZaHIQMRRjAAE3VnV8d5LbnU9zT510ZZqVOUTipU6Vt mq8TroA6oJ2Gz2fp41zEHwchwtLDCjrotxVCWq3FVqZfapdrE3JtidqJIMt4dTmAAmSK et/oHzuXaqaZA8+9eiLyehWsCYNPtVqDfHqBoKyXRPH/ThL4DrJ5lV6hxxkWITees5tX n2Ari63Kl1PWpX+itSvz05OWzhMcwVVR9uywNkxKtEMJrQSLW9GkmV6UiqiNTV2eOZSk iaEc0UZituYhJMYVPAMjr8/p90vXCv1hoNzRF8TIr0NvwEcTe+lN2dZXusOPWl6FKVTp dCXg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b13si19151538edz.312.2021.11.08.02.16.50; Mon, 08 Nov 2021 02:17:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236537AbhKHI1Z (ORCPT + 99 others); Mon, 8 Nov 2021 03:27:25 -0500 Received: from mailgw02.mediatek.com ([210.61.82.184]:55112 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S235830AbhKHI1Y (ORCPT ); Mon, 8 Nov 2021 03:27:24 -0500 X-UUID: 7f2e25ffd2c746c1928d5b134a5e2d14-20211108 X-UUID: 7f2e25ffd2c746c1928d5b134a5e2d14-20211108 Received: from mtkmbs10n1.mediatek.inc [(172.21.101.34)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1300905659; Mon, 08 Nov 2021 16:24:37 +0800 Received: from mtkmbs10n2.mediatek.inc (172.21.101.183) by mtkmbs10n1.mediatek.inc (172.21.101.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.792.15; Mon, 8 Nov 2021 16:24:36 +0800 Received: from localhost.localdomain (10.17.3.154) by mtkmbs10n2.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.792.3 via Frontend Transport; Mon, 8 Nov 2021 16:24:35 +0800 From: Yong Wu To: Krzysztof Kozlowski , Matthias Brugger CC: Krzysztof Kozlowski , Joerg Roedel , Will Deacon , Robin Murphy , "Tomasz Figa" , , , , , , , , , , , Ikjoon Jang , Hsin-Yi Wang Subject: [PATCH v2] memory: mtk-smi: Fix a null dereference for the ostd Date: Mon, 8 Nov 2021 16:24:29 +0800 Message-ID: <20211108082429.15080-1-yong.wu@mediatek.com> X-Mailer: git-send-email 2.18.0 MIME-Version: 1.0 Content-Type: text/plain X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We add the ostd setting for mt8195. It introduces a KE for the previous SoC which doesn't have ostd setting. This is the log: Unable to handle kernel NULL pointer dereference at virtual address 0000000000000080 ... pc : mtk_smi_larb_config_port_gen2_general+0x64/0x130 lr : mtk_smi_larb_resume+0x54/0x98 ... Call trace: mtk_smi_larb_config_port_gen2_general+0x64/0x130 pm_generic_runtime_resume+0x2c/0x48 __genpd_runtime_resume+0x30/0xa8 genpd_runtime_resume+0x94/0x2c8 __rpm_callback+0x44/0x150 rpm_callback+0x6c/0x78 rpm_resume+0x310/0x558 __pm_runtime_resume+0x3c/0x88 In the code: larbostd = larb->larb_gen->ostd[larb->larbid], if "larb->larb_gen->ostd" is null, the "larbostd" is the offset(e.g. 0x80 above), it's also a valid value, then accessing "larbostd[i]" in the "for" loop will cause the KE above. To avoid this issue, initialize "larbostd" to NULL when the SoC doesn't have ostd setting. Signed-off-by: Yong Wu --- change note: Reword the commit message to show why it KE. and update the solution via initializing "larbostd" is NULL explicitly in the non-ostd case. --- drivers/memory/mtk-smi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/memory/mtk-smi.c b/drivers/memory/mtk-smi.c index b883dcc0bbfa..e201e5976f34 100644 --- a/drivers/memory/mtk-smi.c +++ b/drivers/memory/mtk-smi.c @@ -241,7 +241,7 @@ static void mtk_smi_larb_config_port_gen2_general(struct device *dev) { struct mtk_smi_larb *larb = dev_get_drvdata(dev); u32 reg, flags_general = larb->larb_gen->flags_general; - const u8 *larbostd = larb->larb_gen->ostd[larb->larbid]; + const u8 *larbostd = larb->larb_gen->ostd ? larb->larb_gen->ostd[larb->larbid] : NULL; int i; if (BIT(larb->larbid) & larb->larb_gen->larb_direct_to_common_mask) -- 2.18.0