Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp4450599pxb; Thu, 14 Oct 2021 05:33:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx7o845wows41GXn4DnMV/oA2AQh94IgwS7ERSiGkzQC2DxMokmNX5b0oqdoXP/T6yaaukI X-Received: by 2002:aa7:cac2:: with SMTP id l2mr8373887edt.168.1634214785080; Thu, 14 Oct 2021 05:33:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634214785; cv=none; d=google.com; s=arc-20160816; b=GaSnUtpk0lwr3b2sorG+z7xViGRDq9P9bBxkdJLlaZvumoDIxZ0j9AiOee8FbY1tdt PQoIy9LRxQxov+5LA+JoxsTc5Yc1YZO7tluA3Oq6vndwXeDByStiO3cHVuPygH4qN6s6 OSHDpu0yvRwX2kW3g9vZOSNWbMA2+GKZVT6fqWWslrcDwQ/1Ki6CpZHuutyJ47//ltYY FbN+QHFideXY6Azz62Bx9+pl/n1SxOTCRfAq3Pn9XBkYqGZOYTndkhu5cNBY80Pf+Uq7 CygqpJ2irzipoU5dfYavZzPauzRZH4spnNQIeqH53LhXO3BEFcx8RrkEmVfJ7Ks6qMPJ CR/A== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=xjtTKqJNAW9TAfK1opWSOcT+9CXDZRVrcJjqizIFop8=; b=B5a7EK4OkGeh6Si0igSj0jTViDIaQ1jQhSfjml0qogb0ajU4lhDYiReQHTxs+RfEt0 R7cK245kZ8W+Vyd1/tADqu4JPsRD4wcvGt0qRCe8dNkPF4rPj5E4xn8IX76Vp9ToD2tQ awMkS4HC6o48M1evDbTaVBDqScoNYBgWB+hFqF3q/+pjkUSG/rhjgB3t/RGAiMHbXc/O 3RI5UeSJf/y6rGOiijj+lS6Qi6Aq7UlUPKRw1fCtns6qmsmusVoUj+aQALKMy+JxVQuc kckZlLk76VmRB7f9HpOKL/0RVDjzZLQVKojZjrlVpZj5dzX7iXnzOcYM3e3pOf3PJaj1 ZFSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=VdsdzRAn; 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=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l25si3315284ejr.445.2021.10.14.05.32.38; Thu, 14 Oct 2021 05:33:05 -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; dkim=pass header.i=@chromium.org header.s=google header.b=VdsdzRAn; 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=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231417AbhJNMGh (ORCPT + 99 others); Thu, 14 Oct 2021 08:06:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231409AbhJNMGh (ORCPT ); Thu, 14 Oct 2021 08:06:37 -0400 Received: from mail-pg1-x52d.google.com (mail-pg1-x52d.google.com [IPv6:2607:f8b0:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8F515C061570 for ; Thu, 14 Oct 2021 05:04:32 -0700 (PDT) Received: by mail-pg1-x52d.google.com with SMTP id d23so5319118pgh.8 for ; Thu, 14 Oct 2021 05:04:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xjtTKqJNAW9TAfK1opWSOcT+9CXDZRVrcJjqizIFop8=; b=VdsdzRAnoo6T3oe5ardLdZQTZfHNI7s0aObN2E47puJxRGKkUA0aqL/OuTMkAqV8v8 Kbs/GAGctRezd7TcrMxuBUIHbGiVWwTZs2n8LWJLdOGaOjQg69LHDXh5e/WMJkhd4rHc /pB+N/2EBvXkvvsiB8ja2gf9a+ZtlCoe+vSS0= 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=xjtTKqJNAW9TAfK1opWSOcT+9CXDZRVrcJjqizIFop8=; b=Z4pg+lG87lkJrsEvRjU+BaatuVc7+cl7awDzN8RSvVweGkjz/kMWTWdxp3bCSdvZCC YfmWZNKEv4Q3TWYnFae+sLwnMkdMtqDbGohxMnTlNI5Bz4t2tSbxVrSD/4PX/lbGSf0C ZiAfRo9PHgnu+upAuFkpFPQbZ30DPp+8Jt28D7q6wCYo+CgssZf4oOLMNkOXrwiOEIwk MU3klJCbIJylJhIFipYes5DW3H9Z6b8zXENPud4vgSMPY65t/UHarSUpLMJ9dhHiGiCO zPnbRsObc+aEiXmTaTrYsvI3HtWDawV/95wTOrC5nZmPWqgUFfr2TC2bosK7muaYMB3p yALA== X-Gm-Message-State: AOAM533tBH6gB7MJIHdAd2x7dTmEv8u33ehmaGLyQ/LWvxVzhRkQJg1o L+CO4pYDDLr1C3AyO+S+pqxsFA== X-Received: by 2002:a63:3481:: with SMTP id b123mr3910867pga.230.1634213072117; Thu, 14 Oct 2021 05:04:32 -0700 (PDT) Received: from fshao-glinux.tpe.corp.google.com ([2401:fa00:1:10:64c0:3f2d:5152:a6f1]) by smtp.gmail.com with ESMTPSA id b11sm2300275pge.57.2021.10.14.05.04.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Oct 2021 05:04:31 -0700 (PDT) From: Fei Shao To: Jassi Brar Cc: Chun-Kuang Hu , Tzung-Bi Shih , Fei Shao , Jassi Brar , Matthias Brugger , "jason-jh.lin" , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org Subject: [PATCH v2 2/2] mailbox: mtk-cmdq: Fix local clock ID usage Date: Thu, 14 Oct 2021 20:03:52 +0800 Message-Id: <20211014120352.1506321-3-fshao@chromium.org> X-Mailer: git-send-email 2.33.0.882.g93a45727a2-goog In-Reply-To: <20211014120352.1506321-1-fshao@chromium.org> References: <20211014120352.1506321-1-fshao@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In the probe function, the clock IDs were pointed to local variables which should only be used in the same code block, and any access to them after the probing stage becomes an use-after-free case. Since there are only limited variants of the gce clock names so far, we can just declare them as static constants to fix the issue. Fixes: 85dfdbfc13ea ("mailbox: cmdq: add multi-gce clocks support for mt8195") Signed-off-by: Fei Shao --- Changes in v2: - Make clock names static drivers/mailbox/mtk-cmdq-mailbox.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/drivers/mailbox/mtk-cmdq-mailbox.c b/drivers/mailbox/mtk-cmdq-mailbox.c index f3e52dddd422..95ce7275641c 100644 --- a/drivers/mailbox/mtk-cmdq-mailbox.c +++ b/drivers/mailbox/mtk-cmdq-mailbox.c @@ -532,7 +532,8 @@ static int cmdq_probe(struct platform_device *pdev) struct device_node *phandle = dev->of_node; struct device_node *node; int alias_id = 0; - char clk_name[4] = "gce"; + static const char * const clk_name = "gce"; + static const char * const clk_names[] = { "gce0", "gce1" }; cmdq = devm_kzalloc(dev, sizeof(*cmdq), GFP_KERNEL); if (!cmdq) @@ -570,12 +571,9 @@ static int cmdq_probe(struct platform_device *pdev) if (cmdq->gce_num > 1) { for_each_child_of_node(phandle->parent, node) { - char clk_id[8]; - alias_id = of_alias_get_id(node, clk_name); if (alias_id >= 0 && alias_id < cmdq->gce_num) { - snprintf(clk_id, sizeof(clk_id), "%s%d", clk_name, alias_id); - cmdq->clocks[alias_id].id = clk_id; + cmdq->clocks[alias_id].id = clk_names[alias_id]; cmdq->clocks[alias_id].clk = of_clk_get(node, 0); if (IS_ERR(cmdq->clocks[alias_id].clk)) { dev_err(dev, "failed to get gce clk: %d\n", alias_id); -- 2.33.0.882.g93a45727a2-goog