Skip to contentSkip to conversation

aio: Cleanup unnecessary test for nr_pages

PATCH In review Minfei Huang 2 participants 4 messages Jun 12, 2016 – Jun 22, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 aio: Cleanup unnecessary test for nr_pages

The variable nr_pages is always more than 1, because the size of structure aio_ring is bigger than 0. So remove unnecessary test for nr_page.

---
 fs/aio.c | 2 --
 1 file changed, 2 deletions(-)
fs/aio.c +0 -2
index fb8e45b..ec05137 100644
@@ -450,8 +450,6 @@ static int aio_setup_ring(struct kioctx *ctx)
 	size += sizeof(struct io_event) * nr_events;
 
 	nr_pages = PFN_UP(size);
-	if (nr_pages < 0)
-		return -EINVAL;
 
 	file = aio_private_file(ctx, nr_pages);
 	if (IS_ERR(file)) {
Signature · 1 line
2.7.4 (Apple Git-66)
#1 lore raw

Ping. Any comment is appreciate.

Thanks
Minfei

Quoted 25 lines · Minfei Huang

The variable nr_pages is always more than 1, because the size of structure aio_ring is bigger than 0. So remove unnecessary test for nr_page.

---
 fs/aio.c | 2 --
 1 file changed, 2 deletions(-)
fs/aio.c +0 -2
index fb8e45b..ec05137 100644
@@ -450,8 +450,6 @@ static int aio_setup_ring(struct kioctx *ctx)
 	size += sizeof(struct io_event) * nr_events;
 
 	nr_pages = PFN_UP(size);
-	if (nr_pages < 0)
-		return -EINVAL;
 
 	file = aio_private_file(ctx, nr_pages);
 	if (IS_ERR(file)) {
Signature · 1 line
2.7.4 (Apple Git-66)
maintainer
#2 lore raw
Quoted 9 lines · Minfei Huang

Ping. Any comment is appreciate.

Thanks
Minfei

Quoted 3 lines · Minfei Huang

The variable nr_pages is always more than 1, because the size of structure aio_ring is bigger than 0. So remove unnecessary test for nr_page.

What this test really checks is that the value we'd put into nr_pages (PFN_UP(size)) is not greater than 2^31. Whether it's redundant or not is a separate question - it very well might be, due to the code in ioctx_alloc() that caps nr_events, but that needs a proof. In any case, the reasons you are offering in commit message are wrong - it's about size being too _large_, not too small.

#3 lore raw
Quoted 11 lines · Al Viro
Quoted 9 lines · Minfei Huang

Ping. Any comment is appreciate.

Thanks
Minfei

Quoted 3 lines · Minfei Huang

The variable nr_pages is always more than 1, because the size of structure aio_ring is bigger than 0. So remove unnecessary test for nr_page.

Quoted 6 lines

What this test really checks is that the value we'd put into nr_pages (PFN_UP(size)) is not greater than 2^31. Whether it's redundant or not is a separate question - it very well might be, due to the code in ioctx_alloc() that caps nr_events, but that needs a proof. In any case, the reasons you are offering in commit message are wrong - it's about size being too _large_, not too small.

Hmm. But there is a following test in function ioctx_alloc which is used to limit the max of nr_events.

713 /* Prevent overflows */
714 if (nr_events > (0x10000000U / sizeof(struct io_event))) {
715 pr_debug("ENOMEM: nr_events too high\n");
716 return ERR_PTR(-EINVAL);
717 }

So according to this test, we can make sure that nr_pages(PFN_UP(size)) cann't be greater than 2^31, and max to 2^28.

Thanks
Minfei