Skip to contentSkip to conversation

fs: afs: Fix uninit 'count' in afs_deliver_fs_get_capabilities

PATCH New SurajSonawane2415 1 participant 1 message Oct 9, 2024 Afs filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fs: afs: Fix uninit 'count' in afs_deliver_fs_get_capabilities

From: Suraj Sonawane <[email protected]>

Fix the uninitialized symbol 'count' in the function afs_deliver_fs_get_capabilities to resolve the error generated with the smatch tool:

fs/afs/fsclient.c:1704 afs_deliver_fs_get_capabilities() error:
uninitialized symbol 'count'.

The error regarding the uninitialized count symbol in the afs_deliver_fs_get_capabilities function arises due to the control flow of the switch statement. Ensure that you initialize count before its usage to avoid undefined behavior.

If unmarshall skips to cases 2 or 3, count remains uninitialized and may contain a garbage value. This could lead to errors flagged by static analysis tools like smatch.

By initializing count to zero, guarantee that it has a defined value regardless of the control path taken, thereby enhancing code reliability and preventing potential issues associated with uninitialized variables.

---
 fs/afs/fsclient.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/afs/fsclient.c +1 -1
index 098fa034a..4ab41dcdb 100644
@@ -1665,7 +1665,7 @@ int afs_fs_give_up_all_callbacks(struct afs_net *net, struct afs_server *server,
  */
 static int afs_deliver_fs_get_capabilities(struct afs_call *call)
 {
-	u32 count;
+	u32 count = 0;
 	int ret;
 
 	_enter("{%u,%zu}", call->unmarshall, iov_iter_count(call->iter));
Signature · 1 line
2.34.1