[PATCH v3] nvme: core: reject invalid LBA data size from Identify Namespace
John Garry
john.g.garry at oracle.com
Wed Jun 3 03:08:10 PDT 2026
On 02/06/2026 17:18, John Garry wrote:
>
>> I say we can ignore the sparse warning, or we
>> can rewrite this to avoid the check_shl_overflow entirely.
>
FWIW, adding a separate function keeps sparse happy for me:
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index ea837b94d3e5..3ec98038668e 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -2364,6 +2364,11 @@ static int nvme_query_fdp_info(struct nvme_ns
*ns, struct nvme_ns_info *info)
return ret;
}
+static bool nvme_valid_ds(u64 nsze, signed int shift, u64 *capacity)
+{
+ return check_shl_overflow(nsze, shift, capacity);
+}
+
static int nvme_update_ns_info_block(struct nvme_ns *ns,
struct nvme_ns_info *info)
{
@@ -2407,10 +2412,8 @@ static int nvme_update_ns_info_block(struct
nvme_ns *ns,
goto out;
}
- if (id->lbaf[lbaf].ds < SECTOR_SHIFT ||
- check_shl_overflow(le64_to_cpu(id->nsze),
- id->lbaf[lbaf].ds - SECTOR_SHIFT,
- &capacity)) {
+ if (nvme_valid_ds(le64_to_cpu(id->nsze),
+ id->lbaf[lbaf].ds - SECTOR_SHIFT, &capacity)) {
dev_warn_once(ns->ctrl->device,
"invalid LBA data size %u, skipping namespace\n",
id->lbaf[lbaf].ds);
More information about the Linux-nvme
mailing list