aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/block/rbd.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index 085df6765d21..14d0a3c9f96a 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -53,7 +53,14 @@
53 53
54#define RBD_SNAP_HEAD_NAME "-" 54#define RBD_SNAP_HEAD_NAME "-"
55 55
56/*
57 * An RBD device name will be "rbd#", where the "rbd" comes from
58 * RBD_DRV_NAME above, and # is a unique integer identifier.
59 * MAX_INT_FORMAT_WIDTH is used in ensuring DEV_NAME_LEN is big
60 * enough to hold all possible device names.
61 */
56#define DEV_NAME_LEN 32 62#define DEV_NAME_LEN 32
63#define MAX_INT_FORMAT_WIDTH ((5 * sizeof (int)) / 2 + 1)
57 64
58#define RBD_NOTIFY_TIMEOUT_DEFAULT 10 65#define RBD_NOTIFY_TIMEOUT_DEFAULT 10
59 66
@@ -2304,8 +2311,9 @@ static int rbd_add_parse_args(struct rbd_device *rbd_dev,
2304 2311
2305 rbd_dev->obj_len = len; 2312 rbd_dev->obj_len = len;
2306 2313
2307 snprintf(rbd_dev->obj_md_name, sizeof(rbd_dev->obj_md_name), "%s%s", 2314 BUILD_BUG_ON(RBD_MAX_MD_NAME_LEN
2308 rbd_dev->obj, RBD_SUFFIX); 2315 < RBD_MAX_OBJ_NAME_LEN + sizeof (RBD_SUFFIX));
2316 sprintf(rbd_dev->obj_md_name, "%s%s", rbd_dev->obj, RBD_SUFFIX);
2309 2317
2310 /* 2318 /*
2311 * The snapshot name is optional, but it's an error if it's 2319 * The snapshot name is optional, but it's an error if it's
@@ -2355,7 +2363,9 @@ static ssize_t rbd_add(struct bus_type *bus,
2355 rbd_id_get(rbd_dev); 2363 rbd_id_get(rbd_dev);
2356 2364
2357 /* Fill in the device name, now that we have its id. */ 2365 /* Fill in the device name, now that we have its id. */
2358 snprintf(rbd_dev->name, DEV_NAME_LEN, RBD_DRV_NAME "%d", rbd_dev->id); 2366 BUILD_BUG_ON(DEV_NAME_LEN
2367 < sizeof (RBD_DRV_NAME) + MAX_INT_FORMAT_WIDTH);
2368 sprintf(rbd_dev->name, "%s%d", RBD_DRV_NAME, rbd_dev->id);
2359 2369
2360 /* parse add command */ 2370 /* parse add command */
2361 rc = rbd_add_parse_args(rbd_dev, buf, mon_addrs, count, 2371 rc = rbd_add_parse_args(rbd_dev, buf, mon_addrs, count,