Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp16273814ybl; Wed, 1 Jan 2020 01:46:39 -0800 (PST) X-Google-Smtp-Source: APXvYqzI6516wO9+MFGD1Wm/7VtESUBezRg+UKVyOFk2+svW4LxXRe6hL5QVI2HcJagxBN2zx3b7 X-Received: by 2002:a17:906:5ac2:: with SMTP id x2mr82120537ejs.29.1577871999506; Wed, 01 Jan 2020 01:46:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577871999; cv=none; d=google.com; s=arc-20160816; b=H/PKfwsj7S+O4C0YpaxkMMlwgDk1FqI0mDEHoWFzTGcj5VxFK6lvRGmuMUxrDmJ4Uw Ft3XM+2WdXwDOv9ycE1vhcezqH8tX1nb4eO6c3VfMk7zXRgTnpTUKCoL8AFnX3qhq8LG Rh+rRhdi3vXcFFhhuj9VKBkWbODmkAm3jkyJ5uIHjnMnxIIRMcttbiMpHNLyVlRGVSFR XPjoHtHZZScewxkO+0q9qIVtOiDvoe/n5kIBZkI6rYIrRM+xwAxtA7Y2JiKbZUrxK4DI vji9y6XNSGHnRSYUHQAplhdOj2zWBbHoUTNR8kkm8ZZPS2ZC2gZtOc0iFOBF+/bUR7VQ T2rg== 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=Bu6+TozKmgiptzwKA/xDR9qAUMPy5yBwbg5o51wMSNw=; b=C8pGM7c5tur9YKedl8KB5CHWzJtpBSYT3OmSeMvXcbSm1TCH5YDnrQHae3MC/d0Hat ZE3JKIIeb68w1Znwle6wbUXs9HxH+M8CgVg+1abqTVxDMoc9DR/op1cWnYdIxcE2qKx1 VFIfLvn2QkUPAfYQJDGrUqndBHv31+QkuIdXvXwb0sJZCxbM6tpI7jyRh4tTPOijuA6T Jax2asyrfT4sjMKyDyG7vPwMV78lyt9Q3ij27U2K3GZflrG6kBoq39jiZ5eEd2u5Qh8S qL1L0gn7i10l7rCLKTZTX+bWJMahWGSllKsDfeIau2i+OXfWnHCxixCP2RFOYF7VxJeH QJGg== 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 c6si32320259eds.171.2020.01.01.01.46.15; Wed, 01 Jan 2020 01:46:39 -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 S1725883AbgAAJmt (ORCPT + 99 others); Wed, 1 Jan 2020 04:42:49 -0500 Received: from out30-132.freemail.mail.aliyun.com ([115.124.30.132]:44732 "EHLO out30-132.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725783AbgAAJmt (ORCPT ); Wed, 1 Jan 2020 04:42:49 -0500 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R311e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04395;MF=wenyang@linux.alibaba.com;NM=1;PH=DS;RN=5;SR=0;TI=SMTPD_---0TmUDZF-_1577871758; Received: from localhost(mailfrom:wenyang@linux.alibaba.com fp:SMTPD_---0TmUDZF-_1577871758) by smtp.aliyun-inc.com(127.0.0.1); Wed, 01 Jan 2020 17:42:46 +0800 From: Wen Yang To: Steven Rostedt , Ingo Molnar Cc: xlpang@linux.alibaba.com, Wen Yang , linux-kernel@vger.kernel.org Subject: [PATCH RESEND] ftrace: avoid potential division by zero Date: Wed, 1 Jan 2020 17:42:33 +0800 Message-Id: <20200101094233.3804-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 --- kernel/trace/ftrace.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index ac99a35..342e286 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -527,7 +527,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(avg, rec->counter); if (tracing_thresh && (avg < tracing_thresh)) goto out; #endif @@ -553,7 +553,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