Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

fs/9p: Clean-up get_protocol_version() to use strcmp

Signed-off-by: Prem Karat <prem.karat@linux.vnet.ibm.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>

authored by

Prem Karat and committed by
Eric Van Hensbergen
4d63055f a2dd43bb

+39 -20
+3 -3
include/net/9p/client.h
··· 36 36 */ 37 37 38 38 enum p9_proto_versions{ 39 - p9_proto_legacy = 0, 40 - p9_proto_2000u = 1, 41 - p9_proto_2000L = 2, 39 + p9_proto_legacy, 40 + p9_proto_2000u, 41 + p9_proto_2000L, 42 42 }; 43 43 44 44
+1 -1
include/net/9p/transport.h
··· 67 67 68 68 void v9fs_register_trans(struct p9_trans_module *m); 69 69 void v9fs_unregister_trans(struct p9_trans_module *m); 70 - struct p9_trans_module *v9fs_get_trans_by_name(const substring_t *name); 70 + struct p9_trans_module *v9fs_get_trans_by_name(char *s); 71 71 struct p9_trans_module *v9fs_get_default_trans(void); 72 72 void v9fs_put_trans(struct p9_trans_module *m); 73 73 #endif /* NET_9P_TRANSPORT_H */
+33 -14
net/9p/client.c
··· 72 72 EXPORT_SYMBOL(p9_is_proto_dotu); 73 73 74 74 /* Interpret mount option for protocol version */ 75 - static int get_protocol_version(const substring_t *name) 75 + static int get_protocol_version(char *s) 76 76 { 77 77 int version = -EINVAL; 78 78 79 - if (!strncmp("9p2000", name->from, name->to-name->from)) { 79 + if (!strcmp(s, "9p2000")) { 80 80 version = p9_proto_legacy; 81 81 P9_DPRINTK(P9_DEBUG_9P, "Protocol version: Legacy\n"); 82 - } else if (!strncmp("9p2000.u", name->from, name->to-name->from)) { 82 + } else if (!strcmp(s, "9p2000.u")) { 83 83 version = p9_proto_2000u; 84 84 P9_DPRINTK(P9_DEBUG_9P, "Protocol version: 9P2000.u\n"); 85 - } else if (!strncmp("9p2000.L", name->from, name->to-name->from)) { 85 + } else if (!strcmp(s, "9p2000.L")) { 86 86 version = p9_proto_2000L; 87 87 P9_DPRINTK(P9_DEBUG_9P, "Protocol version: 9P2000.L\n"); 88 - } else { 89 - P9_DPRINTK(P9_DEBUG_ERROR, "Unknown protocol version %s. ", 90 - name->from); 91 - } 88 + } else 89 + printk(KERN_INFO "9p: Unknown protocol version %s.\n", s); 90 + 92 91 return version; 93 92 } 94 93 ··· 105 106 char *p; 106 107 substring_t args[MAX_OPT_ARGS]; 107 108 int option; 109 + char *s; 108 110 int ret = 0; 109 111 110 112 clnt->proto_version = p9_proto_2000u; ··· 141 141 clnt->msize = option; 142 142 break; 143 143 case Opt_trans: 144 - clnt->trans_mod = v9fs_get_trans_by_name(&args[0]); 145 - if(clnt->trans_mod == NULL) { 144 + s = match_strdup(&args[0]); 145 + if (!s) { 146 + ret = -ENOMEM; 146 147 P9_DPRINTK(P9_DEBUG_ERROR, 147 - "Could not find request transport: %s\n", 148 - (char *) &args[0]); 148 + "problem allocating copy of trans arg\n"); 149 + goto free_and_return; 150 + } 151 + clnt->trans_mod = v9fs_get_trans_by_name(s); 152 + if (clnt->trans_mod == NULL) { 153 + printk(KERN_INFO 154 + "9p: Could not find " 155 + "request transport: %s\n", s); 149 156 ret = -EINVAL; 157 + kfree(s); 150 158 goto free_and_return; 151 159 } 160 + kfree(s); 152 161 break; 153 162 case Opt_legacy: 154 163 clnt->proto_version = p9_proto_legacy; 155 164 break; 156 165 case Opt_version: 157 - ret = get_protocol_version(&args[0]); 158 - if (ret == -EINVAL) 166 + s = match_strdup(&args[0]); 167 + if (!s) { 168 + ret = -ENOMEM; 169 + P9_DPRINTK(P9_DEBUG_ERROR, 170 + "problem allocating copy of version arg\n"); 159 171 goto free_and_return; 172 + } 173 + ret = get_protocol_version(s); 174 + if (ret == -EINVAL) { 175 + kfree(s); 176 + goto free_and_return; 177 + } 178 + kfree(s); 160 179 clnt->proto_version = ret; 161 180 break; 162 181 default:
+2 -2
net/9p/mod.c
··· 80 80 * @name: string identifying transport 81 81 * 82 82 */ 83 - struct p9_trans_module *v9fs_get_trans_by_name(const substring_t *name) 83 + struct p9_trans_module *v9fs_get_trans_by_name(char *s) 84 84 { 85 85 struct p9_trans_module *t, *found = NULL; 86 86 87 87 spin_lock(&v9fs_trans_lock); 88 88 89 89 list_for_each_entry(t, &v9fs_trans_list, list) 90 - if (strncmp(t->name, name->from, name->to-name->from) == 0 && 90 + if (strcmp(t->name, s) == 0 && 91 91 try_module_get(t->owner)) { 92 92 found = t; 93 93 break;