Skip to contentSkip to conversation

NFS: simplify check for freeing cn_resp

PATCH Superseded [email protected] 2 participants 3 messages Jan 16, 2022

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 NFS: simplify check for freeing cn_resp

From: Tom Rix <[email protected]>

nfs42_files_from_same_server() is called to check if freeing cn_resp is required. Instead of calling a function, check the pointer.

---
 fs/nfs/nfs4file.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nfs/nfs4file.c +1 -1
index e79ae4cbc395e..677631ea4cfb3 100644
@@ -180,7 +180,7 @@ static ssize_t __nfs4_copy_file_range(struct file *file_in, loff_t pos_in,
 	ret = nfs42_proc_copy(file_in, pos_in, file_out, pos_out, count,
 				nss, cnrs, sync);
 out:
-	if (!nfs42_files_from_same_server(file_in, file_out))
+	if (cn_resp)
 		kfree(cn_resp);
 	if (ret == -EAGAIN)
 		goto retry;
Signature · 1 line
2.26.3
#1 lore raw

Hi Tom,

Quoted 20 lines · On Sun, 2022-01-16 at 06:43 -0800, [email protected] wrote:

From: Tom Rix <[email protected]>

nfs42_files_from_same_server() is called to check if freeing cn_resp is required.  Instead of calling a function, check the pointer.

---
 fs/nfs/nfs4file.c | 2 +-

 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nfs/nfs4file.c +0 -0
index e79ae4cbc395e..677631ea4cfb3 100644
@@ -180,7 +180,7 @@ static ssize_t __nfs4_copy_file_range(struct file
 *file_in, loff_t pos_in,
         ret = nfs42_proc_copy(file_in, pos_in, file_out, pos_out,
 count,
                                 nss, cnrs, sync);
Quoted 4 lines

 out:
-       if (!nfs42_files_from_same_server(file_in, file_out)) +       if (cn_resp)
                kfree(cn_resp);

The kernel convention in these circumstances is to just skip the NULL pointer check, since kfree() does that anyway.

Quoted 2 lines

        if (ret == -EAGAIN)
                goto retry;

Signature · 3 lines
Trond Myklebust
Linux NFS client maintainer, Hammerspace
[email protected]
author
#2 lore raw
Quoted 14 lines · Trond Myklebust

Hi Tom,

Quoted 11 lines · On Sun, 2022-01-16 at 06:43 -0800, [email protected] wrote:

From: Tom Rix <[email protected]>

nfs42_files_from_same_server() is called to check if freeing cn_resp is required.  Instead of calling a function, check the pointer.

---
  fs/nfs/nfs4file.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 15 lines

fs/nfs/nfs4file.c static ssize_t __nfs4_copy_file_range(struct file · line 186

Quoted 13 lines
fs/nfs/nfs4file.c +1 -1
index e79ae4cbc395e..677631ea4cfb3 100644
@@ -180,7 +180,7 @@ static ssize_t __nfs4_copy_file_range(struct file
 *file_in, loff_t pos_in,
         ret = nfs42_proc_copy(file_in, pos_in, file_out, pos_out,
 count,
                                 nss, cnrs, sync);
  out:
-       if (!nfs42_files_from_same_server(file_in, file_out))
+       if (cn_resp)
                 kfree(cn_resp);

The kernel convention in these circumstances is to just skip the NULL pointer check, since kfree() does that anyway.

Yes. I'll respin.

Tom

Quoted 3 lines
Quoted 3 lines

        if (ret == -EAGAIN)
                goto retry;