diff mbox series

[5.4,2/5] cifs: Get rid of kstrdup_const()'d paths

Message ID 20230623213406.5596-3-risbhat@amazon.com (mailing list archive)
State New, archived
Headers show
Series CIFS DFS fixes for 5.4 | expand

Commit Message

Rishabh Bhatnagar June 23, 2023, 9:34 p.m. UTC
From: "Paulo Alcantara (SUSE)" <pc@cjr.nz>

commit 199c6bdfb04b71d88a7765e08285885fbca60df4 upstream.

The DFS cache API is mostly used with heap allocated strings.

Signed-off-by: Paulo Alcantara (SUSE) <pc@cjr.nz>
Reviewed-by: Aurelien Aptel <aaptel@suse.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
Signed-off-by: Rishabh Bhatnagar <risbhat@amazon.com>
---
 fs/cifs/dfs_cache.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

David Laight June 25, 2023, 3:38 p.m. UTC | #1
From: Rishabh Bhatnagar
> Sent: 23 June 2023 22:34
> From: "Paulo Alcantara (SUSE)" <pc@cjr.nz>
> 
> commit 199c6bdfb04b71d88a7765e08285885fbca60df4 upstream.
> 
> The DFS cache API is mostly used with heap allocated strings.
> 
...
> -	ce->path = kstrdup_const(path, GFP_KERNEL);
> +	ce->path = kstrndup(path, strlen(path), GFP_KERNEL);

That is entirely brain-dead.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
Paulo Alcantara June 25, 2023, 4:58 p.m. UTC | #2
David Laight <David.Laight@ACULAB.COM> writes:

> From: Rishabh Bhatnagar
>> Sent: 23 June 2023 22:34
>> From: "Paulo Alcantara (SUSE)" <pc@cjr.nz>
>> 
>> commit 199c6bdfb04b71d88a7765e08285885fbca60df4 upstream.
>> 
>> The DFS cache API is mostly used with heap allocated strings.
>> 
> ...
>> -	ce->path = kstrdup_const(path, GFP_KERNEL);
>> +	ce->path = kstrndup(path, strlen(path), GFP_KERNEL);
>
> That is entirely brain-dead.

Yep.  It's got fixed up later by

        8d7672235533 ("cifs: don't cargo-cult strndup()")
diff mbox series

Patch

diff --git a/fs/cifs/dfs_cache.c b/fs/cifs/dfs_cache.c
index 4a241979c7c7..3ca65051b55c 100644
--- a/fs/cifs/dfs_cache.c
+++ b/fs/cifs/dfs_cache.c
@@ -131,7 +131,7 @@  static inline void flush_cache_ent(struct cache_entry *ce)
 		return;
 
 	hlist_del_init_rcu(&ce->hlist);
-	kfree_const(ce->path);
+	kfree(ce->path);
 	free_tgts(ce);
 	cache_count--;
 	call_rcu(&ce->rcu, free_cache_entry);
@@ -420,7 +420,7 @@  static struct cache_entry *alloc_cache_entry(const char *path,
 	if (!ce)
 		return ERR_PTR(-ENOMEM);
 
-	ce->path = kstrdup_const(path, GFP_KERNEL);
+	ce->path = kstrndup(path, strlen(path), GFP_KERNEL);
 	if (!ce->path) {
 		kmem_cache_free(cache_slab, ce);
 		return ERR_PTR(-ENOMEM);
@@ -430,7 +430,7 @@  static struct cache_entry *alloc_cache_entry(const char *path,
 
 	rc = copy_ref_data(refs, numrefs, ce, NULL);
 	if (rc) {
-		kfree_const(ce->path);
+		kfree(ce->path);
 		kmem_cache_free(cache_slab, ce);
 		ce = ERR_PTR(rc);
 	}