Skip to content

Commit 44aef3b

Browse files
Chaitanya KulkarniChristoph Hellwig
authored andcommitted
nvmet-tcp: validate so_priority modparam value
The module parameter so_priority is passed to the function sock_set_priority() which has following prototype and expect priotity arg type to be u32:- void sock_set_priority(struct sock *sk, u32 priority); Add a module parameter validation callback to reject any negative values for the so_priority as it is defigned as int. Use this oppurtunity to update the module parameter description and print the default value. Signed-off-by: Chaitanya Kulkarni <kch@nvidia.com> Reviewed-by: Sagi Grimberg <sagi@grimberg.me> Signed-off-by: Christoph Hellwig <hch@lst.de>
1 parent aeacfce commit 44aef3b

1 file changed

Lines changed: 27 additions & 2 deletions

File tree

drivers/nvme/target/tcp.c

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,40 @@
2020

2121
#define NVMET_TCP_DEF_INLINE_DATA_SIZE (4 * PAGE_SIZE)
2222

23+
static int param_store_val(const char *str, int *val, int min, int max)
24+
{
25+
int ret, new_val;
26+
27+
ret = kstrtoint(str, 10, &new_val);
28+
if (ret)
29+
return -EINVAL;
30+
31+
if (new_val < min || new_val > max)
32+
return -EINVAL;
33+
34+
*val = new_val;
35+
return 0;
36+
}
37+
38+
static int set_params(const char *str, const struct kernel_param *kp)
39+
{
40+
return param_store_val(str, kp->arg, 0, INT_MAX);
41+
}
42+
43+
static const struct kernel_param_ops set_param_ops = {
44+
.set = set_params,
45+
.get = param_get_int,
46+
};
47+
2348
/* Define the socket priority to use for connections were it is desirable
2449
* that the NIC consider performing optimized packet processing or filtering.
2550
* A non-zero value being sufficient to indicate general consideration of any
2651
* possible optimization. Making it a module param allows for alternative
2752
* values that may be unique for some NIC implementations.
2853
*/
2954
static int so_priority;
30-
module_param(so_priority, int, 0644);
31-
MODULE_PARM_DESC(so_priority, "nvmet tcp socket optimize priority");
55+
device_param_cb(so_priority, &set_param_ops, &so_priority, 0644);
56+
MODULE_PARM_DESC(so_priority, "nvmet tcp socket optimize priority: Default 0");
3257

3358
/* Define a time period (in usecs) that io_work() shall sample an activated
3459
* queue before determining it to be idle. This optional module behavior

0 commit comments

Comments
 (0)