Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp18125479ybl; Thu, 2 Jan 2020 19:04:09 -0800 (PST) X-Google-Smtp-Source: APXvYqzrqJEe1K7pJQSakZJkokyipcrNIFKWAyMmIyqU95XkfjT3EuGVyhxuX4HzMxxNMAXuUujp X-Received: by 2002:aca:5905:: with SMTP id n5mr3893366oib.54.1578020649382; Thu, 02 Jan 2020 19:04:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578020649; cv=none; d=google.com; s=arc-20160816; b=X/iky16MgK9j93COX5UCnhGOlhi+NuU1ILYOw/Hs2YcBoxYSjyknbxM6yCXjKwsqNO EIAvnlkb/A/cq2W73TB2BMzjUJHxwe244++b9lo2TcRpAhqXS4UI4WzXYgWXcOG74mVu Q+HRjzGg0BsopgMoETUws4tvTNBwvMwhc6/BDcXUicFymvwohojtPS501sSJ0YpVIMtv mL2beUoecCKpxyFqk/VcC0Yuf1zDzUwMS7zMnF7IkToNPw92lfq16onNTxE8UeSqnRZR SXua4IJTxIgkoLubQAmIgyinLUminy9ZIRn6nTSfg67uff/IKo1gpclsyzFnL/YtAyvF cJVg== 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:mime-version :message-id:date:subject:cc:to:from; bh=MJU0jleVoGf+puIa6WE/tqM3Yrhnx7rBRrszJvNfnHo=; b=ybCT5NmB24e2O+haQt9fUW76H77q8CVhpp3laSzNMgzrGM+XdKQrugecRpqd75kUIc cZ5tTxTSavX6bJfO9wYzgPAJFa8xQ9RGO1TiazAVzjfQMYEB7miUSOlJKRTm4yf5LkAa 7mp436wv3WoO5lYdxTeFwF8V4b5XcVcl4LTFbSRS8BXPxXjih18QFs73FmG/qyhtRh/1 eK0DlhPCBGLdjxsUKCZEUUboaQbcWy7K1AXiusZ/Rj8gGWZzu4eKAdIcoDAF8yXcVAg/ uNjy1V22bjZVQvdvs1+0EdJvO4d3+j08lkCqnII69dOnsim8OOlUP9BgGiLPnTxvhe5Y KQeA== ARC-Authentication-Results: i=1; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f4si21599346oij.133.2020.01.02.19.03.57; Thu, 02 Jan 2020 19:04:09 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727367AbgACDDJ (ORCPT + 99 others); Thu, 2 Jan 2020 22:03:09 -0500 Received: from out30-132.freemail.mail.aliyun.com ([115.124.30.132]:60049 "EHLO out30-132.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726481AbgACDDJ (ORCPT ); Thu, 2 Jan 2020 22:03:09 -0500 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R971e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e01422;MF=wenyang@linux.alibaba.com;NM=1;PH=DS;RN=5;SR=0;TI=SMTPD_---0TmhL4gb_1578020579; Received: from localhost(mailfrom:wenyang@linux.alibaba.com fp:SMTPD_---0TmhL4gb_1578020579) by smtp.aliyun-inc.com(127.0.0.1); Fri, 03 Jan 2020 11:03:07 +0800 From: Wen Yang To: Steven Rostedt , Ingo Molnar Cc: xlpang@linux.alibaba.com, Wen Yang , linux-kernel@vger.kernel.org Subject: [PATCH v2] ftrace: avoid potential division by zero Date: Fri, 3 Jan 2020 11:02:48 +0800 Message-Id: <20200103030248.14516-1-wenyang@linux.alibaba.com> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The ftrace_profile->counter is unsigned long and do_div truncates it to 32 bits, which means it can test non-zero and be truncated to zero for division. Fix this issue by using div64_ul() instead. Signed-off-by: Wen Yang Cc: Steven Rostedt Cc: Ingo Molnar Cc: linux-kernel@vger.kernel.org --- v2: get rid of the pre-assigning of avg. kernel/trace/ftrace.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index ac99a35..9bf1f2c 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -526,8 +526,7 @@ static int function_stat_show(struct seq_file *m, void *v) } #ifdef CONFIG_FUNCTION_GRAPH_TRACER - avg = rec->time; - do_div(avg, rec->counter); + avg = div64_ul(rec->time, rec->counter); if (tracing_thresh && (avg < tracing_thresh)) goto out; #endif @@ -553,7 +552,8 @@ static int function_stat_show(struct seq_file *m, void *v) * Divide only 1000 for ns^2 -> us^2 conversion. * trace_print_graph_duration will divide 1000 again. */ - do_div(stddev, rec->counter * (rec->counter - 1) * 1000); + stddev = div64_ul(stddev, + rec->counter * (rec->counter - 1) * 1000); } trace_seq_init(&s); -- 1.8.3.1