From patchwork Wed Jan 9 05:57:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pi-Hsun Shih X-Patchwork-Id: 10753435 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7ABF66C5 for ; Wed, 9 Jan 2019 05:58:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6600E28DFC for ; Wed, 9 Jan 2019 05:58:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 534D828E03; Wed, 9 Jan 2019 05:58:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7E7BD28DFC for ; Wed, 9 Jan 2019 05:57:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=d5VPel5opW1y9J/WRZ4HFuO3w1bYUoun++xLTq0gHPA=; b=f3FZ3Yu+l0BBIs aqwO3CSALyrZey9Ir0UhrqgEwwVexsDEjA/Qg2iWP9BZ+slOotq0AkX+nYzrSDtkF2t9XqrRmepNM ezWWakoGYiOn6v4bk/r+FSDLCjahg5DqfP35dRMxxADZ18iMjC/EsrQ4vtmE0ffoAENzUyPw+cQvg /8sfpYgw7hlOGppPwbyMkqthxAF3rbbYtJ2d02CV0mYf7fPvEVzn9YcY3Xogw9MxXBlEaC8cL9NWz flViteTEbGAzVejh1Lv75gsH4+e/ZS6dFwnjQTswZh3miEl7P3BElwenqxY4h4pNxJRvvDgNko0iM vD1FlJfd18F5AlF87fgg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gh6sF-0005Gf-Pj; Wed, 09 Jan 2019 05:57:55 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gh6sE-0005GE-Kh for linux-arm-kernel@bombadil.infradead.org; Wed, 09 Jan 2019 05:57:54 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Content-Transfer-Encoding:MIME-Version: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=Aa1uCBP59MSaio3VSgOuyxVekJ64BN6jptSWeh729UM=; b=D0yS7Bc2m49xJu9yQVNKyTaTJm dFxymyYGDeqE6irk56zH85MR4Lh9WQnBOTIumvl4T+T6VmVKYWHKMAYU70veBKiNXjlWTrY0/FUzv 7+RGbM81cIlTpChmY+z9ZM5n8Owvh6456fCdZMaKcOY4Y4+x8xO5atseEky6JrkpkZcDMGlAVMpys 2dMykm5YKVceIK+wSCZ7CAWKQNj7gdUwfNnb94RfQ59c7qowKJWG37UnZZTmlh3VWlocnZ3K/Ax1A 3d9fnKVkC14te8XftZ7sbGOj56Ea+MvwTYedK+Q/gSQ3jo/cpxmuhGzaGvs2p3fvQ7acdPMpOGGO/ 0aF2kfPA==; Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]) by merlin.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gh6sB-00076C-K4 for linux-arm-kernel@lists.infradead.org; Wed, 09 Jan 2019 05:57:52 +0000 Received: by mail-pg1-x542.google.com with SMTP id d72so2818665pga.9 for ; Tue, 08 Jan 2019 21:57:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Aa1uCBP59MSaio3VSgOuyxVekJ64BN6jptSWeh729UM=; b=JRMrjNqvaANp2nwjIVi+v62CRRtIdsNdmrS4Xik+9U7Ze3Q3sZ79s8pImwHbYTgQjS Dv+rbhL7lHgHqTtv6NNNHHhY87BF4q3oM9eBrLFz9thIB3V/f8TqwV0lhqohwKlxYWDB p07mbFI5okRzpWqPFYdIgURZ1V/O/oYdbhPO8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Aa1uCBP59MSaio3VSgOuyxVekJ64BN6jptSWeh729UM=; b=E/DBrWllXEXEnppWe61pztrjQnn/PVMgCuOdEXWez1h/2Yua98fmhK0M+VB15eEnI0 O/qbnHBoRDsakUgCPBrhYnZMd78XiR+T0ue5JaTA348PAV9h0uFwb7NaqZxdfdQbCQ+z omkbWGpQfU779Sv1D9y4BLTJFNAFOufb548GgDZSocKryfeVp/Wt/3FbdcQ0B7D1IZ5o VM8VIhUxQczb92KaEh8r5fUTXBnaYTDEZeHmGFuC6uUlnzSPXNo3QpLsvpCCj45vnY/G Tdblgk72BRd7HsD2BfZKYbTqL4GNZ56Spe3bFG1USgXi6zUwMi47uarA7Do9AAjTQt1M cl/w== X-Gm-Message-State: AJcUukdsltLKRfA8KXo8sltpRioHR2yIrMw8mkO4VS0d6WTdOxvNF4dI Xq/TLMVAu1HzOOMYkj7xoEHPUA== X-Google-Smtp-Source: ALg8bN67dfDF9e4WDOng/a/8ks/+HlzffpdXluuxKI+qUAPC45qiOTRTz4GtqYR9pVsdAlmUUxwtnA== X-Received: by 2002:a63:a91a:: with SMTP id u26mr4147921pge.349.1547013465557; Tue, 08 Jan 2019 21:57:45 -0800 (PST) Received: from pihsun-z840.tpe.corp.google.com ([2401:fa00:1:10:7889:7a43:f899:134c]) by smtp.googlemail.com with ESMTPSA id i1sm102627966pgb.46.2019.01.08.21.57.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 08 Jan 2019 21:57:44 -0800 (PST) From: Pi-Hsun Shih To: Subject: [PATCH] thermal: mtk: Allocate enough space for mtk_thermal. Date: Wed, 9 Jan 2019 13:57:24 +0800 Message-Id: <20190109055724.184692-1-pihsun@chromium.org> X-Mailer: git-send-email 2.20.1.97.g81188d93c3-goog MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190109_005751_670290_4F802104 X-CRM114-Status: GOOD ( 11.64 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "open list:THERMAL" , Daniel Lezcano , open list , Eduardo Valentin , "moderated list:ARM/Mediatek SoC support" , Pi-Hsun Shih , Matthias Brugger , Zhang Rui , "moderated list:ARM/Mediatek SoC support" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The mtk_thermal struct contains a 'struct mtk_thermal_bank banks[];', but the allocation only allocates sizeof(struct mtk_thermal) bytes, which cause out of bound access with the ->banks[] member. Change it to a fixed size array instead. Signed-off-by: Pi-Hsun Shih Reviewed-by: Daniel Lezcano --- drivers/thermal/mtk_thermal.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/thermal/mtk_thermal.c b/drivers/thermal/mtk_thermal.c index 0691f260f6eabe..ea11edb3fcced6 100644 --- a/drivers/thermal/mtk_thermal.c +++ b/drivers/thermal/mtk_thermal.c @@ -159,6 +159,9 @@ #define MT7622_NUM_SENSORS_PER_ZONE 1 #define MT7622_TS1 0 +/* The maximum number of banks */ +#define MAX_NUM_ZONES 8 + struct mtk_thermal; struct thermal_bank_cfg { @@ -178,7 +181,7 @@ struct mtk_thermal_data { const int *sensor_mux_values; const int *msr; const int *adcpnp; - struct thermal_bank_cfg bank_data[]; + struct thermal_bank_cfg bank_data[MAX_NUM_ZONES]; }; struct mtk_thermal { @@ -197,7 +200,7 @@ struct mtk_thermal { s32 vts[MT8173_NUM_SENSORS]; const struct mtk_thermal_data *conf; - struct mtk_thermal_bank banks[]; + struct mtk_thermal_bank banks[MAX_NUM_ZONES]; }; /* MT8173 thermal sensor data */