[PATCH v1 bpf-next 3/5] af_unix: Remove redundant scm->fp check in __scm_destroy().
Kuniyuki Iwashima
kuniyu at amazon.com
Mon May 5 21:56:48 UTC 2025
__scm_destroy() is called from __scm_recv_common() or
scm_destroy(), and both of which check if scm->fp is NULL.
Let's remove the redundant scm->fp check in __scm_destroy().
While at it, we remove EXPORT_SYMBOL() for it and rename it
to scm_fp_destroy() to make the following patch clearer.
Signed-off-by: Kuniyuki Iwashima <kuniyu at amazon.com>
---
include/net/scm.h | 5 +++--
net/compat.c | 2 +-
net/core/scm.c | 19 +++++++++----------
3 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/include/net/scm.h b/include/net/scm.h
index 22bb49589fde..058688a16a63 100644
--- a/include/net/scm.h
+++ b/include/net/scm.h
@@ -53,7 +53,7 @@ struct scm_cookie {
void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm);
void scm_detach_fds_compat(struct msghdr *msg, struct scm_cookie *scm);
int __scm_send(struct socket *sock, struct msghdr *msg, struct scm_cookie *scm);
-void __scm_destroy(struct scm_cookie *scm);
+void scm_fp_destroy(struct scm_cookie *scm);
struct scm_fp_list *scm_fp_dup(struct scm_fp_list *fpl);
#ifdef CONFIG_SECURITY_NETWORK
@@ -84,8 +84,9 @@ static __inline__ void scm_destroy_cred(struct scm_cookie *scm)
static __inline__ void scm_destroy(struct scm_cookie *scm)
{
scm_destroy_cred(scm);
+
if (scm->fp)
- __scm_destroy(scm);
+ scm_fp_destroy(scm);
}
static __inline__ int scm_send(struct socket *sock, struct msghdr *msg,
diff --git a/net/compat.c b/net/compat.c
index 485db8ee9b28..6689a4f37bcf 100644
--- a/net/compat.c
+++ b/net/compat.c
@@ -326,7 +326,7 @@ void scm_detach_fds_compat(struct msghdr *msg, struct scm_cookie *scm)
* All of the files that fit in the message have had their usage counts
* incremented, so we just free the list.
*/
- __scm_destroy(scm);
+ scm_fp_destroy(scm);
}
/* Argument list sizes for compat_sys_socketcall */
diff --git a/net/core/scm.c b/net/core/scm.c
index 733c0cbd393d..bef8d008f910 100644
--- a/net/core/scm.c
+++ b/net/core/scm.c
@@ -130,20 +130,19 @@ static int scm_fp_copy(struct cmsghdr *cmsg, struct scm_fp_list **fplp)
return num;
}
-void __scm_destroy(struct scm_cookie *scm)
+void scm_fp_destroy(struct scm_cookie *scm)
{
struct scm_fp_list *fpl = scm->fp;
int i;
- if (fpl) {
- scm->fp = NULL;
- for (i=fpl->count-1; i>=0; i--)
- fput(fpl->fp[i]);
- free_uid(fpl->user);
- kfree(fpl);
- }
+ scm->fp = NULL;
+
+ for (i = fpl->count - 1; i >= 0; i--)
+ fput(fpl->fp[i]);
+
+ free_uid(fpl->user);
+ kfree(fpl);
}
-EXPORT_SYMBOL(__scm_destroy);
int __scm_send(struct socket *sock, struct msghdr *msg, struct scm_cookie *p)
{
@@ -375,7 +374,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
* All of the files that fit in the message have had their usage counts
* incremented, so we just free the list.
*/
- __scm_destroy(scm);
+ scm_fp_destroy(scm);
}
EXPORT_SYMBOL(scm_detach_fds);
--
2.49.0
More information about the Linux-security-module-archive
mailing list