Skip to content

Commit 36bdf3c

Browse files
braunergregkh
authored andcommitted
binderfs: reserve devices for initial mount
The binderfs instance in the initial ipc namespace will always have a reserve of 4 binder devices unless explicitly capped by specifying a lower value via the "max" mount option. This ensures when binder devices are removed (on accident or on purpose) they can always be recreated without risking that all minor numbers have already been used up. Cc: Todd Kjos <tkjos@google.com> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent c13295a commit 36bdf3c

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

‎drivers/android/binderfs.c‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
#define INODE_OFFSET 3
4141
#define INTSTRLEN 21
4242
#define BINDERFS_MAX_MINOR (1U << MINORBITS)
43+
/* Ensure that the initial ipc namespace always has devices available. */
44+
#define BINDERFS_MAX_MINOR_CAPPED (BINDERFS_MAX_MINOR - 4)
4345

4446
static dev_t binderfs_dev;
4547
static DEFINE_MUTEX(binderfs_minors_mutex);
@@ -127,11 +129,14 @@ static int binderfs_binder_device_create(struct inode *ref_inode,
127129
struct inode *inode = NULL;
128130
struct super_block *sb = ref_inode->i_sb;
129131
struct binderfs_info *info = sb->s_fs_info;
132+
bool use_reserve = (info->ipc_ns == &init_ipc_ns);
130133

131134
/* Reserve new minor number for the new device. */
132135
mutex_lock(&binderfs_minors_mutex);
133136
if (++info->device_count <= info->mount_opts.max)
134-
minor = ida_alloc_max(&binderfs_minors, BINDERFS_MAX_MINOR,
137+
minor = ida_alloc_max(&binderfs_minors,
138+
use_reserve ? BINDERFS_MAX_MINOR :
139+
BINDERFS_MAX_MINOR_CAPPED,
135140
GFP_KERNEL);
136141
else
137142
minor = -ENOSPC;

0 commit comments

Comments
 (0)