Thread (5 messages) 5 messages, 3 authors, 2020-02-04

Re: [PATCH V4] brd: check and limit max_part par

From: Zhiqiang Liu <hidden>
Date: 2020-02-04 01:21:44
Also in: lkml


On 2020/2/3 20:26, Ming Lei wrote:
On Tue, Jan 21, 2020 at 12:04:41PM +0800, Zhiqiang Liu wrote:
quoted
In brd_init func, rd_nr num of brd_device are firstly allocated
and add in brd_devices, then brd_devices are traversed to add each
brd_device by calling add_disk func. When allocating brd_device,
the disk->first_minor is set to i * max_part, if rd_nr * max_part
is larger than MINORMASK, two different brd_device may have the same
devt, then only one of them can be successfully added.
when rmmod brd.ko, it will cause oops when calling brd_exit.
quoted
+static inline void brd_check_and_reset_par(void)
+{
+	if (unlikely(!max_part))
+		max_part = 1;
+
+	if (max_part > DISK_MAX_PARTS) {
+		pr_info("brd: max_part can't be larger than %d, reset max_part = %d.\n",
+			DISK_MAX_PARTS, DISK_MAX_PARTS);
+		max_part = DISK_MAX_PARTS;
+	}
+
+	/*
+	 * make sure 'max_part' can be divided exactly by (1U << MINORBITS),
+	 * otherwise, it is possiable to get same dev_t when adding partitions.
+	 */
+	if ((1U << MINORBITS) % max_part != 0)
+		max_part = 1UL << fls(max_part);
+}
You should move the above change before capping it to DISK_MAX_PARTS
since  1UL << fls() may increase 'max_part'.
Thanks for your suggestion. I will send the v5 patch.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help