linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Matias Bjørling" <m@bjorling.me>
To: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, axboe@fb.com
Cc: Alan <gnomes@lxorguk.ukuu.org.uk>,
	"Alan Cox" <alan@linux.intel.com>,
	"Matias Bjørling" <m@bjorling.me>
Subject: [PATCH 1/3] lightnvm: fix up nonsensical configure overrun checking
Date: Fri, 19 Feb 2016 13:56:57 +0100	[thread overview]
Message-ID: <1455886619-3007-2-git-send-email-m@bjorling.me> (raw)
In-Reply-To: <1455886619-3007-1-git-send-email-m@bjorling.me>

From: Alan <gnomes@lxorguk.ukuu.org.uk>

Instead of checking a constant 0 actually check the space available. Even
better remember to allow for the header and also check the right amount of
space is needed.

Signed-off-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Matias Bjørling <m@bjorling.me>
---
 drivers/lightnvm/core.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c
index c3d4b54..b53632d 100644
--- a/drivers/lightnvm/core.c
+++ b/drivers/lightnvm/core.c
@@ -868,20 +868,19 @@ static int nvm_configure_by_str_event(const char *val,
 
 static int nvm_configure_get(char *buf, const struct kernel_param *kp)
 {
-	int sz = 0;
-	char *buf_start = buf;
+	int sz;
 	struct nvm_dev *dev;
 
-	buf += sprintf(buf, "available devices:\n");
+	sz = sprintf(buf, "available devices:\n");
 	down_write(&nvm_lock);
 	list_for_each_entry(dev, &nvm_devices, devices) {
-		if (sz > 4095 - DISK_NAME_LEN)
+		if (sz > 4095 - DISK_NAME_LEN - 2)
 			break;
-		buf += sprintf(buf, " %32s\n", dev->name);
+		sz += sprintf(buf + sz, " %32s\n", dev->name);
 	}
 	up_write(&nvm_lock);
 
-	return buf - buf_start - 1;
+	return sz;
 }
 
 static const struct kernel_param_ops nvm_configure_by_str_event_param_ops = {
-- 
2.1.4

  reply	other threads:[~2016-02-19 12:58 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-19 12:56 [PATCH 0/3] LightNVM patches for next 4.5-rc Matias Bjørling
2016-02-19 12:56 ` Matias Bjørling [this message]
2016-02-19 12:56 ` [PATCH 2/3] lightnvm: fold get bb tbl when using dual/quad plane mode Matias Bjørling
2016-02-19 12:56 ` [PATCH 3/3] lightnvm: generalize rrpc ppa calculations Matias Bjørling
2016-02-19 19:15 ` [PATCH 0/3] LightNVM patches for next 4.5-rc Jens Axboe
2016-02-20  3:39   ` Jens Axboe

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=1455886619-3007-2-git-send-email-m@bjorling.me \
    --to=m@bjorling.me \
    --cc=alan@linux.intel.com \
    --cc=axboe@fb.com \
    --cc=gnomes@lxorguk.ukuu.org.uk \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).