From patchwork Thu Feb 1 06:33:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Nan X-Patchwork-Id: 195180 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:106:209c:c626 with SMTP id mn5csp259599dyc; Wed, 31 Jan 2024 23:04:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IHSp+TumkXEX2qN9QbLC8/GF7j5HWnJHjOn1/A+Xf9by/NTMBwdvOL9ELEjIoEU2vYAJ6eh X-Received: by 2002:a17:903:110f:b0:1d5:8aa5:d782 with SMTP id n15-20020a170903110f00b001d58aa5d782mr1791759plh.6.1706771050656; Wed, 31 Jan 2024 23:04:10 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706771050; cv=pass; d=google.com; s=arc-20160816; b=E0ZMhG+/YoUwHYGh+Pog4oEd1+45K4TYiASFXpy7CqqOFBVDcNQERn+7RcfWMGV+UE PWlPgUodsd2iaXh35HRcV2wC8cwlFD1NkqbsYnu63ddTHXv1FbdnMPnGw5ejbyOFDNRW DjLT47c8pyF6jiKP6XBjCQg93K8QsRk7MHx6k/98matNmz6lVT2i8ma5+MWaXWyTSISD gMIIJuuZ66UZxTNCrwdg21dF9Q6twHBu4hF6uxbqwqZE0sIvg7fRHpiuQHJmSM+XojOK X/NZlRXU7HAd8rkWbRG5Q/Aw94Vq7fksBU7WScdHoxmCdlDqTy4OqW3w5xY0A8Mp+YdF eAsw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=Dd/JcFp/S54D+5boQgS24d54LHi/+bb8+FacovUwvQ8=; fh=gIb9WGafyoxTts5bkAxxQ+mw5HzC/YEBs1Hu0uf0bCE=; b=U81jbInyKT0/5aIWGZGxwXIp+VU2+IEo6fDJYlesm99Q+NsffCIjOvjLMnNQ+ba0Ws XA5vhTBJLEX/mmSj9hdor1jFOyEam+fh9qV0Zk6O9AGFJ2Qhy+bXtIuTRq9TV/PT78RA 6NPeJYs8ZYevX1OD7RnFDqCYFhK4BNEdttPGXg2dZ6orssYPcJDPj2WomMltKOX2A3iH Rj7v+rXw72iYPx1OXgpftntKlMa77DuPTpGcse84sXYF0Xv/1j7cNWnEULTs3mtSFaL3 vO/aLFSw+78+OC/sJ+DnKvRHUskGY0ps1zZw6NnBXOlnrKzWuBZF2hyO0tbWObCsP9Vk 41+A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-47701-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47701-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCX4hvwA5nNCGVVBfUl33Q1dOpf9MT/0lxmlaSTDRQZKhJ7q3NGgoo8AXIdf1g+kPt+2REH0ZQSGoXMbJIxToOgD4BpDpg== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id y1-20020a17090322c100b001d44769173fsi11811407plg.245.2024.01.31.23.04.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 23:04:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-47701-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-47701-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47701-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 69100B2A0CD for ; Thu, 1 Feb 2024 06:40:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9331715AAC5; Thu, 1 Feb 2024 06:38:37 +0000 (UTC) Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4289E14C5A2; Thu, 1 Feb 2024 06:38:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706769515; cv=none; b=U1V9cUGlMGH86SoDErcyfYaTyX9syGz0xVSw+oXj/Rg/3lc1ReqT0z3qBYSZNRXXLcAcQaUDpl7WQOsxD2fBPlEuDESwHEm8o4H02/bS+lwOEdcJT1B75FNyx4M4Ylm/+i/FJ2eStS9Xs37SHyv02U/LdCvZTq8SUxhIwFBoxww= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706769515; c=relaxed/simple; bh=jP4m22rQj6WvFme4jcbJ2GC1m3E6QRznh9H3QFX0PjE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=W9k7xrNN7tpPKYcRZLLlig5NTHz1ySUioHIocC0djGRBpNagZ0u/wln5B1J7SAEgTJkuJyxgpkRNO2kY2a8Ln+fhux7OskdS/fvYzd/m1g3KbppDOSZ0tH/kzaMRxzgPjshgA0yRDtBICem31aJuMRUBEo0tmJE3gxuJKfQDr3s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4TQTkS3zN7z4f3kns; Thu, 1 Feb 2024 14:38:24 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id BC2711A027B; Thu, 1 Feb 2024 14:38:28 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX5g5iPLtllCl+Cg--.15155S5; Thu, 01 Feb 2024 14:38:28 +0800 (CST) From: linan666@huaweicloud.com To: song@kernel.org, neilb@suse.com, mariusz.tkaczyk@linux.intel.com, shli@fb.com Cc: linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org, linan666@huaweicloud.com, yukuai3@huawei.com, yi.zhang@huawei.com, houtao1@huawei.com, yangerkun@huawei.com Subject: [PATCH v5 1/8] md: merge the check of capabilities into md_ioctl_valid() Date: Thu, 1 Feb 2024 14:33:57 +0800 Message-Id: <20240201063404.772797-2-linan666@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240201063404.772797-1-linan666@huaweicloud.com> References: <20240201063404.772797-1-linan666@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAX5g5iPLtllCl+Cg--.15155S5 X-Coremail-Antispam: 1UD129KBjvJXoW7tFW7Wr15Wry7tw15KF13CFg_yoW8Ar17pF 4fJFWay3y5try7GF45t3ykCa45Zwn2q3yrJrWaka4vq3WUA3yUGryrGw4Fvas3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ved-from-mailbox: INBOX X-GMAIL-THRID: 1789679161045500616 X-GMAIL-MSGID: 1789679161045500616 From: Li Nan There is no functional change. Just to make code cleaner. Signed-off-by: Li Nan Reviewed-by: Yu Kuai --- drivers/md/md.c | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/drivers/md/md.c b/drivers/md/md.c index e351e6c51cc7..1b509fb82040 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -7545,16 +7545,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_valid(unsigned int cmd) { switch (cmd) { - case ADD_NEW_DISK: case GET_ARRAY_INFO: - case GET_BITMAP_FILE: case GET_DISK_INFO: + case RAID_VERSION: + return 0; + 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: @@ -7563,9 +7564,11 @@ 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; + return 0; default: - return false; + return -ENOTTY; } } @@ -7625,18 +7628,9 @@ static int md_ioctl(struct block_device *bdev, blk_mode_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_valid(cmd); + if (err) + return err; /* * Commands dealing with the RAID driver but not any