Rename md_ioctl_valid to md_ioctl_check, check whether the command is valid and whether the permission passes. Signed-off-by: Ye Bin <yebin10@xxxxxxxxxx> --- drivers/md/md.c | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/drivers/md/md.c b/drivers/md/md.c index 729be2c5296c..19960bb33f6d 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -7440,16 +7440,17 @@ static int md_getgeo(struct block_device *bdev, struct hd_geometry *geo) return 0; } -static inline bool md_ioctl_valid(unsigned int cmd) +static inline int md_ioctl_check(unsigned int cmd) { switch (cmd) { - case ADD_NEW_DISK: + case RAID_VERSION: case GET_ARRAY_INFO: - case GET_BITMAP_FILE: case GET_DISK_INFO: + break; + case ADD_NEW_DISK: + case GET_BITMAP_FILE: case HOT_ADD_DISK: case HOT_REMOVE_DISK: - case RAID_VERSION: case RESTART_ARRAY_RW: case RUN_ARRAY: case SET_ARRAY_INFO: @@ -7458,10 +7459,14 @@ static inline bool md_ioctl_valid(unsigned int cmd) case STOP_ARRAY: case STOP_ARRAY_RO: case CLUSTERED_DISK_NACK: - return true; + if (!capable(CAP_SYS_ADMIN)) + return -EACCES; + break; default: - return false; + return -ENOTTY; } + + return 0; } static int md_ioctl(struct block_device *bdev, fmode_t mode, @@ -7472,18 +7477,9 @@ static int md_ioctl(struct block_device *bdev, fmode_t mode, struct mddev *mddev = NULL; bool did_set_md_closing = false; - if (!md_ioctl_valid(cmd)) - return -ENOTTY; - - switch (cmd) { - case RAID_VERSION: - case GET_ARRAY_INFO: - case GET_DISK_INFO: - break; - default: - if (!capable(CAP_SYS_ADMIN)) - return -EACCES; - } + err = md_ioctl_check(cmd); + if (err) + return err; /* * Commands dealing with the RAID driver but not any -- 2.31.1