From e5c1bf9fa72fccc0146a066845fd58a4a6ca105a Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Thu, 30 Apr 2009 13:59:08 -0700 Subject: [PATCH] brcompat: Use named macro in place of literal constants. Thanks to Justin for the suggestion. --- datapath/brc_procfs.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/datapath/brc_procfs.c b/datapath/brc_procfs.c index 3455da13..1489ef81 100644 --- a/datapath/brc_procfs.c +++ b/datapath/brc_procfs.c @@ -70,15 +70,19 @@ static struct proc_dir_entry *brc_open_dir(const char *dir_name, return *dirp; } +/* Maximum length of the BRC_GENL_A_PROC_DIR and BRC_GENL_A_PROC_NAME strings. + * If we could depend on supporting NLA_NUL_STRING and the .len member in + * Generic Netlink policy, then we could just put this in brc_genl_policy (and + * simplify brc_genl_set_proc() below too), but upstream 2.6.18 does not have + * either. */ +#define BRC_NAME_LEN_MAX 32 + int brc_genl_set_proc(struct sk_buff *skb, struct genl_info *info) { struct proc_dir_entry *dir, *entry; const char *dir_name, *name; char *data; - /* The following would be much simpler if we could depend on supporting - * NLA_NUL_STRING and the .len member in Generic Netlink policy, but - * upstream 2.6.18 does not have either. */ if (!info->attrs[BRC_GENL_A_PROC_DIR] || VERIFY_NUL_STRING(info->attrs[BRC_GENL_A_PROC_DIR]) || !info->attrs[BRC_GENL_A_PROC_NAME] || @@ -89,7 +93,8 @@ int brc_genl_set_proc(struct sk_buff *skb, struct genl_info *info) dir_name = nla_data(info->attrs[BRC_GENL_A_PROC_DIR]); name = nla_data(info->attrs[BRC_GENL_A_PROC_NAME]); - if (strlen(dir_name) > 32 || strlen(name) > 32) + if (strlen(dir_name) > BRC_NAME_LEN_MAX || + strlen(name) > BRC_NAME_LEN_MAX) return -EINVAL; if (!strcmp(dir_name, "net/vlan")) @@ -149,7 +154,7 @@ static void kill_proc_dir(const char *dir_name, for (;;) { struct proc_dir_entry *e; char *data; - char name[33]; + char name[BRC_NAME_LEN_MAX + 1]; e = dir->subdir; if (!e) @@ -157,8 +162,8 @@ static void kill_proc_dir(const char *dir_name, if (e->namelen >= sizeof name) { /* Can't happen: we prevent adding names this long by - * limiting the BRC_GENL_A_PROC_NAME string to 32 - * bytes. */ + * limiting the BRC_GENL_A_PROC_NAME string to + * BRC_NAME_LEN_MAX bytes. */ WARN_ON(1); break; } -- 2.30.2