Skip to content

Commit 4d63055

Browse files
Prem Karatericvh
authored andcommitted
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>
1 parent a2dd43b commit 4d63055

4 files changed

Lines changed: 39 additions & 20 deletions

File tree

‎include/net/9p/client.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@
3636
*/
3737

3838
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,
4242
};
4343

4444

‎include/net/9p/transport.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ struct p9_trans_module {
6767

6868
void v9fs_register_trans(struct p9_trans_module *m);
6969
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);
7171
struct p9_trans_module *v9fs_get_default_trans(void);
7272
void v9fs_put_trans(struct p9_trans_module *m);
7373
#endif /* NET_9P_TRANSPORT_H */

‎net/9p/client.c‎

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -72,23 +72,22 @@ inline int p9_is_proto_dotu(struct p9_client *clnt)
7272
EXPORT_SYMBOL(p9_is_proto_dotu);
7373

7474
/* Interpret mount option for protocol version */
75-
static int get_protocol_version(const substring_t *name)
75+
static int get_protocol_version(char *s)
7676
{
7777
int version = -EINVAL;
7878

79-
if (!strncmp("9p2000", name->from, name->to-name->from)) {
79+
if (!strcmp(s, "9p2000")) {
8080
version = p9_proto_legacy;
8181
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")) {
8383
version = p9_proto_2000u;
8484
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")) {
8686
version = p9_proto_2000L;
8787
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+
9291
return version;
9392
}
9493

@@ -106,6 +105,7 @@ static int parse_opts(char *opts, struct p9_client *clnt)
106105
char *p;
107106
substring_t args[MAX_OPT_ARGS];
108107
int option;
108+
char *s;
109109
int ret = 0;
110110

111111
clnt->proto_version = p9_proto_2000u;
@@ -141,22 +141,41 @@ static int parse_opts(char *opts, struct p9_client *clnt)
141141
clnt->msize = option;
142142
break;
143143
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;
146147
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);
149156
ret = -EINVAL;
157+
kfree(s);
150158
goto free_and_return;
151159
}
160+
kfree(s);
152161
break;
153162
case Opt_legacy:
154163
clnt->proto_version = p9_proto_legacy;
155164
break;
156165
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");
171+
goto free_and_return;
172+
}
173+
ret = get_protocol_version(s);
174+
if (ret == -EINVAL) {
175+
kfree(s);
159176
goto free_and_return;
177+
}
178+
kfree(s);
160179
clnt->proto_version = ret;
161180
break;
162181
default:

‎net/9p/mod.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,14 @@ EXPORT_SYMBOL(v9fs_unregister_trans);
8080
* @name: string identifying transport
8181
*
8282
*/
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)
8484
{
8585
struct p9_trans_module *t, *found = NULL;
8686

8787
spin_lock(&v9fs_trans_lock);
8888

8989
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 &&
9191
try_module_get(t->owner)) {
9292
found = t;
9393
break;

0 commit comments

Comments
 (0)