Skip to contentSkip to conversation

9p: Add const and unsigned to wnames allocation type

PATCH In review Kees Cook 2 participants 2 messages Sep 17 9P file system

lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 9p: Add const and unsigned to wnames allocation type

From: Kees Cook <[email protected]>

In preparation for converting the kmalloc family of allocators to the type-aware kmalloc_obj family, we need to make sure that the returned type from the allocation matches the type of the variable being assigned. (The kmalloc family returns "void *", which can be implicitly cast to any pointer type.)

The assigned type is "const unsigned char **", but the converted allocation type would be "char **", which differs in both the const qualifier and the signedness of the character type. Take the size from the assignment target instead. No change in allocation size results.

Build tested ARCH=x86_64 allmodconfig with GCC 16.2.0:
fs/9p/fid.o

Assisted-by LLM coccinelle

---
Cc: Eric Van Hensbergen <[email protected]>
Cc: Latchesar Ionkov <[email protected]>
Cc: Dominique Martinet <[email protected]>
Cc: Christian Schoenebeck <[email protected]>
Cc: <[email protected]>

---
 fs/9p/fid.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/9p/fid.c +1 -1
index 76242d450aa7..65dc7972b396 100644
@@ -154,7 +154,7 @@ static int build_path_from_dentry(struct v9fs_session_info *v9ses,
 	for (ds = dentry; !IS_ROOT(ds); ds = ds->d_parent)
 		n++;
 
-	wnames = kmalloc_array(n, sizeof(char *), GFP_KERNEL);
+	wnames = kmalloc_array(n, sizeof(*wnames), GFP_KERNEL);
 	if (!wnames)
 		goto err_out;
 
Signature · 1 line
2.34.1
#1 lore raw

Kees Cook wrote on Thu, Sep 17, 2026 at 02:11:59PM -0700:

Quoted 13 lines

From: Kees Cook <[email protected]>

In preparation for converting the kmalloc family of allocators to the type-aware kmalloc_obj family, we need to make sure that the returned type from the allocation matches the type of the variable being assigned. (The kmalloc family returns "void *", which can be implicitly cast to any pointer type.)

The assigned type is "const unsigned char **", but the converted allocation type would be "char **", which differs in both the const qualifier and the signedness of the character type. Take the size from the assignment target instead. No change in allocation size results.

Quoted 5 lines

Build tested ARCH=x86_64 allmodconfig with GCC 16.2.0:
fs/9p/fid.o

Assisted-by LLM coccinelle

Ack, will pick up this weekend for 7.4

Signature · 1 line
Dominique