From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3CE5F27727 for ; Wed, 29 Jul 2026 00:05:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785283525; cv=none; b=WPze/ARwyrgKYidkDftxRJ6unuuzdF1RmhslZkuLHBvlPj+qZfExaWC08/aRk5oNbonRyGeEZLpPHoJXCaXpM5nsTi/UyaOV31RXqfyY/IkuBdlMsfO3vnO8sAnsHIVHtJwmjSCd+8cFk1Ks9LQOgTvi4SR2Y3egT7VQKJPHhpc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785283525; c=relaxed/simple; bh=Od69qxQdn0OsyJxzUiaLIe+Tp6czKzV0y1/33vJJeUk=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=JehBidVWFFU1Jndnu+BzQ5ZtPpgOpr2V0DbJxGxaCZOE1yUeatCFzyiXIriG+ZqOben1/I5F2oijsoqXESsJu2rL2CEdD+nu4rxyxftlK9L/BKw1cT9o1zYCJ5jrFd4Pvxn9NA8expKJVuqwzHpFO86rF2XQF8NKHmQy5s/bI8Y= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=oakA61lz; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="oakA61lz" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F18481F00A3F; Wed, 29 Jul 2026 00:05:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1785283523; bh=Wj5tddqcg2mlGny9YXys1FJG6eGsdWf0srW5UcTepLo=; h=Date:From:To:Cc:Subject:References; b=oakA61lzXOH37q6malqZtiV3Aox1jqncd7cNLtattum6ehVhgY5C4v4p9m0J7PP9k r66hPt17Cc9GqmeJHF38L7mygZFFbCqHjCfhwvImPji59F5Kc3PcSguU4SOD71iIjS V2eJVBPEF/K2eTu2qSq6Jkk/VR7tVUTufBvBWusieuo9VG+7PSUEy/ZIA/kiKJEHCU nCnZ3xMpQkwaKf3DuuPe3DxmcT7ihDslCn3Q4t/ENXa8dSltzklkb6AjDmyzy5xWg0 EKh2XLf9qs9UA50Pf0i9Bekih2EN30ZTkg/SPdJiEHfUU5uTOsOno5t4Did3lDAu9t EyJDovd2krXkw== Received: from rostedt by gandalf with local (Exim 4.99.4) (envelope-from ) id 1woro5-00000006UgC-1Pir; Tue, 28 Jul 2026 20:05:57 -0400 Message-ID: <20260729000557.215624909@kernel.org> User-Agent: quilt/0.69 Date: Tue, 28 Jul 2026 20:05:36 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Samuel Moelius Subject: [for-next][PATCH 13/16] samples/ftrace: Prevent division by zero when nr_function_calls is zero References: <20260729000523.093060274@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 From: Samuel Moelius 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. Link: https://patch.msgid.link/20260629152616.107080.e19bfbed249c.ftrace-ops-zero-function-calls-div0@trailofbits.com Assisted-by: Codex:gpt-5.5-cyber-preview Signed-off-by: Samuel Moelius Signed-off-by: Steven Rostedt --- 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 152ffc1a30b6..8cae38d8b879 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.53.0