From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 402F53BCD01 for ; Mon, 20 Jul 2026 20:18:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784578734; cv=none; b=HlCI8+/sSbUJ/ez3p6GYabDJKKzxDkJDaSmefsQdsRUd2vdpri/zvXugXTO3e27WRC0DQ58SaIdfhHbd5uF7tdQUWoaWpn5ht34J+fdnuWzwsQyHMvlYET8wQSpMZ6YgDXZpaTDWA58HVKupaGMp2QYZPKti19mkP205cOaeRfU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784578734; c=relaxed/simple; bh=4FyuTkwbqfh2fh5kMsLr7bSHIwxA/kMJjmDdbvxdG4o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Nvk1mEtPuUY7RKm9wOhAcMI7idlO6WdY1f2SWVTseaDnnbG+t+1keI43eY3zPvEbDllkJ4G0IPX/AEobRFMYzOfWQeGz4ItUW0x+fSQH5qXhVURwucL4d6erbgvoVLYfYlvu14xdi61jS1OmklQNcmRbHfBSPvWq9wnArPQR/C0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=IyF8rVdv; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="IyF8rVdv" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 14A151F000E9; Mon, 20 Jul 2026 20:18:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1784578732; bh=NZWoaDozpMgmEnRxeIaSMGm3PAqhC8yBmnWdDoUeC3I=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=IyF8rVdv8i6iMHgPNVmRzQ1yXhMJ8D/s0nSf/V2joiofFcEaBW4j2/4VyrUYq0H+8 NNIhl612HJzKaczvuEMenITZoZ2Y2dajSXmeEYiJGrMJFRm1O5xgEOI3ypbt0T5s97 vQxOAv4dHadAGLD9reu9ibu88X0xUeYxGjdgtOjC1vvc2+oGdvBNMd2oGi+pGuDfF7 gccM3Y0iFjdUG2vKG68VAFXguHN+RTTcfkFLrixOa80fdfZ5N5iP9PAjTSPFFaC4sr Z+ntx8qIxCvuf/Mh7R3PeXtvofyn3tWkjj5DKRKiVlR4bWIZFl/SdqZMtZeNVrQZQN 8r93cJv/AqORQ== From: Sasha Levin To: stable@vger.kernel.org Cc: Weiwen Hu , Sagi Grimberg , Chaitanya Kulkarni , Christoph Hellwig , Keith Busch , Sasha Levin Subject: [PATCH 5.15.y 1/3] nvme: fix status magic numbers Date: Mon, 20 Jul 2026 16:18:48 -0400 Message-ID: <20260720201850.3239465-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026071541-variably-lion-7934@gregkh> References: <2026071541-variably-lion-7934@gregkh> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Weiwen Hu [ Upstream commit d89a5c6705998ddc42b104f8eabd3c4b9e8fde08 ] Replaced some magic numbers about SC and SCT with enum and macro. Signed-off-by: Weiwen Hu Reviewed-by: Sagi Grimberg Reviewed-by: Chaitanya Kulkarni Reviewed-by: Christoph Hellwig Signed-off-by: Keith Busch Stable-dep-of: 53cd102a7a56 ("nvmet: fix pre-auth out-of-bounds heap read in Discovery Get Log Page") Signed-off-by: Sasha Levin --- drivers/nvme/host/core.c | 4 ++-- drivers/nvme/host/multipath.c | 2 +- drivers/nvme/host/nvme.h | 4 ++-- include/linux/nvme.h | 14 ++++++++++++-- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index f3071bd11fdd39..4902a4a1d3a31f 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -262,7 +262,7 @@ static void nvme_delete_ctrl_sync(struct nvme_ctrl *ctrl) static blk_status_t nvme_error_status(u16 status) { - switch (status & 0x7ff) { + switch (status & NVME_SCT_SC_MASK) { case NVME_SC_SUCCESS: return BLK_STS_OK; case NVME_SC_CAP_EXCEEDED: @@ -1248,7 +1248,7 @@ EXPORT_SYMBOL_NS_GPL(nvme_execute_passthru_rq, NVME_TARGET_PASSTHRU); /* * Recommended frequency for KATO commands per NVMe 1.4 section 7.12.1: - * + * * The host should send Keep Alive commands at half of the Keep Alive Timeout * accounting for transport roundtrip times [..]. */ diff --git a/drivers/nvme/host/multipath.c b/drivers/nvme/host/multipath.c index 4bc0ce9c16df19..8dda563e6e4822 100644 --- a/drivers/nvme/host/multipath.c +++ b/drivers/nvme/host/multipath.c @@ -68,7 +68,7 @@ bool nvme_mpath_set_disk_name(struct nvme_ns *ns, char *disk_name, int *flags) void nvme_failover_req(struct request *req) { struct nvme_ns *ns = req->q->queuedata; - u16 status = nvme_req(req)->status & 0x7ff; + u16 status = nvme_req(req)->status & NVME_SCT_SC_MASK; unsigned long flags; struct bio *bio; diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h index c6cd3d65065c8e..c7674a2d076ec8 100644 --- a/drivers/nvme/host/nvme.h +++ b/drivers/nvme/host/nvme.h @@ -615,7 +615,7 @@ static inline u32 nvme_bytes_to_numd(size_t len) static inline bool nvme_is_ana_error(u16 status) { - switch (status & 0x7ff) { + switch (status & NVME_SCT_SC_MASK) { case NVME_SC_ANA_TRANSITION: case NVME_SC_ANA_INACCESSIBLE: case NVME_SC_ANA_PERSISTENT_LOSS: @@ -628,7 +628,7 @@ static inline bool nvme_is_ana_error(u16 status) static inline bool nvme_is_path_error(u16 status) { /* check for a status code type of 'path related status' */ - return (status & 0x700) == 0x300; + return (status & NVME_SCT_MASK) == NVME_SCT_PATH; } /* diff --git a/include/linux/nvme.h b/include/linux/nvme.h index 94fa0184c153f4..ab9d26a9406563 100644 --- a/include/linux/nvme.h +++ b/include/linux/nvme.h @@ -1485,6 +1485,7 @@ enum { /* * Generic Command Status: */ + NVME_SCT_GENERIC = 0x0, NVME_SC_SUCCESS = 0x0, NVME_SC_INVALID_OPCODE = 0x1, NVME_SC_INVALID_FIELD = 0x2, @@ -1531,6 +1532,7 @@ enum { /* * Command Specific Status: */ + NVME_SCT_COMMAND_SPECIFIC = 0x100, NVME_SC_CQ_INVALID = 0x100, NVME_SC_QID_INVALID = 0x101, NVME_SC_QUEUE_SIZE = 0x102, @@ -1604,6 +1606,7 @@ enum { /* * Media and Data Integrity Errors: */ + NVME_SCT_MEDIA_ERROR = 0x200, NVME_SC_WRITE_FAULT = 0x280, NVME_SC_READ_ERROR = 0x281, NVME_SC_GUARD_CHECK = 0x282, @@ -1616,16 +1619,23 @@ enum { /* * Path-related Errors: */ + NVME_SCT_PATH = 0x300, NVME_SC_ANA_PERSISTENT_LOSS = 0x301, NVME_SC_ANA_INACCESSIBLE = 0x302, NVME_SC_ANA_TRANSITION = 0x303, NVME_SC_HOST_PATH_ERROR = 0x370, NVME_SC_HOST_ABORTED_CMD = 0x371, - NVME_SC_CRD = 0x1800, - NVME_SC_DNR = 0x4000, + NVME_SC_MASK = 0x00ff, /* Status Code */ + NVME_SCT_MASK = 0x0700, /* Status Code Type */ + NVME_SCT_SC_MASK = NVME_SCT_MASK | NVME_SC_MASK, + + NVME_SC_CRD = 0x1800, /* Command Retry Delayed */ + NVME_SC_DNR = 0x4000, /* Do Not Retry */ }; +#define NVME_SCT(status) ((status) >> 8 & 7) + struct nvme_completion { /* * Used by Admin and Fabrics commands to return data: -- 2.53.0