All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chaitanya Kulkarni <kch@nvidia.com>
To: <linux-block@vger.kernel.org>
Cc: <axboe@kernel.dk>, <kch@nvidia.com>,
	<damien.lemoal@opensource.wdc.com>, <johannes.thumshirn@wdc.com>,
	<ming.lei@redhat.com>, <bvanassche@acm.org>,
	<shinichiro.kawasaki@wdc.com>, <vincent.fu@samsung.com>
Subject: [PATCH 5/6] null_blk: check for valid max_sectors value
Date: Thu, 6 Oct 2022 23:30:35 -0700	[thread overview]
Message-ID: <20221007063036.13428-6-kch@nvidia.com> (raw)
In-Reply-To: <20221007063036.13428-1-kch@nvidia.com>

Right now we don't check for valid module parameter value for
max_sectors, that allows user to set negative values.

Add a callback to error out when max_sectors value is set < 1 before
module is loaded.

Signed-off-by: Chaitanya Kulkarni <kch@nvidia.com>
---
 drivers/block/null_blk/main.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c
index 7cfc1eaa5e3c..1b9fa5af02d5 100644
--- a/drivers/block/null_blk/main.c
+++ b/drivers/block/null_blk/main.c
@@ -195,7 +195,18 @@ device_param_cb(bs, &null_bs_param_ops, &g_bs, 0444);
 MODULE_PARM_DESC(bs, "Block size (in bytes)");
 
 static int g_max_sectors;
-module_param_named(max_sectors, g_max_sectors, int, 0444);
+
+static int null_set_max_sects(const char *s, const struct kernel_param *p)
+{
+	return null_param_store_val(s, &g_max_sectors, 1, INT_MAX);
+}
+
+static const struct kernel_param_ops null_max_sects_param_ops = {
+	.set	= null_set_max_sects,
+	.get	= param_get_int,
+};
+
+device_param_cb(max_sectors, &null_max_sects_param_ops, &g_max_sectors, 0444);
 MODULE_PARM_DESC(max_sectors, "Maximum size of a command (in 512B sectors)");
 
 static unsigned int nr_devices = 1;
-- 
2.29.0


  parent reply	other threads:[~2022-10-07  6:32 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-07  6:30 [PATCH 0/6] null_blk: add modparam vefication Chaitanya Kulkarni
2022-10-07  6:30 ` [PATCH 1/6] null_blk: check for valid submit_queue value Chaitanya Kulkarni
2022-10-07  6:30 ` [PATCH 2/6] null_blk: check for valid poll_queue value Chaitanya Kulkarni
2022-10-07  6:30 ` [PATCH 3/6] null_blk: check for valid gb value Chaitanya Kulkarni
2022-10-07  6:30 ` [PATCH 4/6] null_blk: check for valid block size value Chaitanya Kulkarni
2022-10-07  6:30 ` Chaitanya Kulkarni [this message]
2022-10-07  6:30 ` [PATCH 6/6] null_blk: check for valid queue depth value Chaitanya Kulkarni

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=20221007063036.13428-6-kch@nvidia.com \
    --to=kch@nvidia.com \
    --cc=axboe@kernel.dk \
    --cc=bvanassche@acm.org \
    --cc=damien.lemoal@opensource.wdc.com \
    --cc=johannes.thumshirn@wdc.com \
    --cc=linux-block@vger.kernel.org \
    --cc=ming.lei@redhat.com \
    --cc=shinichiro.kawasaki@wdc.com \
    --cc=vincent.fu@samsung.com \
    /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.