Subject: Re: [PATCH v4 07/14] net-next/yunsilicon: Init auxiliary device

From: Leon Romanovsky <[email-masked]>
Date: Thu, 13 Feb 2025 16:37:02 +0200

On Thu, Feb 13, 2025 at 05:14:19PM +0800, Xin Tian wrote:
> Initialize eth auxiliary device when pci probing
> 
> Co-developed-by: Honggang Wei <[email-masked]>
> Signed-off-by: Honggang Wei <[email-masked]>
> Co-developed-by: Lei Yan <[email-masked]>
> Signed-off-by: Lei Yan <[email-masked]>
> Signed-off-by: Xin Tian <[email-masked]>
> ---
>  .../ethernet/yunsilicon/xsc/common/xsc_core.h |  12 ++
>  .../net/ethernet/yunsilicon/xsc/pci/Makefile  |   3 +-
>  .../net/ethernet/yunsilicon/xsc/pci/adev.c    | 110 ++++++++++++++++++
>  .../net/ethernet/yunsilicon/xsc/pci/adev.h    |  14 +++
>  .../net/ethernet/yunsilicon/xsc/pci/main.c    |  10 ++
>  5 files changed, 148 insertions(+), 1 deletion(-)
>  create mode 100644 drivers/net/ethernet/yunsilicon/xsc/pci/adev.c
>  create mode 100644 drivers/net/ethernet/yunsilicon/xsc/pci/adev.h

<...>

> diff --git a/drivers/net/ethernet/yunsilicon/xsc/pci/adev.c b/drivers/net/ethernet/yunsilicon/xsc/pci/adev.c
> new file mode 100644
> index 000000000..1f8f27d72
> --- /dev/null
> +++ b/drivers/net/ethernet/yunsilicon/xsc/pci/adev.c
> @@ -0,0 +1,110 @@
> +// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
> +/*
> + * Copyright (C) 2021-2025, Shanghai Yunsilicon Technology Co., Ltd.
> + * All rights reserved.
> + */
> +
> +#include <linux/auxiliary_bus.h>
> +#include <linux/idr.h>
> +
> +#include "adev.h"
> +
> +static DEFINE_IDA(xsc_adev_ida);
> +
> +enum xsc_adev_idx {
> +	XSC_ADEV_IDX_ETH,
> +	XSC_ADEV_IDX_MAX
> +};
> +
> +static const char * const xsc_adev_name[] = {
> +	[XSC_ADEV_IDX_ETH] = XSC_ETH_ADEV_NAME,
> +};
> +
> +static void xsc_release_adev(struct device *dev)
> +{
> +	/* Doing nothing, but auxiliary bus requires a release function */
> +}

It is unlikely to be true in driver lifetime model. At least you should
free xsc_adev here.

Thanks

> +
> +static int xsc_reg_adev(struct xsc_core_device *xdev, int idx)
> +{
> +	struct auxiliary_device	*adev;
> +	struct xsc_adev *xsc_adev;
> +	int ret;
> +
> +	xsc_adev = kzalloc(sizeof(*xsc_adev), GFP_KERNEL);
> +	if (!xsc_adev)
> +		return -ENOMEM;
> +
> +	adev = &xsc_adev->adev;
> +	adev->name = xsc_adev_name[idx];
> +	adev->id = xdev->adev_id;
> +	adev->dev.parent = &xdev->pdev->dev;
> +	adev->dev.release = xsc_release_adev;
> +	xsc_adev->xdev = xdev;
> +
> +	ret = auxiliary_device_init(adev);
> +	if (ret)
> +		goto err_free_adev;
> +
> +	ret = auxiliary_device_add(adev);
> +	if (ret)
> +		goto err_uninit_adev;
> +
> +	xdev->xsc_adev_list[idx] = xsc_adev;
> +
> +	return 0;
> +err_uninit_adev:
> +	auxiliary_device_uninit(adev);
> +err_free_adev:
> +	kfree(xsc_adev);
> +
> +	return ret;
> +}