From patchwork Fri Feb 5 16:35:15 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Shishkin X-Patchwork-Id: 61330 Delivered-To: patch@linaro.org Received: by 10.112.43.199 with SMTP id y7csp69917lbl; Fri, 5 Feb 2016 08:38:41 -0800 (PST) X-Received: by 10.98.32.150 with SMTP id m22mr14108852pfj.27.1454690321490; Fri, 05 Feb 2016 08:38:41 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h8si24874727pfh.96.2016.02.05.08.38.40; Fri, 05 Feb 2016 08:38:41 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755399AbcBEQia (ORCPT + 30 others); Fri, 5 Feb 2016 11:38:30 -0500 Received: from mga04.intel.com ([192.55.52.120]:9532 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754738AbcBEQiV (ORCPT ); Fri, 5 Feb 2016 11:38:21 -0500 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga104.fm.intel.com with ESMTP; 05 Feb 2016 08:38:20 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.22,401,1449561600"; d="scan'208";a="906330068" Received: from um.fi.intel.com (HELO localhost) ([10.237.72.212]) by orsmga002.jf.intel.com with ESMTP; 05 Feb 2016 08:38:18 -0800 From: Alexander Shishkin To: Greg KH Cc: Mathieu Poirier , Chunyan Zhang , laurent.fert@intel.com, yann.fouassier@intel.com, linux-kernel@vger.kernel.org, Alexander Shishkin Subject: [QUEUED v0 06/19] stm class: Fix an off-by-one in master array allocation Date: Fri, 5 Feb 2016 18:35:15 +0200 Message-Id: <1454690128-21994-7-git-send-email-alexander.shishkin@linux.intel.com> X-Mailer: git-send-email 2.7.0.rc3 In-Reply-To: <1454690128-21994-1-git-send-email-alexander.shishkin@linux.intel.com> References: <1454690128-21994-1-git-send-email-alexander.shishkin@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Chunyan Zhang Since both sw_start and sw_end are master indices, the size of array that holds them is sw_end - sw_start + 1, which the current code gets wrong, allocating one item less than required. This patch corrects the allocation size, avoiding potential slab corruption. Signed-off-by: Chunyan Zhang [alexander.shishkin@linux.intel.com: re-wrote the commit message] Signed-off-by: Alexander Shishkin --- drivers/hwtracing/stm/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.7.0 diff --git a/drivers/hwtracing/stm/core.c b/drivers/hwtracing/stm/core.c index ddcb606ace..40a8b79ab7 100644 --- a/drivers/hwtracing/stm/core.c +++ b/drivers/hwtracing/stm/core.c @@ -618,7 +618,7 @@ int stm_register_device(struct device *parent, struct stm_data *stm_data, if (!stm_data->packet || !stm_data->sw_nchannels) return -EINVAL; - nmasters = stm_data->sw_end - stm_data->sw_start; + nmasters = stm_data->sw_end - stm_data->sw_start + 1; stm = kzalloc(sizeof(*stm) + nmasters * sizeof(void *), GFP_KERNEL); if (!stm) return -ENOMEM;