Re: [PATCH v4 1/4] dmaengine: add dma_device_get() helper

Frank Li <[email protected]>
Newsgroups org.kernel.vger.dmaengine,org.kernel.vger.linux-kernel,org.kernel.vger.stable
Message-ID <aoSEe2FujhG6J0iD@SMW015318>
On Tue, Aug 18, 2026 at 03:43:45AM +0000, Shivank Garg wrote:
> Add dma_device_get() helper to match dma_device_put() to make code
> symmetric. It wraps open-coded kref_get_unless_zero() and asserts that
> dma_list_mutex is held, matching its put counterpart.
>
> No functional change intended.
>
> Suggested-by: Frank Li <[email protected]>
> Signed-off-by: Shivank Garg <[email protected]>
> ---
>  drivers/dma/dmaengine.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c
> index 6ffd8bd82154..77638dc16e71 100644
> --- a/drivers/dma/dmaengine.c
> +++ b/drivers/dma/dmaengine.c
> @@ -433,6 +433,12 @@ static void dma_device_release(struct kref *ref)
>  		device->device_release(device);
>  }
>
> +static bool dma_device_get(struct dma_device *device)

Please the same return type of kref_get_unless_zero(),

it should be int.

Frank

> +{
> +	lockdep_assert_held(&dma_list_mutex);
> +	return kref_get_unless_zero(&device->ref);
> +}
> +
>  static void dma_device_put(struct dma_device *device)
>  {
>  	lockdep_assert_held(&dma_list_mutex);
> @@ -460,8 +466,7 @@ static int dma_chan_get(struct dma_chan *chan)
>  	if (!try_module_get(owner))
>  		return -ENODEV;
>
> -	ret = kref_get_unless_zero(&chan->device->ref);
> -	if (!ret) {
> +	if (!dma_device_get(chan->device)) {
>  		ret = -ENODEV;
>  		goto module_put_out;
>  	}
>
> --
> 2.43.0
>
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.