Skip to content

Commit ca2864c

Browse files
Hridya Valsarajugregkh
authored andcommitted
binder: Add default binder devices through binderfs when configured
Currently, since each binderfs instance needs its own private binder devices, every time a binderfs instance is mounted, all the default binder devices need to be created via the BINDER_CTL_ADD IOCTL. This patch aims to add a solution to automatically create the default binder devices for each binderfs instance that gets mounted. To achieve this goal, when CONFIG_ANDROID_BINDERFS is set, the default binder devices specified by CONFIG_ANDROID_BINDER_DEVICES are created in each binderfs instance instead of global devices being created by the binder driver. Co-developed-by: Christian Brauner <[email protected]> Signed-off-by: Christian Brauner <[email protected]> Signed-off-by: Hridya Valsaraju <[email protected]> Reviewed-by: Joel Fernandes (Google) <[email protected]> Link: https://lore.kernel.org/r/[email protected] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 028fb58 commit ca2864c

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

drivers/android/binder.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ static uint32_t binder_debug_mask = BINDER_DEBUG_USER_ERROR |
122122
BINDER_DEBUG_FAILED_TRANSACTION | BINDER_DEBUG_DEAD_TRANSACTION;
123123
module_param_named(debug_mask, binder_debug_mask, uint, 0644);
124124

125-
static char *binder_devices_param = CONFIG_ANDROID_BINDER_DEVICES;
125+
char *binder_devices_param = CONFIG_ANDROID_BINDER_DEVICES;
126126
module_param_named(devices, binder_devices_param, charp, 0444);
127127

128128
static DECLARE_WAIT_QUEUE_HEAD(binder_user_error_wait);
@@ -6131,7 +6131,8 @@ static int __init binder_init(void)
61316131
&transaction_log_fops);
61326132
}
61336133

6134-
if (strcmp(binder_devices_param, "") != 0) {
6134+
if (!IS_ENABLED(CONFIG_ANDROID_BINDERFS) &&
6135+
strcmp(binder_devices_param, "") != 0) {
61356136
/*
61366137
* Copy the module_parameter string, because we don't want to
61376138
* tokenize it in-place.

drivers/android/binder_internal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ struct binder_device {
3737

3838
extern const struct file_operations binder_fops;
3939

40+
extern char *binder_devices_param;
41+
4042
#ifdef CONFIG_ANDROID_BINDERFS
4143
extern bool is_binderfs_device(const struct inode *inode);
4244
#else

drivers/android/binderfs.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,7 @@ static int binderfs_binder_device_create(struct inode *ref_inode,
186186
req->major = MAJOR(binderfs_dev);
187187
req->minor = minor;
188188

189-
ret = copy_to_user(userp, req, sizeof(*req));
190-
if (ret) {
189+
if (userp && copy_to_user(userp, req, sizeof(*req))) {
191190
ret = -EFAULT;
192191
goto err;
193192
}
@@ -467,6 +466,9 @@ static int binderfs_fill_super(struct super_block *sb, void *data, int silent)
467466
int ret;
468467
struct binderfs_info *info;
469468
struct inode *inode = NULL;
469+
struct binderfs_device device_info = { 0 };
470+
const char *name;
471+
size_t len;
470472

471473
sb->s_blocksize = PAGE_SIZE;
472474
sb->s_blocksize_bits = PAGE_SHIFT;
@@ -521,7 +523,22 @@ static int binderfs_fill_super(struct super_block *sb, void *data, int silent)
521523
if (!sb->s_root)
522524
return -ENOMEM;
523525

524-
return binderfs_binder_ctl_create(sb);
526+
ret = binderfs_binder_ctl_create(sb);
527+
if (ret)
528+
return ret;
529+
530+
name = binder_devices_param;
531+
for (len = strcspn(name, ","); len > 0; len = strcspn(name, ",")) {
532+
strscpy(device_info.name, name, len + 1);
533+
ret = binderfs_binder_device_create(inode, NULL, &device_info);
534+
if (ret)
535+
return ret;
536+
name += len;
537+
if (*name == ',')
538+
name++;
539+
}
540+
541+
return 0;
525542
}
526543

527544
static struct dentry *binderfs_mount(struct file_system_type *fs_type,

0 commit comments

Comments
 (0)