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

Serge Semin fancer.lancer at gmail.com
Tue Oct 18 08:44:02 PDT 2022


On Tue, Oct 18, 2022 at 05:38:41PM +0200, Christoph Hellwig wrote:
> On Tue, Oct 18, 2022 at 06:31:36PM +0300, Serge Semin wrote:
> > What about just taking the -EINTR error into account by the
> > nvme_hwmon_init() caller and ignore any other there? Meanwhile you can
> > convert the nvme_hwmon_init() method to return any error including the
> > ENOMEM. Thus the function will be more consistent and will have
> > independent from the caller context design.
> 

> Yeah, that actually looks a tad cleaner than what I just sent out:

> 
> diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
> index 9cbe7854d4883..7c949f44e1db2 100644
> --- a/drivers/nvme/host/core.c
> +++ b/drivers/nvme/host/core.c
> @@ -3261,9 +3261,13 @@ int nvme_init_ctrl_finish(struct nvme_ctrl *ctrl)
>  	if (ret < 0)
>  		return ret;
>  
> +	/*
> +	 * Do not return errors unless we are in a controller reset.
> +	 * The controller works perfectly fine without the hwmon registration.
> +	 */
>  	if (!ctrl->identified && !nvme_discovery_ctrl(ctrl)) {
>  		ret = nvme_hwmon_init(ctrl);

> -		if (ret < 0)
> +		if (err == -EINTR)
>  			return ret;

Note: s/err/ret

Exactly what I meant. Looks good to me.

-Sergey

>  	}
>  
> diff --git a/drivers/nvme/host/hwmon.c b/drivers/nvme/host/hwmon.c
> index 0a586d7129201..23918bb7bdca2 100644
> --- a/drivers/nvme/host/hwmon.c
> +++ b/drivers/nvme/host/hwmon.c
> @@ -230,7 +230,7 @@ int nvme_hwmon_init(struct nvme_ctrl *ctrl)
>  
>  	data = kzalloc(sizeof(*data), GFP_KERNEL);
>  	if (!data)
> -		return 0;
> +		return -ENOMEM;
>  
>  	data->ctrl = ctrl;
>  	mutex_init(&data->read_lock);
> @@ -238,8 +238,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 err_free_data;
>  	}
>  
>  	hwmon = hwmon_device_register_with_info(dev, "nvme",
> @@ -247,11 +246,15 @@ 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);
> +		err = PTR_ERR(hwmon);
> +		goto err_free_data;
>  	}
>  	ctrl->hwmon_device = hwmon;
>  	return 0;
> +
> +err_free_data:
> +	kfree(data);
> +	return err;
>  }
>  
>  void nvme_hwmon_exit(struct nvme_ctrl *ctrl)



More information about the Linux-nvme mailing list