[PATCH] nvme: keep ctrl->namespaces ordered

Keith Busch kbusch at kernel.org
Wed Sep 15 07:10:35 PDT 2021


On Wed, Sep 15, 2021 at 09:20:06AM +0200, Christoph Hellwig wrote:
> +static void nvme_ns_add_to_ctrl_list(struct nvme_ns *ns)
> +{
> +	struct nvme_ns *tmp;
> +
> +	list_for_each_entry_reverse(tmp, &ns->ctrl->namespaces, list) {
> +		if (tmp->head->ns_id < ns->head->ns_id) {
> +			list_add(&tmp->list, &ns->ctrl->namespaces);
> +			return;
> +		}
> +	}
> +
> +	list_add_tail(&ns->list, &ns->ctrl->namespaces);

Actually, this list_add_tail() looks wrong. If the new 'ns' has the
lowest nsid, then we need it added at the head, so this should just be a
"list_add()".



More information about the Linux-nvme mailing list