Skip to content

Commit ee57741

Browse files
author
Alex Elder
committed
rbd: make ceph_parse_options() return a pointer
ceph_parse_options() takes the address of a pointer as an argument and uses it to return the address of an allocated structure if successful. With this interface is not evident at call sites that the pointer is always initialized. Change the interface to return the address instead (or a pointer-coded error code) to make the validity of the returned pointer obvious. Signed-off-by: Alex Elder <elder@dreamhost.com> Signed-off-by: Sage Weil <sage@newdream.net>
1 parent 2107978 commit ee57741

4 files changed

Lines changed: 17 additions & 13 deletions

File tree

‎drivers/block/rbd.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,11 +371,13 @@ static int rbd_get_client(struct rbd_device *rbd_dev, const char *mon_addr,
371371

372372
rbd_opts->notify_timeout = RBD_NOTIFY_TIMEOUT_DEFAULT;
373373

374-
ret = ceph_parse_options(&opt, options, mon_addr,
374+
opt = ceph_parse_options(options, mon_addr,
375375
mon_addr + strlen(mon_addr),
376376
parse_rbd_opts_token, rbd_opts);
377-
if (ret < 0)
377+
if (IS_ERR(opt)) {
378+
ret = PTR_ERR(opt);
378379
goto done_err;
380+
}
379381

380382
spin_lock(&node_lock);
381383
rbdc = __rbd_client_find(opt);

‎fs/ceph/super.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,10 +334,12 @@ static int parse_mount_options(struct ceph_mount_options **pfsopt,
334334
*path += 2;
335335
dout("server path '%s'\n", *path);
336336

337-
err = ceph_parse_options(popt, options, dev_name, dev_name_end,
337+
*popt = ceph_parse_options(options, dev_name, dev_name_end,
338338
parse_fsopt_token, (void *)fsopt);
339-
if (err)
339+
if (IS_ERR(*popt)) {
340+
err = PTR_ERR(*popt);
340341
goto out;
342+
}
341343

342344
/* success */
343345
*pfsopt = fsopt;

‎include/linux/ceph/libceph.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ extern struct kmem_cache *ceph_cap_cachep;
207207
extern struct kmem_cache *ceph_dentry_cachep;
208208
extern struct kmem_cache *ceph_file_cachep;
209209

210-
extern int ceph_parse_options(struct ceph_options **popt, char *options,
210+
extern struct ceph_options *ceph_parse_options(char *options,
211211
const char *dev_name, const char *dev_name_end,
212212
int (*parse_extra_token)(char *c, void *private),
213213
void *private);

‎net/ceph/ceph_common.c‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -277,10 +277,11 @@ static int get_secret(struct ceph_crypto_key *dst, const char *name) {
277277
return err;
278278
}
279279

280-
int ceph_parse_options(struct ceph_options **popt, char *options,
281-
const char *dev_name, const char *dev_name_end,
282-
int (*parse_extra_token)(char *c, void *private),
283-
void *private)
280+
struct ceph_options *
281+
ceph_parse_options(char *options, const char *dev_name,
282+
const char *dev_name_end,
283+
int (*parse_extra_token)(char *c, void *private),
284+
void *private)
284285
{
285286
struct ceph_options *opt;
286287
const char *c;
@@ -289,7 +290,7 @@ int ceph_parse_options(struct ceph_options **popt, char *options,
289290

290291
opt = kzalloc(sizeof(*opt), GFP_KERNEL);
291292
if (!opt)
292-
return err;
293+
return ERR_PTR(-ENOMEM);
293294
opt->mon_addr = kcalloc(CEPH_MAX_MON, sizeof(*opt->mon_addr),
294295
GFP_KERNEL);
295296
if (!opt->mon_addr)
@@ -412,12 +413,11 @@ int ceph_parse_options(struct ceph_options **popt, char *options,
412413
}
413414

414415
/* success */
415-
*popt = opt;
416-
return 0;
416+
return opt;
417417

418418
out:
419419
ceph_destroy_options(opt);
420-
return err;
420+
return ERR_PTR(err);
421421
}
422422
EXPORT_SYMBOL(ceph_parse_options);
423423

0 commit comments

Comments
 (0)