Skip to contentSkip to conversation

smack: clean up smack_enabled to be more readable

PATCH In review Austin Kim 2 participants 3 messages Nov 3, 2021

Subsystems (2)
lore
Share & tools
lore

Austin Kim

author
#0 lore raw

PATCH 1/1 smack: clean up smack_enabled to be more readable

The smack_enabled is only set to 0, 1. So changing type of smack_enabled as bool may make relevant routine be more readable.

---
 security/smack/smack.h           | 2 +-
 security/smack/smack_lsm.c       | 4 ++--
 security/smack/smack_netfilter.c | 2 +-
 security/smack/smackfs.c         | 2 +-
 4 files changed, 5 insertions(+), 5 deletions(-)
security/smack/smack.h +1 -1
index 99c3422596ab..dc1726f5953f 100644
@@ -302,7 +302,7 @@ int smack_populate_secattr(struct smack_known *skp);
 /*
  * Shared data.
  */
-extern int smack_enabled __initdata;
+extern bool smack_enabled __initdata;
 extern int smack_cipso_direct;
 extern int smack_cipso_mapped;
 extern struct smack_known *smack_net_ambient;
security/smack/smack_lsm.c +2 -2
index efd35b07c7f8..ba3b46bd2ceb 100644
@@ -56,7 +56,7 @@ static DEFINE_MUTEX(smack_ipv6_lock);
 static LIST_HEAD(smk_ipv6_port_list);
 #endif
 struct kmem_cache *smack_rule_cache;
-int smack_enabled __initdata;
+bool smack_enabled __initdata;
 
 #define A(s) {"smack"#s, sizeof("smack"#s) - 1, Opt_##s}
 static struct {
@@ -4953,7 +4953,7 @@ static __init int smack_init(void)
 	 * Register with LSM
 	 */
 	security_add_hooks(smack_hooks, ARRAY_SIZE(smack_hooks), "smack");
-	smack_enabled = 1;
+	smack_enabled = true;
 
 	pr_info("Smack:  Initializing.\n");
 #ifdef CONFIG_SECURITY_SMACK_NETFILTER
security/smack/smack_netfilter.c +1 -1
index b945c1d3a743..82092d9387a3 100644
@@ -70,7 +70,7 @@ static struct pernet_operations smack_net_ops = {
 
 static int __init smack_nf_ip_init(void)
 {
-	if (smack_enabled == 0)
+	if (smack_enabled == false)
 		return 0;
 
 	printk(KERN_DEBUG "Smack: Registering netfilter hooks\n");
security/smack/smackfs.c +1 -1
index 658eab05599e..7649ad8cc335 100644
@@ -2993,7 +2993,7 @@ static int __init init_smk_fs(void)
 	int err;
 	int rc;
 
-	if (smack_enabled == 0)
+	if (smack_enabled == false)
 		return 0;
 
 	err = smk_init_sysfs();
Signature · 1 line
2.20.1
maintainer
#1 lore raw
Quoted 4 lines · Austin Kim

The smack_enabled is only set to 0, 1. So changing type of smack_enabled as bool may make relevant routine be more readable.

A couple of changes below.

Quoted 47 lines
---
  security/smack/smack.h           | 2 +-
  security/smack/smack_lsm.c       | 4 ++--
  security/smack/smack_netfilter.c | 2 +-
  security/smack/smackfs.c         | 2 +-
  4 files changed, 5 insertions(+), 5 deletions(-)
security/smack/smack.h +1 -1
index 99c3422596ab..dc1726f5953f 100644
@@ -302,7 +302,7 @@ int smack_populate_secattr(struct smack_known *skp);
  /*
   * Shared data.
   */
-extern int smack_enabled __initdata;
+extern bool smack_enabled __initdata;
  extern int smack_cipso_direct;
  extern int smack_cipso_mapped;
  extern struct smack_known *smack_net_ambient;
security/smack/smack_lsm.c +2 -2
index efd35b07c7f8..ba3b46bd2ceb 100644
@@ -56,7 +56,7 @@ static DEFINE_MUTEX(smack_ipv6_lock);
  static LIST_HEAD(smk_ipv6_port_list);
  #endif
  struct kmem_cache *smack_rule_cache;
-int smack_enabled __initdata;
+bool smack_enabled __initdata;
 
  #define A(s) {"smack"#s, sizeof("smack"#s) - 1, Opt_##s}
  static struct {
@@ -4953,7 +4953,7 @@ static __init int smack_init(void)
  	 * Register with LSM
  	 */
  	security_add_hooks(smack_hooks, ARRAY_SIZE(smack_hooks), "smack");
-	smack_enabled = 1;
+	smack_enabled = true;
 
  	pr_info("Smack:  Initializing.\n");
  #ifdef CONFIG_SECURITY_SMACK_NETFILTER
security/smack/smack_netfilter.c +0 -0
index b945c1d3a743..82092d9387a3 100644

security/smack/smack_netfilter.c static struct pernet_operations smack_net_ops = { · line 73

Quoted 5 lines
security/smack/smack_netfilter.c +1 -1
@@ -70,7 +70,7 @@ static struct pernet_operations smack_net_ops = {
 
  static int __init smack_nf_ip_init(void)
  {
-	if (smack_enabled == 0)
+	if (smack_enabled == false)

If you want to use a bool you should use it fully.
+ if (!smack_enabled)

security/smack/smackfs.c static int __init init_smk_fs(void) · line 2996

Quoted 13 lines
security/smack/smack_netfilter.c +0 -0
  		return 0;
 
  	printk(KERN_DEBUG "Smack: Registering netfilter hooks\n");
security/smack/smackfs.c +1 -1
index 658eab05599e..7649ad8cc335 100644
@@ -2993,7 +2993,7 @@ static int __init init_smk_fs(void)
  	int err;
  	int rc;
 
-	if (smack_enabled == 0)
+	if (smack_enabled == false)

Same here.

Quoted 3 lines
security/smack/smackfs.c +0 -0
  		return 0;
 
  	err = smk_init_sysfs();
author
#2 lore raw

2021년 11월 4일 (목) 오전 1:01, Casey Schaufler <[email protected]>님이 작성:

Quoted 76 lines · Austin Kim
Quoted 4 lines

The smack_enabled is only set to 0, 1. So changing type of smack_enabled as bool may make relevant routine be more readable.

A couple of changes below.

Quoted 47 lines
---
  security/smack/smack.h           | 2 +-
  security/smack/smack_lsm.c       | 4 ++--
  security/smack/smack_netfilter.c | 2 +-
  security/smack/smackfs.c         | 2 +-
  4 files changed, 5 insertions(+), 5 deletions(-)
security/smack/smack.h +1 -1
index 99c3422596ab..dc1726f5953f 100644
@@ -302,7 +302,7 @@ int smack_populate_secattr(struct smack_known *skp);
  /*
   * Shared data.
   */
-extern int smack_enabled __initdata;
+extern bool smack_enabled __initdata;
  extern int smack_cipso_direct;
  extern int smack_cipso_mapped;
  extern struct smack_known *smack_net_ambient;
security/smack/smack_lsm.c +2 -2
index efd35b07c7f8..ba3b46bd2ceb 100644
@@ -56,7 +56,7 @@ static DEFINE_MUTEX(smack_ipv6_lock);
  static LIST_HEAD(smk_ipv6_port_list);
  #endif
  struct kmem_cache *smack_rule_cache;
-int smack_enabled __initdata;
+bool smack_enabled __initdata;
 
  #define A(s) {"smack"#s, sizeof("smack"#s) - 1, Opt_##s}
  static struct {
@@ -4953,7 +4953,7 @@ static __init int smack_init(void)
       * Register with LSM
       */
      security_add_hooks(smack_hooks, ARRAY_SIZE(smack_hooks), "smack");
-     smack_enabled = 1;
+     smack_enabled = true;
 
      pr_info("Smack:  Initializing.\n");
  #ifdef CONFIG_SECURITY_SMACK_NETFILTER
security/smack/smack_netfilter.c +0 -0
index b945c1d3a743..82092d9387a3 100644

security/smack/smack_netfilter.c static struct pernet_operations smack_net_ops = { · line 73

Quoted 5 lines
security/smack/smack_netfilter.c +1 -1
@@ -70,7 +70,7 @@ static struct pernet_operations smack_net_ops = {
 
  static int __init smack_nf_ip_init(void)
  {
-     if (smack_enabled == 0)
+     if (smack_enabled == false)

If you want to use a bool you should use it fully.
+ if (!smack_enabled)

Quoted 11 lines
security/smack/smack_netfilter.c +0 -0
              return 0;
 
      printk(KERN_DEBUG "Smack: Registering netfilter hooks\n");
security/smack/smackfs.c +0 -0
index 658eab05599e..7649ad8cc335 100644
@@ -2993,7 +2993,7 @@ static int __init init_smk_fs(void)
      int err;
      int rc;
 
Quoted 4 lines

security/smack/smackfs.c static int __init init_smk_fs(void) · line 2996

Quoted 2 lines
security/smack/smackfs.c +1 -1
-     if (smack_enabled == 0)
+     if (smack_enabled == false)

Same here.

Thanks for feedback.
Let me resend the patch.

BR,
Austin Kim

Quoted 4 lines
Quoted 4 lines
security/smack/smackfs.c +0 -0
              return 0;
 
      err = smk_init_sysfs();