Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1224894pxb; Wed, 27 Oct 2021 22:53:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx4XgwhFzBfuIHl42hePK54JZT5277lbq4zRdnG50HZC4LhkmOsCCGxmTgzw7bbR/zd+V7D X-Received: by 2002:a50:9f8b:: with SMTP id c11mr3211954edf.251.1635400407739; Wed, 27 Oct 2021 22:53:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635400407; cv=none; d=google.com; s=arc-20160816; b=XAYK5z1O7ouB2jdR3UjxRNOCxYd+W7epvHLvbyOuLP7zug5Ej7z2X1Izq7Gx0iy/a0 65i/+X+9inVEiRMwhAOCOAWFwi/6LYXOrE7SrUMMwPxoYPQmFPmCocpvKN/QUlYP9tyu A+Vt0kUKtDS6c9qWAO8+bEF2cmoigFwSqTSWwnepi2VGBW7Q1VWNOyH+4exqf1HTgzZ8 CaOlQ7K/sZRwuOEjFH4AVUswNbvbNhwRXlJdR09U7H9latiQhIIytDyWFWhw3gjWtLdm s61SMjYhwu2MmFB8BqsoT/+Qv4Xn1Nw898eYHnd36rSjTK4CCTe6r9dvOgmHHFy5O2Z1 mp3A== 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=mmVZfFS5oXVGFlmYunvDJof2HCrlfwzuBJZ64Vqfoi4=; b=mo3sJZW4Ie9VfdbGj9Xr4l7ZnH4B1bAemrm5k6U/MbqrzsNswasdOW+RxZZWJ9AnhQ F08czkooD0rGtepQoT6HdgK8vjD5j9tCQzde5M2pdA6nK6w964fm3AOSHVBwAz+k9ui1 pGPKvy0h1IlDM2yqq5x0V2ek5o7QjQ7PlkS5c7CgF6Zxwxzz+iCJHZk+XIsH6RmaQKNa 0zj2g7425q1AiqBZonk0BMQCtPEPa02+C0d2u9SS9Y2rK12H182bfzvn2AKDhy9ggbKm uI2sLgX0Ez6/Sw77z2Ux9/pnOd9oD2nABUOz9sxk2Ahm8pI1mxyYc+q8TFQtvUyJtIhd 0VJQ== 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 t1si3012913edd.159.2021.10.27.22.53.03; Wed, 27 Oct 2021 22:53:27 -0700 (PDT) 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 S229784AbhJ1Fxb (ORCPT + 99 others); Thu, 28 Oct 2021 01:53:31 -0400 Received: from mailgw02.mediatek.com ([210.61.82.184]:33612 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S229586AbhJ1Fxb (ORCPT ); Thu, 28 Oct 2021 01:53:31 -0400 X-UUID: 40e1470920704bad80456c6b63ae08c7-20211028 X-UUID: 40e1470920704bad80456c6b63ae08c7-20211028 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 1816670345; Thu, 28 Oct 2021 13:51:00 +0800 Received: from mtkmbs10n1.mediatek.inc (172.21.101.34) 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; Thu, 28 Oct 2021 13:50:59 +0800 Received: from localhost.localdomain (10.17.3.154) by mtkmbs10n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.792.15 via Frontend Transport; Thu, 28 Oct 2021 13:50:58 +0800 From: Yong Wu To: Krzysztof Kozlowski , Matthias Brugger CC: Krzysztof Kozlowski , Joerg Roedel , Will Deacon , Robin Murphy , "Tomasz Figa" , , , , , , , , , , , Ikjoon Jang Subject: [PATCH] memory: mtk-smi: Fix a null dereference for the ostd Date: Thu, 28 Oct 2021 13:50:56 +0800 Message-ID: <20211028055056.26378-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 abort 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, it is also a valid value, thus, use the larb->larb_gen->ostd as the condition inside the "for" loop. Signed-off-by: Yong Wu --- Hi Krzysztof, Could you help review and conside this as a fix for the mt8195 patchset? The mt8195 patchset are not in mainline, thus, I don't know its sha-id, and don't add Fixes tag. Thanks --- 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..0262a59a2d6e 100644 --- a/drivers/memory/mtk-smi.c +++ b/drivers/memory/mtk-smi.c @@ -257,7 +257,7 @@ static void mtk_smi_larb_config_port_gen2_general(struct device *dev) if (MTK_SMI_CAPS(flags_general, MTK_SMI_FLAG_SW_FLAG)) writel_relaxed(SMI_LARB_SW_FLAG_1, larb->base + SMI_LARB_SW_FLAG); - for (i = 0; i < SMI_LARB_PORT_NR_MAX && larbostd && !!larbostd[i]; i++) + for (i = 0; i < SMI_LARB_PORT_NR_MAX && larb->larb_gen->ostd && !!larbostd[i]; i++) writel_relaxed(larbostd[i], larb->base + SMI_LARB_OSTDL_PORTx(i)); for_each_set_bit(i, (unsigned long *)larb->mmu, 32) { -- 2.18.0