[PATCH] nvme-hwmon: don't return errors from nvme_hwmon_init

Serge Semin fancer.lancer at gmail.com
Tue Oct 18 08:14:21 PDT 2022


On Tue, Oct 18, 2022 at 04:58:08PM +0200, Christoph Hellwig wrote:
> An NVMe controller works perfectly fine even when the hwmon
> initialization fails.  Stop returning errors from nvme_hwmon_init to
> handle this case consistently.
> 
> Signed-off-by: Christoph Hellwig <hch at lst.de>

I was going to resubmit the series taking into account your resolution
on this issue since patch #3 still needs to be resent. But you just
submitted a fixup patch. Less worries to me. I'll resend patch #3
separately then. Thanks.

Reviewed-by: Serge Semin <fancer.lancer at gmail.com>

-Sergey

> ---
> 
> This should go before the patch from Serge to document and consistently
> handle the lack of initialization failure handling for hwmon.
> 
>  drivers/nvme/host/core.c  |  7 ++-----
>  drivers/nvme/host/hwmon.c | 16 +++++++++-------
>  drivers/nvme/host/nvme.h  |  5 ++---
>  3 files changed, 13 insertions(+), 15 deletions(-)
> 
> diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
> index 9cbe7854d4883..952768966bdcd 100644
> --- a/drivers/nvme/host/core.c
> +++ b/drivers/nvme/host/core.c
> @@ -3261,11 +3261,8 @@ int nvme_init_ctrl_finish(struct nvme_ctrl *ctrl)
>  	if (ret < 0)
>  		return ret;
>  
> -	if (!ctrl->identified && !nvme_discovery_ctrl(ctrl)) {
> -		ret = nvme_hwmon_init(ctrl);
> -		if (ret < 0)
> -			return ret;
> -	}
> +	if (!ctrl->identified && !nvme_discovery_ctrl(ctrl))
> +		nvme_hwmon_init(ctrl);
>  
>  	ctrl->identified = true;
>  
> diff --git a/drivers/nvme/host/hwmon.c b/drivers/nvme/host/hwmon.c
> index 0a586d7129201..c6ddb8b46c699 100644
> --- a/drivers/nvme/host/hwmon.c
> +++ b/drivers/nvme/host/hwmon.c
> @@ -221,7 +221,8 @@ static const struct hwmon_chip_info nvme_hwmon_chip_info = {
>  	.info	= nvme_hwmon_info,
>  };
>  
> -int nvme_hwmon_init(struct nvme_ctrl *ctrl)
> +/* do not return errors - nvme works fine without hwmon registration */
> +void nvme_hwmon_init(struct nvme_ctrl *ctrl)
>  {
>  	struct device *dev = ctrl->device;
>  	struct nvme_hwmon_data *data;
> @@ -230,7 +231,7 @@ int nvme_hwmon_init(struct nvme_ctrl *ctrl)
>  
>  	data = kzalloc(sizeof(*data), GFP_KERNEL);
>  	if (!data)
> -		return 0;
> +		return;
>  
>  	data->ctrl = ctrl;
>  	mutex_init(&data->read_lock);
> @@ -238,8 +239,7 @@ int nvme_hwmon_init(struct nvme_ctrl *ctrl)
>  	err = nvme_hwmon_get_smart_log(data);
>  	if (err) {
>  		dev_warn(dev, "Failed to read smart log (error %d)\n", err);
> -		kfree(data);
> -		return err;
> +		goto out_free_data;
>  	}
>  
>  	hwmon = hwmon_device_register_with_info(dev, "nvme",
> @@ -247,11 +247,13 @@ int nvme_hwmon_init(struct nvme_ctrl *ctrl)
>  						NULL);
>  	if (IS_ERR(hwmon)) {
>  		dev_warn(dev, "Failed to instantiate hwmon device\n");
> -		kfree(data);
> -		return PTR_ERR(hwmon);
> +		goto out_free_data;
>  	}
>  	ctrl->hwmon_device = hwmon;
> -	return 0;
> +	return;
> +
> +out_free_data:
> +	kfree(data);
>  }
>  
>  void nvme_hwmon_exit(struct nvme_ctrl *ctrl)
> diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
> index a29877217ee65..4cd3e00c47a2b 100644
> --- a/drivers/nvme/host/nvme.h
> +++ b/drivers/nvme/host/nvme.h
> @@ -1000,12 +1000,11 @@ static inline struct nvme_ns *nvme_get_ns_from_dev(struct device *dev)
>  }
>  
>  #ifdef CONFIG_NVME_HWMON
> -int nvme_hwmon_init(struct nvme_ctrl *ctrl);
> +void nvme_hwmon_init(struct nvme_ctrl *ctrl);
>  void nvme_hwmon_exit(struct nvme_ctrl *ctrl);
>  #else
> -static inline int nvme_hwmon_init(struct nvme_ctrl *ctrl)
> +static inline void nvme_hwmon_init(struct nvme_ctrl *ctrl)
>  {
> -	return 0;
>  }
>  
>  static inline void nvme_hwmon_exit(struct nvme_ctrl *ctrl)
> -- 
> 2.30.2
> 



More information about the Linux-nvme mailing list