Linux CIFS filesystem development
 help / color / mirror / Atom feed
From: Bharath SM <bharathsm.hsk@gmail.com>
To: linux-cifs@vger.kernel.org, smfrench@gmail.com
Cc: Bharath SM <bharathsm@microsoft.com>
Subject: [PATCH 6/7] smb: Fix potential divide-by-zero issue when iface_min_speed is 0
Date: Thu, 19 Jun 2025 21:05:37 +0530	[thread overview]
Message-ID: <20250619153538.1600500-6-bharathsm@microsoft.com> (raw)
In-Reply-To: <20250619153538.1600500-1-bharathsm@microsoft.com>

Address potential divide-by-zero issue when iface_min_speed is 0
by adding proper handling to prevent undefined behavior.

Signed-off-by: Bharath SM <bharathsm@microsoft.com>
---
 fs/smb/client/cifs_debug.c | 2 +-
 fs/smb/client/sess.c       | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/fs/smb/client/cifs_debug.c b/fs/smb/client/cifs_debug.c
index 3fdf75737d43..bc56f315e2e0 100644
--- a/fs/smb/client/cifs_debug.c
+++ b/fs/smb/client/cifs_debug.c
@@ -599,7 +599,7 @@ static int cifs_debug_data_proc_show(struct seq_file *m, void *v)
 				seq_printf(m, "\n\t%d)", ++j);
 				cifs_dump_iface(m, iface);
 
-				iface_weight = iface->speed / iface_min_speed;
+				iface_weight = iface_min_speed ? (iface->speed / iface_min_speed) : 0;
 				seq_printf(m, "\t\tWeight (cur,total): (%zu,%zu)"
 					   "\n\t\tAllocated channels: %u\n",
 					   iface->weight_fulfilled,
diff --git a/fs/smb/client/sess.c b/fs/smb/client/sess.c
index ec0db32c7d98..697170be6591 100644
--- a/fs/smb/client/sess.c
+++ b/fs/smb/client/sess.c
@@ -218,7 +218,7 @@ int cifs_try_adding_channels(struct cifs_ses *ses)
 				continue;
 
 			/* check if we already allocated enough channels */
-			iface_weight = iface->speed / iface_min_speed;
+			iface_weight = iface_min_speed ? (iface->speed / iface_min_speed) : 0;
 
 			if (iface->weight_fulfilled >= iface_weight)
 				continue;
@@ -387,7 +387,7 @@ cifs_chan_update_iface(struct cifs_ses *ses, struct TCP_Server_Info *server)
 		}
 
 		/* check if we already allocated enough channels */
-		iface_weight = iface->speed / iface_min_speed;
+		iface_weight = iface_min_speed ? (iface->speed / iface_min_speed) : 0;
 
 		if (iface->weight_fulfilled >= iface_weight)
 			continue;
-- 
2.43.0


  parent reply	other threads:[~2025-06-19 15:36 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-19 15:35 [PATCH 1/7] smb: Use loff_t for directory position in cached_dirents Bharath SM
2025-06-19 15:35 ` [PATCH 2/7] smb: minor fix to use sizeof to initialize flags_string buffer Bharath SM
2025-06-19 16:06   ` Paulo Alcantara
2025-06-20  9:36   ` Shyam Prasad N
2025-06-19 15:35 ` [PATCH 3/7] smb: minor fix to use SMB2_NTLMV2_SESSKEY_SIZE for auth_key size Bharath SM
2025-06-19 16:08   ` Paulo Alcantara
2025-06-20  9:44   ` Shyam Prasad N
2025-06-19 15:35 ` [PATCH 4/7] smb: add NULL check after kzalloc in cifsConvertToUTF16 Bharath SM
2025-06-19 16:24   ` Paulo Alcantara
2025-06-20 15:04     ` Bharath SM
2025-06-20  9:44   ` Shyam Prasad N
2025-06-19 15:35 ` [PATCH 5/7] cifs: minor cleanup to remove unused permission bit macros Bharath SM
2025-06-19 15:35 ` Bharath SM [this message]
2025-06-19 16:01   ` [PATCH 6/7] smb: Fix potential divide-by-zero issue when iface_min_speed is 0 Paulo Alcantara
2025-06-20 15:04     ` Bharath SM
2025-06-20  9:49   ` Shyam Prasad N
2025-06-19 15:35 ` [PATCH 7/7] smb: Fix memory allocation and ACL handling in cifs_xattr_set Bharath SM
2025-06-19 15:57   ` Paulo Alcantara
2025-06-19 16:05 ` [PATCH 1/7] smb: Use loff_t for directory position in cached_dirents Paulo Alcantara
2025-06-20  9:34 ` Shyam Prasad N

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250619153538.1600500-6-bharathsm@microsoft.com \
    --to=bharathsm.hsk@gmail.com \
    --cc=bharathsm@microsoft.com \
    --cc=linux-cifs@vger.kernel.org \
    --cc=smfrench@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox