diff --git a/drivers/block/ramshared/queue.c b/drivers/block/ramshared/queue.c index 4f1282267..fca3946ae 100644 --- a/drivers/block/ramshared/queue.c +++ b/drivers/block/ramshared/queue.c @@ -260,18 +260,18 @@ const struct attribute_group *ramshared_attr_groups[] = { int ramshared_queue_init(struct ramshared_device *rs_dev, struct device *parent_dev, unsigned int q_depth) { - unsigned int valid_depth; int ret; if (!rs_dev || !parent_dev) return -EINVAL; - valid_depth = clamp_t(unsigned int, q_depth, 16U, 1024U); + if (q_depth < 16U || q_depth > 1024U) + return -EINVAL; memset(&rs_dev->tag_set, 0, sizeof(rs_dev->tag_set)); rs_dev->tag_set.ops = &ramshared_mq_ops; rs_dev->tag_set.nr_hw_queues = num_online_cpus(); - rs_dev->tag_set.queue_depth = valid_depth; + rs_dev->tag_set.queue_depth = q_depth; rs_dev->tag_set.numa_node = NUMA_NO_NODE; #ifdef BLK_MQ_F_SHOULD_MERGE rs_dev->tag_set.flags = BLK_MQ_F_SHOULD_MERGE; diff --git a/patch.py b/patch.py new file mode 100644 index 000000000..e3889bed1 --- /dev/null +++ b/patch.py @@ -0,0 +1,13 @@ +import re + +with open('drivers/block/ramshared/queue.c', 'r') as f: + content = f.read() + +content = re.sub( + r'\tunsigned int valid_depth;\n\tint ret;\n\n\tif \(!rs_dev \|\| !parent_dev\)\n\t\treturn -EINVAL;\n\n\tvalid_depth = clamp_t\(unsigned int, q_depth, 16U, 1024U\);\n\n\tmemset\(&rs_dev->tag_set, 0, sizeof\(rs_dev->tag_set\)\);\n\trs_dev->tag_set\.ops = &ramshared_mq_ops;\n\trs_dev->tag_set\.nr_hw_queues = num_online_cpus\(\);\n\trs_dev->tag_set\.queue_depth = valid_depth;', + '\tint ret;\n\n\tif (!rs_dev || !parent_dev)\n\t\treturn -EINVAL;\n\n\tif (q_depth < 16U || q_depth > 1024U)\n\t\treturn -EINVAL;\n\n\tmemset(&rs_dev->tag_set, 0, sizeof(rs_dev->tag_set));\n\trs_dev->tag_set.ops = &ramshared_mq_ops;\n\trs_dev->tag_set.nr_hw_queues = num_online_cpus();\n\trs_dev->tag_set.queue_depth = q_depth;', + content +) + +with open('drivers/block/ramshared/queue.c', 'w') as f: + f.write(content)