Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753156Ab0HZMMV (ORCPT ); Thu, 26 Aug 2010 08:12:21 -0400 Received: from bombadil.infradead.org ([18.85.46.34]:60857 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751710Ab0HZMMU convert rfc822-to-8bit (ORCPT ); Thu, 26 Aug 2010 08:12:20 -0400 Subject: Re: [PATCH] perf: fix possible divide-by-zero in perf_swevent_overflow() From: Peter Zijlstra To: Dongdong Deng Cc: mingo@elte.hu, fweisbec@gmail.com, acme@redhat.com, paulus@samba.org, linux-kernel@vger.kernel.org In-Reply-To: <1282824438-13970-1-git-send-email-dongdong.deng@windriver.com> References: <1282824438-13970-1-git-send-email-dongdong.deng@windriver.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT Date: Thu, 26 Aug 2010 14:12:07 +0200 Message-ID: <1282824727.1975.747.camel@laptop> Mime-Version: 1.0 X-Mailer: Evolution 2.28.3 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1454 Lines: 40 On Thu, 2010-08-26 at 20:07 +0800, Dongdong Deng wrote: > The event->hw.last_period is possible to zero, thus it will > cause divide_by_zero later in perf_swevent_set_period(). How can it be zero? > This patch checks event->hw.last_period before invoke > perf_swevent_set_period() and replaces "event->hw" with "hwc". > > Signed-off-by: Dongdong Deng > Cc: Peter Zijlstra > Cc: Frederic Weisbecker > Cc: Arnaldo Carvalho de Melo > Cc: Paul Mackerras > --- > kernel/perf_event.c | 4 ++-- > 1 files changed, 2 insertions(+), 2 deletions(-) > > diff --git a/kernel/perf_event.c b/kernel/perf_event.c > index 403d180..ccba741 100644 > --- a/kernel/perf_event.c > +++ b/kernel/perf_event.c > @@ -4050,8 +4050,8 @@ static void perf_swevent_overflow(struct perf_event *event, u64 overflow, > struct hw_perf_event *hwc = &event->hw; > int throttle = 0; > > - data->period = event->hw.last_period; > - if (!overflow) > + data->period = hwc->last_period; > + if (!overflow && hwc->last_period) > overflow = perf_swevent_set_period(event); > > if (hwc->interrupts == MAX_INTERRUPTS) -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/