Re: [PATCH 1/2] nvme: keep transport module referenced while head node is open

Keith Busch <[email protected]>
Newsgroups org.infradead.lists.linux-nvme
Message-ID <apb_3yu6G0dx_rWe@kbusch-mbp>
On Mon, Aug 31, 2026 at 08:49:54PM +0530, Nilay Shroff wrote:
> +static inline int nvme_module_get(struct nvme_ns *ns, unsigned int count)
> +{
> +	unsigned int i;
> +
> +	for (i = 0; i < count; i++) {
> +		if (!try_module_get(ns->ctrl->ops->module))
> +			goto out_unwind;
> +	}
> +
> +	return 0;
> +out_unwind:
> +	while (i--)
> +		module_put(ns->ctrl->ops->module);
> +	return -ENXIO;
> +}
> +
> +static inline void nvme_module_put(struct nvme_ns *ns, unsigned int count)
> +{
> +	while (count--)
> +		module_put(ns->ctrl->ops->module);
> +}

Thanks, looks correct to me.

I don't like the looping though. This could be done in a single
atomic_sub instead of multiple atomic_dec calls if the module api
provided something to get/put many references.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.