Skip to content

Commit 124f75f

Browse files
author
Al Viro
committed
clean overflow checks in count_mounts() a bit
Wraparound checks in there are redundant (x + y < x and x + y < y are equivalent when x and y are both unsigned int). IMO more straightforward code would be better here... Signed-off-by: Al Viro <[email protected]>
1 parent 90b2433 commit 124f75f

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

fs/namespace.c

+10-9
Original file line numberDiff line numberDiff line change
@@ -2069,22 +2069,23 @@ static int invent_group_ids(struct mount *mnt, bool recurse)
20692069
int count_mounts(struct mnt_namespace *ns, struct mount *mnt)
20702070
{
20712071
unsigned int max = READ_ONCE(sysctl_mount_max);
2072-
unsigned int mounts = 0, old, pending, sum;
2072+
unsigned int mounts = 0;
20732073
struct mount *p;
20742074

2075+
if (ns->mounts >= max)
2076+
return -ENOSPC;
2077+
max -= ns->mounts;
2078+
if (ns->pending_mounts >= max)
2079+
return -ENOSPC;
2080+
max -= ns->pending_mounts;
2081+
20752082
for (p = mnt; p; p = next_mnt(p, mnt))
20762083
mounts++;
20772084

2078-
old = ns->mounts;
2079-
pending = ns->pending_mounts;
2080-
sum = old + pending;
2081-
if ((old > sum) ||
2082-
(pending > sum) ||
2083-
(max < sum) ||
2084-
(mounts > (max - sum)))
2085+
if (mounts > max)
20852086
return -ENOSPC;
20862087

2087-
ns->pending_mounts = pending + mounts;
2088+
ns->pending_mounts += mounts;
20882089
return 0;
20892090
}
20902091

0 commit comments

Comments
 (0)