From: Ben Pfaff Date: Tue, 30 Dec 2008 20:40:11 +0000 (-0800) Subject: Simplify lookup_dp() now that we can assume that dp_name is null-terminated. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1d666b00cffc4b5418d40b012b967d5efbb83dcc;p=openvswitch Simplify lookup_dp() now that we can assume that dp_name is null-terminated. --- diff --git a/datapath/datapath.c b/datapath/datapath.c index d9184b65..e10b5206 100644 --- a/datapath/datapath.c +++ b/datapath/datapath.c @@ -1135,13 +1135,9 @@ struct datapath *dp_get_by_idx(int dp_idx) struct datapath *dp_get_by_name(const char *dp_name) { int i; - - if (!dp_name || (strlen(dp_name) >= sizeof(dps[0]->netdev->name))) - return NULL; - for (i=0; inetdev->name, dp_name, IFNAMSIZ)) + if (dp && !strcmp(dp->netdev->name, dp_name)) return dp; } return NULL; @@ -1154,25 +1150,21 @@ lookup_dp(struct genl_info *info) nla_get_u32(info->attrs[DP_GENL_A_DP_IDX]) : -1; const char *dp_name = info->attrs[DP_GENL_A_DP_NAME] ? nla_data(info->attrs[DP_GENL_A_DP_NAME]) : NULL; - struct datapath *dp = NULL; - - if ((dp_idx == -1) && (!dp_name)) - return ERR_PTR(-EINVAL); if (dp_idx != -1) { - dp = dp_get_by_idx(dp_idx); + struct datapath *dp = dp_get_by_idx(dp_idx); if (!dp) return ERR_PTR(-ENOENT); - } - - if (dp_name) { - struct datapath *dp_n = dp_get_by_name(dp_name); - if (dp && dp != dp_n) + else if (dp_name && strcmp(dp->netdev->name, dp_name)) return ERR_PTR(-EINVAL); - dp = dp_n; + else + return dp; + } else if (dp_name) { + struct datapath *dp = dp_get_by_name(dp_name); + return dp ? dp : ERR_PTR(-ENOENT); + } else { + return ERR_PTR(-EINVAL); } - - return dp ? dp : ERR_PTR(-ENOENT); } static int dp_genl_del(struct sk_buff *skb, struct genl_info *info)