[PATCH] nvme: keep ctrl->namespaces ordered

Keith Busch kbusch at kernel.org
Wed Sep 15 05:37:35 PDT 2021


On Wed, Sep 15, 2021 at 07:36:04AM +0000, Damien Le Moal 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);
> 
> I wonder if it is worth checking that ns->head->id is not equal to the ID of the
> first NS in the list. That can only happen for a very buggy system or device,
> but that is not unheard of...

We would never be able to hit the condition of two heads with matching
NSID's. If the controller was broken and provided duplicate NSIDs in the
namespace list, this driver will just recheck the first namespace rather
than allocate a new one.



More information about the Linux-nvme mailing list