[PATCH v4 6/8] nvme: set discard_granularity from NPDG/NPDA

Keith Busch kbusch at kernel.org
Thu Feb 26 13:20:02 PST 2026


On Thu, Feb 26, 2026 at 12:04:13PM -0700, Caleb Sander Mateos wrote:
> +	if (optperf & 0x2 && nvm && nvm->npdgl)
> +		npdg = le32_to_cpu(nvm->npdgl);
> +	else if (optperf & 0x1)
> +		npdg = from0based(id->npdg);
> +	if (optperf & 0x2 && nvm && nvm->npdal)
> +		npda = le32_to_cpu(nvm->npdal);
> +	else if (optperf)
> +		npda = from0based(id->npda);
> +	lim->discard_granularity = max(npdg, npda) * lim->logical_block_size;

I suspect some controller could report a very large npdal/npdgl such
that the multiplication result overflows the discard_granularity type,
so let's check with a fallback:

	if (check_mul_overflow(max(npdg, npda), lim->logical_block_size, &result))
		lim->discard_granularity = U32_MAX & (lim->logical_block_size - 1);



More information about the Linux-nvme mailing list