From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?UTF-8?q?Matias=20Bj=C3=B8rling?= Subject: [PATCH v2] null_blk: boundary check queue_mode and irqmode Date: Wed, 26 Nov 2014 21:39:24 +0100 Message-ID: <1417034364-2841-1-git-send-email-m@bjorling.me> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: =?UTF-8?q?Matias=20Bj=C3=B8rling?= To: axboe@kernel.dk, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Return-path: Sender: linux-kernel-owner@vger.kernel.org List-Id: linux-fsdevel.vger.kernel.org When either queue_mode or irq_mode parameter is set outside its boundar= ies, the driver will not complete requests. This stalls driver initialization wh= en partitions are probed. Fix by setting out of bound values to the parame= ters default. Signed-off-by: Matias Bj=C3=B8rling --- drivers/block/null_blk.c | 58 ++++++++++++++++++++++++++++++++++++++++= ++++++-- 1 file changed, 56 insertions(+), 2 deletions(-) diff --git a/drivers/block/null_blk.c b/drivers/block/null_blk.c index 8001e81..9b865ed 100644 --- a/drivers/block/null_blk.c +++ b/drivers/block/null_blk.c @@ -78,7 +78,34 @@ module_param(home_node, int, S_IRUGO); MODULE_PARM_DESC(home_node, "Home node for the device"); =20 static int queue_mode =3D NULL_Q_MQ; -module_param(queue_mode, int, S_IRUGO); + +static int null_set_queue_mode(const char *val, const struct kernel_pa= ram *kp) +{ + int ret, new_queue_mode; + + ret =3D kstrtoint(val, 10, &new_queue_mode); + if (ret) + goto fail; + + if (new_queue_mode < 0 || new_queue_mode > 2) { + ret =3D -EINVAL; + goto fail; + } + + queue_mode =3D new_queue_mode; + + return 0; +fail: + pr_warn("null_blk: defaults queue_mode to multiqueue\n"); + return ret; +} + +static struct kernel_param_ops null_queue_mode_param_ops =3D { + .set =3D null_set_queue_mode, + .get =3D param_get_int, +}; + +device_param_cb(queue_mode, &null_queue_mode_param_ops, &queue_mode, S= _IRUGO); MODULE_PARM_DESC(queue_mode, "Block interface to use (0=3Dbio,1=3Drq,2= =3Dmultiqueue)"); =20 static int gb =3D 250; @@ -94,7 +121,34 @@ module_param(nr_devices, int, S_IRUGO); MODULE_PARM_DESC(nr_devices, "Number of devices to register"); =20 static int irqmode =3D NULL_IRQ_SOFTIRQ; -module_param(irqmode, int, S_IRUGO); + +static int null_set_irqmode(const char *val, const struct kernel_param= *kp) +{ + int ret, new_irqmode; + + ret =3D kstrtoint(val, 10, &new_irqmode); + if (ret) + goto fail; + + if (new_irqmode < 0 || new_irqmode > 2) { + ret =3D -EINVAL; + goto fail; + } + + irqmode =3D new_irqmode; + + return 0; +fail: + pr_warn("null_blk: defaults to irqmode to softirq\n"); + return ret; +} + +static struct kernel_param_ops null_irqmode_param_ops =3D { + .set =3D null_set_irqmode, + .get =3D param_get_int, +}; + +device_param_cb(irqmode, &null_irqmode_param_ops, &irqmode, S_IRUGO); MODULE_PARM_DESC(irqmode, "IRQ completion handler. 0-none, 1-softirq, = 2-timer"); =20 static int completion_nsec =3D 10000; --=20 2.1.0