Subject: Re: [PATCH v3 net-next 4/8] mfd: zl3073x: Add support for devlink device info

From: Andy Shevchenko <[email-masked]>
Date: Thu, 17 Apr 2025 18:53:40 +0300

On Wed, Apr 16, 2025 at 06:21:40PM +0200, Ivan Vecera wrote:
> Use devlink_alloc() to alloc zl3073x_dev structure, register the device
> as a devlink device and add devlink callback to provide devlink device
> info.

...

>  /**
>   * zl3073x_devm_alloc - allocates zl3073x device structure
>   * @dev: pointer to device structure
> @@ -124,12 +204,18 @@ static const struct regmap_config zl3073x_regmap_config = {
>  struct zl3073x_dev *zl3073x_devm_alloc(struct device *dev)
>  {
>  	struct zl3073x_dev *zldev;
> +	struct devlink *devlink;
>  	int rc;
>  
> -	zldev = devm_kzalloc(dev, sizeof(*zldev), GFP_KERNEL);
> -	if (!zldev)
> +	devlink = devlink_alloc(&zl3073x_devlink_ops, sizeof(*zldev), dev);
> +	if (!devlink)
>  		return ERR_PTR(-ENOMEM);
>  
> +	/* Add devres action to free devlink device */
> +	if (devm_add_action_or_reset(dev, zl3073x_devlink_free, devlink))
> +		return ERR_PTR(-ENOMEM);

Please, do not shadow the error codes. You might miss something. Shadowing
error codes needs a good justification.

> +	zldev = devlink_priv(devlink);
>  	zldev->dev = dev;

>  }

...

> +	/* Add devres action to unregister devlink device */
> +	rc = devm_add_action_or_reset(zldev->dev, zl3073x_devlink_unregister,
> +				      devlink);
> +	if (rc)
> +		return rc;

The code is even inconsistent in one patch!

-- 
With Best Regards,
Andy Shevchenko