Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5672911imu; Wed, 30 Jan 2019 01:26:20 -0800 (PST) X-Google-Smtp-Source: ALg8bN6wgOTSUEgLVhOxAADGGVYJsA5Rf7Nj9ONPTHlGiadqI9iECTz2gRDVEOcEIinNnNXQ9+RL X-Received: by 2002:a17:902:9b87:: with SMTP id y7mr29853856plp.336.1548840380875; Wed, 30 Jan 2019 01:26:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548840380; cv=none; d=google.com; s=arc-20160816; b=yt52tCm573DMD+dPI1LeC1pNEYaSdLQiRb3w2In7Npk5jLrhwWQ4PFVkL7MXs/dfQV ccFuPVYdgl0IP0rc+fQNt8XMKLinFmDp+CP7mR8EhPy13Se2BIzrtt6VhLzbuDVTWHGe Tip9roEPPDmDnh5WAWYKWq0YWOInbhQbnE4Vg5PuSH7SPglJEw0Zc8s2QnmpqDt41N8J zoQGZyRr7Fdp5dKJgoziw6XcdF0QnyPTPw5R3PJJjsY/kde9qvgWdGzee00Qo0I9L9b7 CtWleNjTVOJX2CIKTJlL9/fncrefm/GeCXwS7WVRlEXKEZMGi4HHb4nI2SAlUjnSSul0 HEEQ== 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:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=5a7NvQkWOISkNnAGXM7TAeezdcdvrRYnkbW1NYEQoWw=; b=OY7nQ3c3/dwoaYqn8NzwFilD9Kp1OClm8FYbfcsBvIgxei7RnrKDJyRLopZmPOXq3I DfGXTM8yGZyM5NpTeZLkyQtNMOtxkC699P1qgt6pgF2GiAvWnIxoEXbAgUhvuM7y/HmU eDE1MOT3ud67W7XMi6C8+A2DO2Mw9o5Lyr12jeYwtJEran2XmoTcA0g3SGCnRH/SAKZC D7QMLYJq26NxhfFxFoQZGdPlO2vvOQGpMpXlY9ttWr/Ljj/DKC9FK1icrnZvtPOiR6ZW S/gbSz9y58NeQN5Tnr0E6RqJDQvs0qvwjemmasw4LXwGFopAwru0t0zhnqRylImfvTvs 86lQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=ErO9o3wm; 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=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f12si963413pgd.68.2019.01.30.01.26.05; Wed, 30 Jan 2019 01:26:20 -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=@chromium.org header.s=google header.b=ErO9o3wm; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730213AbfA3JZk (ORCPT + 99 others); Wed, 30 Jan 2019 04:25:40 -0500 Received: from mail-ed1-f66.google.com ([209.85.208.66]:38106 "EHLO mail-ed1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730091AbfA3JZk (ORCPT ); Wed, 30 Jan 2019 04:25:40 -0500 Received: by mail-ed1-f66.google.com with SMTP id h50so18391985ede.5 for ; Wed, 30 Jan 2019 01:25:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=5a7NvQkWOISkNnAGXM7TAeezdcdvrRYnkbW1NYEQoWw=; b=ErO9o3wmAG1rh48oPZST8SDvEgdzFIqMvwpSRCPjOjyqqlur6MUak6HZl+Oy26YyOg uLoFAHxWCHYNAoQG+tt2Ovu3T26/bRS/31WTOk8maA0APDQMX6nEL+fFYbomuxvo5X30 qzsn/KqGl6vdguVGcIFERkIplb6ICppSv8F5w= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=5a7NvQkWOISkNnAGXM7TAeezdcdvrRYnkbW1NYEQoWw=; b=VrLoLwZ1jj/vR7L3WdaPvMsGp9I8+IjMICQDFlH5SFaQX5M9uNLoDLoz5MNVnAtWLj ioKFT+EIEGlmMt3qYu1HyA1MzTPCIw+Ot5ezyhTD03slqZbU51aJfGpNS1Pawydh5EzL WRrVQxADUUzP1mgk+5uFopoMIKZxXEVHFiIyQu9Uhwe7tHxYkkH0cCSIMHBxZjuxdoJR zPueNgvTHyQ8AYLqDi1Pcgq8/dBqiVxnqP8u7ihC/zYgqO/91j2kXFj1S6+i+iO9DlNA CXXsmsB9aIbqSHlUnlhvJkKkeXMnY9aqaIpIW6rAHYHkvBzxXVNwWoK1KqzSeAieCa4M ptUA== X-Gm-Message-State: AJcUukcL2zYbgh2ylOopyOxcN0Gd0tT8WVCuWjlqUefdOhF7//aAY2CI Qy2py7hwwTv/528SfawPIzSq52ClDrU4zNCu/Uh5mA== X-Received: by 2002:a17:906:4691:: with SMTP id a17mr25821356ejr.58.1548840338153; Wed, 30 Jan 2019 01:25:38 -0800 (PST) MIME-Version: 1.0 References: <20190109055724.184692-1-pihsun@chromium.org> <81115ad5-521e-557b-d229-1effb92068a4@linaro.org> In-Reply-To: <81115ad5-521e-557b-d229-1effb92068a4@linaro.org> From: Pi-Hsun Shih Date: Wed, 30 Jan 2019 17:25:27 +0800 Message-ID: Subject: Re: [PATCH] thermal: mtk: Allocate enough space for mtk_thermal. To: Daniel Lezcano 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jan 30, 2019 at 3:44 PM Daniel Lezcano wrote: > > 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 t= o > >> 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. > For the current code structure, those mtk_thermal_data are statically decla= red, so if there's new board containing more than MAX_NUM_ZONES of bank_data, it would actually be a compile error. I'm fine with either way, but feel like that this is simpler than manually calculating the size needed for allocation. > > >> 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_therm= al.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 =E2=94=82 Open source software for A= RM SoCs > > Follow Linaro: Facebook | > Twitter | > Blog >