Re: [PATCH v3 net-next 1/5] device_cgroup: add DEVCG_ prefix to ACC_* and DEV_* constants

From: Joe Perches
Date: Thu Nov 02 2017 - 13:54:39 EST


On Thu, 2017-11-02 at 13:15 -0400, Roman Gushchin wrote:
> Rename device type and access type constants defined in
> security/device_cgroup.c by adding the DEVCG_ prefix.
>
> The reason behind this renaming is to make them global namespace
> friendly, as they will be moved to the corresponding header file
> by following patches.
[]
> diff --git a/security/device_cgroup.c b/security/device_cgroup.c
[]
> @@ -14,14 +14,14 @@
> #include <linux/rcupdate.h>
> #include <linux/mutex.h>
>
> -#define ACC_MKNOD 1
> -#define ACC_READ 2
> -#define ACC_WRITE 4
> -#define ACC_MASK (ACC_MKNOD | ACC_READ | ACC_WRITE)
> +#define DEVCG_ACC_MKNOD 1
> +#define DEVCG_ACC_READ 2
> +#define DEVCG_ACC_WRITE 4
> +#define DEVCG_ACC_MASK (DEVCG_ACC_MKNOD | DEVCG_ACC_READ | DEVCG_ACC_WRITE)

trivia:

major and minor are u32 but all the
type and access uses seem to be "short"

Perhaps u16 (or __u16 if uapi public) instead?

> -#define DEV_BLOCK 1
> -#define DEV_CHAR 2
> -#define DEV_ALL 4 /* this represents all devices */
> +#define DEVCG_DEV_BLOCK 1
> +#define DEVCG_DEV_CHAR 2
> +#define DEVCG_DEV_ALL 4 /* this represents all devices */
>
> static DEFINE_MUTEX(devcgroup_mutex);
>
> @@ -245,21 +245,21 @@ static void set_access(char *acc, short access)
> {
> int idx = 0;
> memset(acc, 0, ACCLEN);
> - if (access & ACC_READ)
> + if (access & DEVCG_ACC_READ)
> acc[idx++] = 'r';
> - if (access & ACC_WRITE)
> + if (access & DEVCG_ACC_WRITE)
> acc[idx++] = 'w';
> - if (access & ACC_MKNOD)
> + if (access & DEVCG_ACC_MKNOD)
> acc[idx++] = 'm';
> }
>
> static char type_to_char(short type)
> {
> - if (type == DEV_ALL)
> + if (type == DEVCG_DEV_ALL)
> return 'a';
> - if (type == DEV_CHAR)
> + if (type == DEVCG_DEV_CHAR)
> return 'c';
> - if (type == DEV_BLOCK)
> + if (type == DEVCG_DEV_BLOCK)
> return 'b';
> return 'X';
> }