From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753186AbcJMIwW (ORCPT ); Thu, 13 Oct 2016 04:52:22 -0400 Received: from aserp1040.oracle.com ([141.146.126.69]:29611 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752554AbcJMIwO (ORCPT ); Thu, 13 Oct 2016 04:52:14 -0400 Date: Thu, 13 Oct 2016 11:50:24 +0300 From: Dan Carpenter To: Andrew Morton , Akash Goel Cc: Thomas Gleixner , Al Viro , Sebastian Andrzej Siewior , Richard Weinberger , Zhouyi Zhou , Peter Zijlstra , linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [patch] relay: check array offset before using it Message-ID: <20161013084947.GC16198@mwanda> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.6.0 (2016-04-01) X-Source-IP: userv0021.oracle.com [156.151.31.71] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Smatch complains that we started using the array offset before we checked that it was valid. Fixes: 017c59c042d0 ('relay: Use per CPU constructs for the relay channel buffer pointers') Signed-off-by: Dan Carpenter diff --git a/kernel/relay.c b/kernel/relay.c index da79a10..8f18d31 100644 --- a/kernel/relay.c +++ b/kernel/relay.c @@ -809,11 +809,11 @@ void relay_subbufs_consumed(struct rchan *chan, { struct rchan_buf *buf; - if (!chan) + if (!chan || cpu >= NR_CPUS) return; buf = *per_cpu_ptr(chan->buf, cpu); - if (cpu >= NR_CPUS || !buf || subbufs_consumed > chan->n_subbufs) + if (!buf || subbufs_consumed > chan->n_subbufs) return; if (subbufs_consumed > buf->subbufs_produced - buf->subbufs_consumed)