Thread (13 messages) 13 messages, 4 authors, 2022-09-01

Re: [PATCH v3] xfrm: Update ipcomp_scratches with NULL if not allocated

From: Khalid Masum <hidden>
Date: 2022-09-01 07:04:44
Also in: linux-kernel-mentees, lkml

On Thu, Sep 1, 2022 at 10:18 AM Herbert Xu [off-list ref] wrote:
On Thu, Sep 01, 2022 at 10:03:07AM +0600, Khalid Masum wrote:
quoted
diff --git a/net/xfrm/xfrm_ipcomp.c b/net/xfrm/xfrm_ipcomp.c
index cb40ff0ff28d..3774d07c5819 100644
--- a/net/xfrm/xfrm_ipcomp.c
+++ b/net/xfrm/xfrm_ipcomp.c
@@ -203,6 +203,7 @@ static void ipcomp_free_scratches(void)
              vfree(*per_cpu_ptr(scratches, i));

      free_percpu(scratches);
+     ipcomp_scratches = NULL;
 }
Good catch! This is probably the root cause of all the crashes.
quoted
 static void * __percpu *ipcomp_alloc_scratches(void)
@@ -215,7 +216,7 @@ static void * __percpu *ipcomp_alloc_scratches(void)

      scratches = alloc_percpu(void *);
      if (!scratches)
-             return NULL;
+             return ipcomp_scratches = NULL;
This is unnecessary as with your first hunk, ipcomp_scratches
is guaranteed to be NULL.

Thanks,
--
You are right. Instead of setting it to NULL at both places, it makes
more sense to
do it when memory is freed.

I shall send a v4 with the suggested change.

thanks,
 -- Khalid Masum
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help