All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alex Elder <elder@dreamhost.com>
To: ceph-devel@vger.kernel.org
Subject: [PATCH 3/5] rbd: do a few checks at build time
Date: Tue, 28 Feb 2012 19:59:16 -0800	[thread overview]
Message-ID: <4F4DA294.7050008@dreamhost.com> (raw)
In-Reply-To: <4F4DA1EA.3080705@dreamhost.com>

This is a bit gratuitous, but there are a few things that can be
verified at build time rather than run time, so do that.

Signed-off-by: Alex Elder <elder@dreamhost.com>
---
  drivers/block/rbd.c |   15 ++++++++++++---
  1 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index d2157a7..0602ed9 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -53,7 +53,14 @@

  #define RBD_SNAP_HEAD_NAME	"-"

+/*
+ * An RBD device name will be "rbd#", where the "rbd" comes from
+ * RBD_DRV_NAME above, and # is a unique integer identifier.
+ * MAX_INT_FORMAT_WIDTH is used in ensuring DEV_NAME_LEN is big
+ * enough to hold all possible device names.
+ */
  #define DEV_NAME_LEN		32
+#define MAX_INT_FORMAT_WIDTH	((5 * sizeof (int)) / 2 + 1)

  #define RBD_NOTIFY_TIMEOUT_DEFAULT 10

@@ -2303,8 +2310,9 @@ static int rbd_add_parse_args(struct rbd_device 
*rbd_dev,

  	rbd_dev->obj_len = len;

-	snprintf(rbd_dev->obj_md_name, sizeof(rbd_dev->obj_md_name), "%s%s",
-		 rbd_dev->obj, RBD_SUFFIX);
+	BUILD_BUG_ON(RBD_MAX_MD_NAME_LEN
+				< RBD_MAX_OBJ_NAME_LEN + sizeof RBD_SUFFIX);
+	sprintf(rbd_dev->obj_md_name, "%s%s", rbd_dev->obj, RBD_SUFFIX);

  	/*
  	 * The snapshot name is optional, but it's an error if it's
@@ -2352,7 +2360,8 @@ static ssize_t rbd_add(struct bus_type *bus,
  	rbd_id_get(rbd_dev);

  	/* Fill in the device name, now that we have its id. */
-	snprintf(rbd_dev->name, DEV_NAME_LEN, RBD_DRV_NAME "%d", rbd_dev->id);
+	BUILD_BUG_ON(DEV_NAME_LEN < sizeof RBD_DRV_NAME + MAX_INT_FORMAT_WIDTH);
+	sprintf(rbd_dev->name, "%s%d", RBD_DRV_NAME, rbd_dev->id);

  	/* parse add command */
  	rc = rbd_add_parse_args(rbd_dev, buf, mon_addrs, count,
-- 
1.7.5.4


  parent reply	other threads:[~2012-02-29  3:59 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-29  3:56 [PATCH 0/5] rbd: cleanups related to argument parsing Alex Elder
2012-02-29  3:59 ` [PATCH 1/5] rbd: encapsulate argument parsing for rbd_add() Alex Elder
2012-02-29  3:59 ` [PATCH 2/5] rbd: don't use sscanf() in rbd_add_parse_args() Alex Elder
2012-02-29  3:59 ` Alex Elder [this message]
2012-02-29  3:59 ` [PATCH 4/5] rbd: have rbd_parse_args() report found mon_addrs size Alex Elder
2012-02-29  3:59 ` [PATCH 5/5] rbd: don't allocate mon_addrs buffer in rbd_add() Alex Elder
2012-03-02 21:28 ` [PATCH 0/5] rbd: cleanups related to argument parsing Sage Weil

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4F4DA294.7050008@dreamhost.com \
    --to=elder@dreamhost.com \
    --cc=ceph-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.