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

Keith Busch kbusch at kernel.org
Tue Oct 18 08:26:24 PDT 2022


On Tue, Oct 18, 2022 at 05:23:09PM +0200, Christoph Hellwig wrote:
> On Tue, Oct 18, 2022 at 09:15:08AM -0600, Keith Busch wrote:
> > We still need to check for < 0 since nvme_hwmon_init() sends an admin
> > command. If the admin command times out, the controller is reset and
> > -EINTR is returned, indicating we have to abort initialization. All
> > other errors should be ignored, though, since the controller remains
> > usable.
> 
> So I guess we should just ignore everything but EINTR, e.g.:

Yep, this looks fine. You'll just need to initialize 'int err = 0;' at
the beginning.

 
> diff --git a/drivers/nvme/host/hwmon.c b/drivers/nvme/host/hwmon.c
> index 0a586d7129201..aed245678315f 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;
> +		goto err;
>  
>  	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,22 @@ 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);
> +err:
> +	/*
> +	 * Do not return errors unless we are in a controller reset.
> +	 * The controller works perfectly fine without the hwmon registration.
> +	 */
> +	if (err == -EINTR)
> +		return -EINTR;
> +	return 0;
>  }
>  
>  void nvme_hwmon_exit(struct nvme_ctrl *ctrl)
> -- 
> 2.30.2
> 



More information about the Linux-nvme mailing list