mutex_lock(&pipe->inode->i_mutex);
switch (cmd) {
- case F_SETPIPE_SZ:
- if (!capable(CAP_SYS_ADMIN) && arg > pipe_max_pages) {
- ret = -EINVAL;
+ case F_SETPIPE_SZ: {
+ unsigned long nr_pages;
+
+ /*
+ * Currently the array must be a power-of-2 size, so adjust
+ * upwards if needed.
+ */
+ nr_pages = (arg + PAGE_SIZE - 1) >> PAGE_SHIFT;
+ nr_pages = roundup_pow_of_two(nr_pages);
+
- if (!capable(CAP_SYS_ADMIN) && nr_pages > pipe_max_pages)
- return -EPERM;
++ if (!capable(CAP_SYS_ADMIN) && nr_pages > pipe_max_pages) {
++ ret = -EPERM;
+ goto out;
+ }
+
/*
* The pipe needs to be at least 2 pages large to
* guarantee POSIX behaviour.
*/
- if (nr_pages < 2)
- return -EINVAL;
- ret = pipe_set_size(pipe, nr_pages);
+ if (arg < 2) {
+ ret = -EINVAL;
+ goto out;
+ }
+ ret = pipe_set_size(pipe, arg);
break;
+ }
case F_GETPIPE_SZ:
- ret = pipe->buffers;
+ ret = pipe->buffers * PAGE_SIZE;
break;
default:
ret = -EINVAL;