Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5593719imu; Tue, 29 Jan 2019 23:45:32 -0800 (PST) X-Google-Smtp-Source: ALg8bN70lMP7WL77enOciBS5qzQIfrB3nzS/VmTMMgMsYK4DuSIqdfZ+9TMpPv5+HIWISpNM+TGa X-Received: by 2002:a17:902:9a9:: with SMTP id 38mr28847321pln.204.1548834332034; Tue, 29 Jan 2019 23:45:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548834332; cv=none; d=google.com; s=arc-20160816; b=RrONsy4LvGavG8ihCZ+R6V6UXaXM04dWGmkVTTAxwL6qvoPlqp/+MEUpDc/ixswid+ ShjclET/b0dW/A5dCUu30WYlyQ2l/IZs7XwlkQuN4ltliAbqFm+B9S+u2Ya1kio1czR6 4vJuUU/6tlBx9RyJLC83X0Cu95xeCmosaRk8L2QO+emFVudX1S1ecA5nu0YMwm2FPtHH oTiTkrMBeAtatBaiE7RYeo1O55nS/vdHTvFAI/AJc/GUzz8aFWXdWNOEGwKQoVXgkg5m JezmkvGnYs+nNp614iziyJqGbfqYweIy5RYxMluo5pHLL6yE5rS35yIQzIPbVuTDGPWr jfJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=X4QCf+1aoDy366tLdrMDAEPagCHQZQgMBcUSlcgghUw=; b=riCrzIs4vheGU3rSGS8C0hPnOII5gMBtP1UGA+9FRJ7yr3XVFCR4AK/6pINveQK+R0 0+zhIwxXlRVHZGXn0G7axP+++BMJys8quiA5s9vPktJhl3QjtPaVpvv2chBgzhUq7/Pg v85UjbcX6BCJn0kyfcw0bKvGpTNfKYm+viRtSpsaw1IKc4Cinw0tFjLWMU0P7wU2/l+w 9pn0+hr/oSBnOU/E85vbIGi7bwIWs/5kZnXiF7uQp9v64lj81/rWjTDqMtAEu2boKKNs PI/ip0P2VQMg8UPX7oWKfTzy599vui3IPUNXRuQ0cpJWnVcz/1+rQg3y/YlLK/A7OtyP lFtw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="MF08K1N/"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d25si730965pgd.88.2019.01.29.23.45.11; Tue, 29 Jan 2019 23:45:31 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="MF08K1N/"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730141AbfA3Hof (ORCPT + 99 others); Wed, 30 Jan 2019 02:44:35 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:43987 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725819AbfA3Hof (ORCPT ); Wed, 30 Jan 2019 02:44:35 -0500 Received: by mail-wr1-f65.google.com with SMTP id r10so24842978wrs.10 for ; Tue, 29 Jan 2019 23:44:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=X4QCf+1aoDy366tLdrMDAEPagCHQZQgMBcUSlcgghUw=; b=MF08K1N/yysxuch0gDLytcVb4nyipvQoeLO0UEoO7ZgkE6iICkQlj1PVmsYMRRKISh 4u7NMtuiJAX05C+FeNzFdu5NtQEICje2nF3CeBqE0Qjoc/YPNJ2ssbb52oPp/M8vkPGl yeo9NwGD6DwCo1MB/+kD27xOEbQ1yNSmt6gjw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=X4QCf+1aoDy366tLdrMDAEPagCHQZQgMBcUSlcgghUw=; b=jY8aaZpYxypFMzl85G2iLZIAydkeRvY2KLix+a9DOG5JI6U0RxA9WP+XJLd4qjdtJV auKU7oSJhkoUpLEOsVVbvjdIufgb5d80I7Ofpmw+erCICzSJubQBAYwJN9U/JNNE95Xz Jmz9Rr/sSdQxrBmNQ2H6MohiaRqjVeds+P+WoMMuro6i1DSQDAsAhvCtnpywVgJc3nI1 yno3b8ddVdh8f7NT1ZyuiFBEWW8L96Oir4pIDgRlDHQLNFsRU6Cu2KethJ4TiP0Gwpu3 LJs8E40a4J0TW3L8rmNMTz18MukWxLoCbqumCQkupReMizTPXzOFTNGgk83ne74k8m1y pO8g== X-Gm-Message-State: AHQUAuYHS2MDNl+WdG6mtN9/jRTpxPUTiHpU0ZwWvBV99l/l8mRoW++A 7igAhRDT2WNcqzcSUamTVNLU2w== X-Received: by 2002:a5d:678b:: with SMTP id v11mr7013843wru.245.1548834273590; Tue, 29 Jan 2019 23:44:33 -0800 (PST) Received: from [192.168.0.41] (164.30.95.92.rev.sfr.net. [92.95.30.164]) by smtp.googlemail.com with ESMTPSA id f191sm1034950wmg.12.2019.01.29.23.44.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Jan 2019 23:44:32 -0800 (PST) Subject: Re: [PATCH] thermal: mtk: Allocate enough space for mtk_thermal. To: Peter Shih Cc: Zhang Rui , Eduardo Valentin , Matthias Brugger , "open list:THERMAL" , "moderated list:ARM/Mediatek SoC support" , "moderated list:ARM/Mediatek SoC support" , open list , Michael.Kao@mediatek.com References: <20190109055724.184692-1-pihsun@chromium.org> From: Daniel Lezcano Message-ID: <81115ad5-521e-557b-d229-1effb92068a4@linaro.org> Date: Wed, 30 Jan 2019 08:44:31 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 30/01/2019 07:04, Peter Shih wrote: > Adding Michael Kao to cc list. > > On Wed, Jan 9, 2019 at 1:57 PM Pi-Hsun Shih wrote: >> >> 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. Even if the fix is correct, it pushes back the bug later in time if a new board containing more than MAX_NUM_ZONES is introduced. I suggest to dynamically allocate the array with the 'num_banks' value. >> Signed-off-by: Pi-Hsun Shih >> --- >> 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 */ >> -- >> 2.20.1.97.g81188d93c3-goog >> -- Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog