All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] selinux: minor tweaks to selinux_add_opt()
@ 2021-12-22 20:10 Paul Moore
  2021-12-23  2:30 ` Paul Moore
  0 siblings, 1 reply; 2+ messages in thread
From: Paul Moore @ 2021-12-22 20:10 UTC (permalink / raw)
  To: selinux

Two minor edits to selinux_add_opt(): use "sizeof(*ptr)" instead of
"sizeof(type)" in the kzalloc() call, and rename the "Einval" jump
target to "err" for the sake of consistency.

Signed-off-by: Paul Moore <paul@paul-moore.com>
---
 security/selinux/hooks.c |   18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index 8ef63b7af855..904f9c23f0f6 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -972,14 +972,14 @@ static int selinux_add_opt(int token, const char *s, void **mnt_opts)
 	struct selinux_mnt_opts *opts = *mnt_opts;
 	bool is_alloc_opts = false;
 
-	if (token == Opt_seclabel)	/* eaten and completely ignored */
+	if (token == Opt_seclabel)
+		/* eaten and completely ignored */
 		return 0;
-
 	if (!s)
 		return -ENOMEM;
 
 	if (!opts) {
-		opts = kzalloc(sizeof(struct selinux_mnt_opts), GFP_KERNEL);
+		opts = kzalloc(sizeof(*opts), GFP_KERNEL);
 		if (!opts)
 			return -ENOMEM;
 		*mnt_opts = opts;
@@ -989,27 +989,29 @@ static int selinux_add_opt(int token, const char *s, void **mnt_opts)
 	switch (token) {
 	case Opt_context:
 		if (opts->context || opts->defcontext)
-			goto Einval;
+			goto err;
 		opts->context = s;
 		break;
 	case Opt_fscontext:
 		if (opts->fscontext)
-			goto Einval;
+			goto err;
 		opts->fscontext = s;
 		break;
 	case Opt_rootcontext:
 		if (opts->rootcontext)
-			goto Einval;
+			goto err;
 		opts->rootcontext = s;
 		break;
 	case Opt_defcontext:
 		if (opts->context || opts->defcontext)
-			goto Einval;
+			goto err;
 		opts->defcontext = s;
 		break;
 	}
+
 	return 0;
-Einval:
+
+err:
 	if (is_alloc_opts) {
 		kfree(opts);
 		*mnt_opts = NULL;


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

* Re: [PATCH] selinux: minor tweaks to selinux_add_opt()
  2021-12-22 20:10 [PATCH] selinux: minor tweaks to selinux_add_opt() Paul Moore
@ 2021-12-23  2:30 ` Paul Moore
  0 siblings, 0 replies; 2+ messages in thread
From: Paul Moore @ 2021-12-23  2:30 UTC (permalink / raw)
  To: selinux

On Wed, Dec 22, 2021 at 3:10 PM Paul Moore <paul@paul-moore.com> wrote:
>
> Two minor edits to selinux_add_opt(): use "sizeof(*ptr)" instead of
> "sizeof(type)" in the kzalloc() call, and rename the "Einval" jump
> target to "err" for the sake of consistency.
>
> Signed-off-by: Paul Moore <paul@paul-moore.com>
> ---
>  security/selinux/hooks.c |   18 ++++++++++--------
>  1 file changed, 10 insertions(+), 8 deletions(-)

Merged into selinux/next.

-- 
paul moore
www.paul-moore.com

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

end of thread, other threads:[~2021-12-23  2:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-22 20:10 [PATCH] selinux: minor tweaks to selinux_add_opt() Paul Moore
2021-12-23  2:30 ` Paul Moore

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.