linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] afs: Use kfree_rcu() instead of casting kfree() to rcu_callback_t
@ 2020-03-06 16:17 Jann Horn
  0 siblings, 0 replies; 3+ messages in thread
From: Jann Horn @ 2020-03-06 16:17 UTC (permalink / raw)
  To: David Howells; +Cc: linux-afs, linux-kernel

afs_put_addrlist() casts kfree() to rcu_callback_t. Apart from being wrong
in theory, this might also blow up when people start enforcing function
types via compiler instrumentation, and it means the rcu_head has to be
first in struct afs_addr_list.

Use kfree_rcu() instead, it's simpler and more correct.

Signed-off-by: Jann Horn <jannh@google.com>
---
compile-tested only

 fs/afs/addr_list.c | 2 +-
 fs/afs/internal.h  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/afs/addr_list.c b/fs/afs/addr_list.c
index df415c05939e..de1ae0bead3b 100644
--- a/fs/afs/addr_list.c
+++ b/fs/afs/addr_list.c
@@ -19,7 +19,7 @@
 void afs_put_addrlist(struct afs_addr_list *alist)
 {
 	if (alist && refcount_dec_and_test(&alist->usage))
-		call_rcu(&alist->rcu, (rcu_callback_t)kfree);
+		kfree_rcu(alist, rcu);
 }
 
 /*
diff --git a/fs/afs/internal.h b/fs/afs/internal.h
index 1d81fc4c3058..35f951ac296f 100644
--- a/fs/afs/internal.h
+++ b/fs/afs/internal.h
@@ -81,7 +81,7 @@ enum afs_call_state {
  * List of server addresses.
  */
 struct afs_addr_list {
-	struct rcu_head		rcu;		/* Must be first */
+	struct rcu_head		rcu;
 	refcount_t		usage;
 	u32			version;	/* Version */
 	unsigned char		max_addrs;

base-commit: aeb542a1b5c507ea117d21c3e3e012ba16f065ac
-- 
2.25.0.265.gbab2e86ba0-goog


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] afs: Use kfree_rcu() instead of casting kfree() to rcu_callback_t
  2020-03-12 21:36 David Howells
@ 2020-03-13 17:48 ` Linus Torvalds
  0 siblings, 0 replies; 3+ messages in thread
From: Linus Torvalds @ 2020-03-13 17:48 UTC (permalink / raw)
  To: David Howells; +Cc: Jann Horn, linux-afs, Linux Kernel Mailing List

On Thu, Mar 12, 2020 at 2:37 PM David Howells <dhowells@redhat.com> wrote:
>
> Use kfree_rcu() instead, it's simpler and more correct.

Applied,

            Linus

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] afs: Use kfree_rcu() instead of casting kfree() to rcu_callback_t
@ 2020-03-12 21:36 David Howells
  2020-03-13 17:48 ` Linus Torvalds
  0 siblings, 1 reply; 3+ messages in thread
From: David Howells @ 2020-03-12 21:36 UTC (permalink / raw)
  To: torvalds; +Cc: Jann Horn, dhowells, linux-afs, linux-kernel

From: Jann Horn <jannh@google.com>

afs_put_addrlist() casts kfree() to rcu_callback_t. Apart from being wrong
in theory, this might also blow up when people start enforcing function
types via compiler instrumentation, and it means the rcu_head has to be
first in struct afs_addr_list.

Use kfree_rcu() instead, it's simpler and more correct.

Signed-off-by: Jann Horn <jannh@google.com>
Signed-off-by: David Howells <dhowells@redhat.com>
---

 fs/afs/addr_list.c |    2 +-
 fs/afs/internal.h  |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/afs/addr_list.c b/fs/afs/addr_list.c
index df415c05939e..de1ae0bead3b 100644
--- a/fs/afs/addr_list.c
+++ b/fs/afs/addr_list.c
@@ -19,7 +19,7 @@
 void afs_put_addrlist(struct afs_addr_list *alist)
 {
 	if (alist && refcount_dec_and_test(&alist->usage))
-		call_rcu(&alist->rcu, (rcu_callback_t)kfree);
+		kfree_rcu(alist, rcu);
 }
 
 /*
diff --git a/fs/afs/internal.h b/fs/afs/internal.h
index 1d81fc4c3058..35f951ac296f 100644
--- a/fs/afs/internal.h
+++ b/fs/afs/internal.h
@@ -81,7 +81,7 @@ enum afs_call_state {
  * List of server addresses.
  */
 struct afs_addr_list {
-	struct rcu_head		rcu;		/* Must be first */
+	struct rcu_head		rcu;
 	refcount_t		usage;
 	u32			version;	/* Version */
 	unsigned char		max_addrs;



^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-03-13 17:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-06 16:17 [PATCH] afs: Use kfree_rcu() instead of casting kfree() to rcu_callback_t Jann Horn
2020-03-12 21:36 David Howells
2020-03-13 17:48 ` Linus Torvalds

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).