Skip to content

Commit 2fe4ffc

Browse files
Li Nanliu-song-6
authored andcommitted
md: merge the check of capabilities into md_ioctl_valid()
There is no functional change. Just to make code cleaner. Signed-off-by: Li Nan <[email protected]> Reviewed-by: Yu Kuai <[email protected]> Signed-off-by: Song Liu <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 82c6515 commit 2fe4ffc

File tree

1 file changed

+12
-18
lines changed

1 file changed

+12
-18
lines changed

drivers/md/md.c

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7522,16 +7522,17 @@ static int md_getgeo(struct block_device *bdev, struct hd_geometry *geo)
75227522
return 0;
75237523
}
75247524

7525-
static inline bool md_ioctl_valid(unsigned int cmd)
7525+
static inline int md_ioctl_valid(unsigned int cmd)
75267526
{
75277527
switch (cmd) {
7528-
case ADD_NEW_DISK:
75297528
case GET_ARRAY_INFO:
7530-
case GET_BITMAP_FILE:
75317529
case GET_DISK_INFO:
7530+
case RAID_VERSION:
7531+
return 0;
7532+
case ADD_NEW_DISK:
7533+
case GET_BITMAP_FILE:
75327534
case HOT_ADD_DISK:
75337535
case HOT_REMOVE_DISK:
7534-
case RAID_VERSION:
75357536
case RESTART_ARRAY_RW:
75367537
case RUN_ARRAY:
75377538
case SET_ARRAY_INFO:
@@ -7540,9 +7541,11 @@ static inline bool md_ioctl_valid(unsigned int cmd)
75407541
case STOP_ARRAY:
75417542
case STOP_ARRAY_RO:
75427543
case CLUSTERED_DISK_NACK:
7543-
return true;
7544+
if (!capable(CAP_SYS_ADMIN))
7545+
return -EACCES;
7546+
return 0;
75447547
default:
7545-
return false;
7548+
return -ENOTTY;
75467549
}
75477550
}
75487551

@@ -7602,18 +7605,9 @@ static int md_ioctl(struct block_device *bdev, blk_mode_t mode,
76027605
struct mddev *mddev = NULL;
76037606
bool did_set_md_closing = false;
76047607

7605-
if (!md_ioctl_valid(cmd))
7606-
return -ENOTTY;
7607-
7608-
switch (cmd) {
7609-
case RAID_VERSION:
7610-
case GET_ARRAY_INFO:
7611-
case GET_DISK_INFO:
7612-
break;
7613-
default:
7614-
if (!capable(CAP_SYS_ADMIN))
7615-
return -EACCES;
7616-
}
7608+
err = md_ioctl_valid(cmd);
7609+
if (err)
7610+
return err;
76177611

76187612
/*
76197613
* Commands dealing with the RAID driver but not any

0 commit comments

Comments
 (0)