From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qt1-f172.google.com (mail-qt1-f172.google.com [209.85.160.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2FC6A3E6DE8 for ; Mon, 29 Jun 2026 15:26:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782746801; cv=none; b=qpDFdGXss7x9EaQ9aW5yQKbfzO25aTdWIN/Jyd9XAos2/x7nQ7glWLSGHUbGNSQEUmgJb3Zi70ehYqfOAzq0i0VoijuKbBKdCz6W1TG0ew7w1X4qDR3n0hUhwjYdDQm4covdwFvR1zkmxYtcWdKzEjqXRdX7RqTtN1QZm0+Isjs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782746801; c=relaxed/simple; bh=53qVlCkjPEAghXQTAvM5OIhcWm/iMVOx3RjSY83UM3Q=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=dL4yxf0uxw+r3nvHgZS+E2aQQI3SSPIZzzqxAU7TdUhOma9PKxXjDCveqpugN4xc1trhcujpvvZMf1gI0R+QDsYKe9BRivpdkfLw76pe1YolwMKuuPlfUEfs5sMbKWHpdRbbR4AKC2X5SDozpALEiVQzv6kfucaz+IBGxI6wR2c= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=trailofbits.com; spf=pass smtp.mailfrom=trailofbits.com; dkim=pass (2048-bit key) header.d=trailofbits.com header.i=@trailofbits.com header.b=ek+mBRNi; arc=none smtp.client-ip=209.85.160.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=trailofbits.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=trailofbits.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=trailofbits.com header.i=@trailofbits.com header.b="ek+mBRNi" Received: by mail-qt1-f172.google.com with SMTP id d75a77b69052e-51bfad59921so9572471cf.0 for ; Mon, 29 Jun 2026 08:26:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=trailofbits.com; s=google; t=1782746799; x=1783351599; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=uo9qqQT1HhLcaACp/Mr7EDXYSbliJVG9YBYTx1Ho1dY=; b=ek+mBRNiUItbXo8UFGciZcBKkFMvaZAeRA+kl8pjKEUNrTL91jPdQs0PafS1spKIYo HGPk4h6wvDWSelNP8uZ4U8yckTOjdVmS5nwekV/q87mv6homyk8YAc6VGq+o4IY3OSjg b5bHJXcDjR0jc732FqhtmhkgqfRY1HwYVi7aPcYPpwQrZ4jkfDhPV2aNqprrGTPrdGdG fWGWy6INry7g0Mq9Z90kB2nVJXoVXnwsG0OrDwaXMyNl/DtWksyiugpnVYlBnjklt3LN CzfGBor1GAWp71gW4SkFYgiGi1m3KZAFfIIrtuOTlg7AwrQwvRPgK5xtd+KWJj/0QWAh P4lA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782746799; x=1783351599; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=uo9qqQT1HhLcaACp/Mr7EDXYSbliJVG9YBYTx1Ho1dY=; b=f8QDUPO7GERSxfAuuS9DxcZnmPP+ucLnhMa2ZUnrfPlyfThYtuvlZpfhxuADimf1/i izzm5rzcDn+nuj8jVADaGJmWDdzWoPW1j8nJ7E/OJlogoanAa/v/K7k1+HbBmroUSR/d E0HQGzWOOFhiDU+7DTvX4FHaNQ65ZL6tb452DFc0rhC746vgkTwTwCbCbGd6XKFefEvx TRJEKZ036w6eT4tqJD0okXUN/PZ9pE+AkAQYu3fU78rexhZYKpb4F++fTntfoD/IvqcW w5JVTTCoEKZo/3m43NpNr0CHANNgFHtWZ23vNCuucAPctOpM607xohcmF1rcAap0vZpW Xgsg== X-Forwarded-Encrypted: i=1; AFNElJ+9I0GyhnJtq6D0H/0k92srUrGQ+yfP5OyUH0G9lpKWWSgYzn94jVew9n3b6gFJxK3D9fQFGJ9+SyZFGDA=@vger.kernel.org X-Gm-Message-State: AOJu0Yz9oAXUncBE/TCAqD9MmSMnvoS/c6+cyIkK2m8tPOaJkcj7TTaA 2xxdHGlWMFDx9tynlgL1GzNLZ6PuBBPI+/lOA/bF3OoxfqrWX3y7AJc2rlo61bOkIF8= X-Gm-Gg: AfdE7ckPAwVOH6G+Kany4vJE6/Ue++xArJQyEDDC2ApxwlNza96Br2sP2W5cyMfFgkM 9g01SkkkrMUqfDuW7VjSE7W4+deDamThgJqbaAcNQXJ5tO6hUIkO7mfdfLrFr+e6dzNBra0acrk g8IgrpNassvxfd31J3pg3Pld01m69tO46sSK7XITmofEOtm9yOVvSB8pQhZAk+xmdvNpJbDHxQt RliAm36rUrvSlCRVfX+raHZcQRXE76K9JYEu4ixBbBWxq/Anr8BJMwiNddN7pbrxIvPFYnbC4gD ChScN3aRoMDOso9XbwuaOMjZDCQcMPirTjksKtDgZ9sVqT+RBd9/g41zFLPmLIJuQzD841Uver3 vsZ5hXaNnw3fn+VwY5F9LoVJjF8vWQL/ai9Vc5VlVhUM6AnyqBfsthxDSvTsEFsshcYpGDxkf78 x4OS1wqPdX2GvROFn2 X-Received: by 2002:a05:622a:1f1a:b0:51c:f3:34e3 with SMTP id d75a77b69052e-51c0c9ac15emr17841711cf.28.1782746799141; Mon, 29 Jun 2026 08:26:39 -0700 (PDT) Received: from localhost ([161.35.96.86]) by smtp.gmail.com with UTF8SMTPSA id d75a77b69052e-51a514b5271sm173231731cf.5.2026.06.29.08.26.37 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 29 Jun 2026 08:26:37 -0700 (PDT) From: Samuel Moelius To: Steven Rostedt Cc: Samuel Moelius , Masami Hiramatsu , Mark Rutland , linux-kernel@vger.kernel.org (open list:FUNCTION HOOKS (FTRACE)), linux-trace-kernel@vger.kernel.org (open list:FUNCTION HOOKS (FTRACE)) Subject: [PATCH] samples/ftrace: Prevent division by zero when nr_function_calls is zero Date: Mon, 29 Jun 2026 15:26:17 +0000 Message-ID: <20260629152616.107080.e19bfbed249c.ftrace-ops-zero-function-calls-div0@trailofbits.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The ftrace-ops sample exposes nr_function_calls as a module parameter and uses it as the divisor when printing the measured time per call. Loading the module with nr_function_calls=0 skips the benchmark loop and then divides the elapsed time by zero, crashing the kernel during sample module initialization. Keep accepting the parameter value, but report -1LL as the per-call duration when the call count is zero instead of dividing by it. Assisted-by: Codex:gpt-5.5-cyber-preview Signed-off-by: Samuel Moelius --- samples/ftrace/ftrace-ops.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/ftrace/ftrace-ops.c b/samples/ftrace/ftrace-ops.c index 68d6685c80bd..e6c07da407cc 100644 --- a/samples/ftrace/ftrace-ops.c +++ b/samples/ftrace/ftrace-ops.c @@ -223,7 +223,7 @@ static int __init ftrace_ops_sample_init(void) pr_info("Attempted %u calls to %ps in %lluns (%lluns / call)\n", nr_function_calls, tracee_relevant, - period, div_u64(period, nr_function_calls)); + period, nr_function_calls ? div_u64(period, nr_function_calls) : -1LL); if (persist) return 0; -- 2.43.0