All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] nvme-hwmon: don't return errors from nvme_hwmon_init
@ 2022-10-18 14:58 Christoph Hellwig
  2022-10-18 15:14 ` Serge Semin
  2022-10-18 15:15 ` Keith Busch
  0 siblings, 2 replies; 13+ messages in thread
From: Christoph Hellwig @ 2022-10-18 14:58 UTC (permalink / raw)
  To: kbusch, sagi, fancer.lancer, linux; +Cc: linux-nvme

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@lst.de>
---

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



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH] nvme-hwmon: don't return errors from nvme_hwmon_init
  2022-10-18 14:58 [PATCH] nvme-hwmon: don't return errors from nvme_hwmon_init Christoph Hellwig
@ 2022-10-18 15:14 ` Serge Semin
  2022-10-18 15:16   ` Christoph Hellwig
  2022-10-18 15:15 ` Keith Busch
  1 sibling, 1 reply; 13+ messages in thread
From: Serge Semin @ 2022-10-18 15:14 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: kbusch, sagi, linux, linux-nvme

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@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@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
> 


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] nvme-hwmon: don't return errors from nvme_hwmon_init
  2022-10-18 14:58 [PATCH] nvme-hwmon: don't return errors from nvme_hwmon_init Christoph Hellwig
  2022-10-18 15:14 ` Serge Semin
@ 2022-10-18 15:15 ` Keith Busch
  2022-10-18 15:23   ` Christoph Hellwig
  1 sibling, 1 reply; 13+ messages in thread
From: Keith Busch @ 2022-10-18 15:15 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: sagi, fancer.lancer, linux, linux-nvme

On Tue, Oct 18, 2022 at 04:58:08PM +0200, Christoph Hellwig wrote:
> @@ -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);

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.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] nvme-hwmon: don't return errors from nvme_hwmon_init
  2022-10-18 15:14 ` Serge Semin
@ 2022-10-18 15:16   ` Christoph Hellwig
  2022-10-18 15:21     ` Serge Semin
  0 siblings, 1 reply; 13+ messages in thread
From: Christoph Hellwig @ 2022-10-18 15:16 UTC (permalink / raw)
  To: Serge Semin; +Cc: Christoph Hellwig, kbusch, sagi, linux, linux-nvme

On Tue, Oct 18, 2022 at 06:14:21PM +0300, Serge Semin wrote:
> 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@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.

I already have a locally rebased version, so don't bother.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] nvme-hwmon: don't return errors from nvme_hwmon_init
  2022-10-18 15:16   ` Christoph Hellwig
@ 2022-10-18 15:21     ` Serge Semin
  2022-10-18 15:23       ` Christoph Hellwig
  0 siblings, 1 reply; 13+ messages in thread
From: Serge Semin @ 2022-10-18 15:21 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: kbusch, sagi, linux, linux-nvme

On Tue, Oct 18, 2022 at 05:16:25PM +0200, Christoph Hellwig wrote:
> On Tue, Oct 18, 2022 at 06:14:21PM +0300, Serge Semin wrote:
> > 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@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.
> 

> I already have a locally rebased version, so don't bother.

Just to clarify. Are you saying that you have already got a patch for
the sed-opal driver which fixes opal_dev.{cmd,resp} buffers being used
for DMA and takes the Jonathan Derrick note into account?
Here is his note:
Link: https://lore.kernel.org/linux-nvme/cce74aec-61b1-d5eb-1b62-746e45ebfe69@linux.dev/

-Sergey


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] nvme-hwmon: don't return errors from nvme_hwmon_init
  2022-10-18 15:15 ` Keith Busch
@ 2022-10-18 15:23   ` Christoph Hellwig
  2022-10-18 15:26     ` Keith Busch
  0 siblings, 1 reply; 13+ messages in thread
From: Christoph Hellwig @ 2022-10-18 15:23 UTC (permalink / raw)
  To: Keith Busch; +Cc: Christoph Hellwig, sagi, fancer.lancer, linux, linux-nvme

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.:


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



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH] nvme-hwmon: don't return errors from nvme_hwmon_init
  2022-10-18 15:21     ` Serge Semin
@ 2022-10-18 15:23       ` Christoph Hellwig
  2022-10-18 15:25         ` Serge Semin
  0 siblings, 1 reply; 13+ messages in thread
From: Christoph Hellwig @ 2022-10-18 15:23 UTC (permalink / raw)
  To: Serge Semin; +Cc: Christoph Hellwig, kbusch, sagi, linux, linux-nvme

On Tue, Oct 18, 2022 at 06:21:48PM +0300, Serge Semin wrote:
> Just to clarify. Are you saying that you have already got a patch for
> the sed-opal driver which fixes opal_dev.{cmd,resp} buffers being used
> for DMA and takes the Jonathan Derrick note into account?

No, just the nvme patch.  For sed-opal please just resend it standalone
to the linux-block list and the maintainers.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] nvme-hwmon: don't return errors from nvme_hwmon_init
  2022-10-18 15:23       ` Christoph Hellwig
@ 2022-10-18 15:25         ` Serge Semin
  0 siblings, 0 replies; 13+ messages in thread
From: Serge Semin @ 2022-10-18 15:25 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: kbusch, sagi, linux, linux-nvme

On Tue, Oct 18, 2022 at 05:23:46PM +0200, Christoph Hellwig wrote:
> On Tue, Oct 18, 2022 at 06:21:48PM +0300, Serge Semin wrote:
> > Just to clarify. Are you saying that you have already got a patch for
> > the sed-opal driver which fixes opal_dev.{cmd,resp} buffers being used
> > for DMA and takes the Jonathan Derrick note into account?
> 

> No, just the nvme patch.  For sed-opal please just resend it standalone
> to the linux-block list and the maintainers.

Ok. Thanks.

-Sergey


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] nvme-hwmon: don't return errors from nvme_hwmon_init
  2022-10-18 15:23   ` Christoph Hellwig
@ 2022-10-18 15:26     ` Keith Busch
  2022-10-18 15:31       ` Christoph Hellwig
  2022-10-18 15:31       ` Serge Semin
  0 siblings, 2 replies; 13+ messages in thread
From: Keith Busch @ 2022-10-18 15:26 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: sagi, fancer.lancer, linux, linux-nvme

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
> 


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] nvme-hwmon: don't return errors from nvme_hwmon_init
  2022-10-18 15:26     ` Keith Busch
@ 2022-10-18 15:31       ` Christoph Hellwig
  2022-10-18 15:31       ` Serge Semin
  1 sibling, 0 replies; 13+ messages in thread
From: Christoph Hellwig @ 2022-10-18 15:31 UTC (permalink / raw)
  To: Keith Busch; +Cc: Christoph Hellwig, sagi, fancer.lancer, linux, linux-nvme

On Tue, Oct 18, 2022 at 09:26:24AM -0600, Keith Busch wrote:
> Yep, this looks fine. You'll just need to initialize 'int err = 0;' at
> the beginning.

Grr, stupid lack of uninitialized variable tracking in gcc..


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] nvme-hwmon: don't return errors from nvme_hwmon_init
  2022-10-18 15:26     ` Keith Busch
  2022-10-18 15:31       ` Christoph Hellwig
@ 2022-10-18 15:31       ` Serge Semin
  2022-10-18 15:38         ` Christoph Hellwig
  1 sibling, 1 reply; 13+ messages in thread
From: Serge Semin @ 2022-10-18 15:31 UTC (permalink / raw)
  To: Keith Busch, Christoph Hellwig; +Cc: sagi, linux, linux-nvme

On Tue, Oct 18, 2022 at 09:26:24AM -0600, Keith Busch wrote:
> 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;

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.

-Sergey

> > +	return 0;
> >  }
> >  
> >  void nvme_hwmon_exit(struct nvme_ctrl *ctrl)
> > -- 
> > 2.30.2
> > 


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] nvme-hwmon: don't return errors from nvme_hwmon_init
  2022-10-18 15:31       ` Serge Semin
@ 2022-10-18 15:38         ` Christoph Hellwig
  2022-10-18 15:44           ` Serge Semin
  0 siblings, 1 reply; 13+ messages in thread
From: Christoph Hellwig @ 2022-10-18 15:38 UTC (permalink / raw)
  To: Serge Semin; +Cc: Keith Busch, Christoph Hellwig, sagi, linux, linux-nvme

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;
 	}
 
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)


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH] nvme-hwmon: don't return errors from nvme_hwmon_init
  2022-10-18 15:38         ` Christoph Hellwig
@ 2022-10-18 15:44           ` Serge Semin
  0 siblings, 0 replies; 13+ messages in thread
From: Serge Semin @ 2022-10-18 15:44 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: Keith Busch, sagi, linux, linux-nvme

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)


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2022-10-18 15:45 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-18 14:58 [PATCH] nvme-hwmon: don't return errors from nvme_hwmon_init Christoph Hellwig
2022-10-18 15:14 ` Serge Semin
2022-10-18 15:16   ` Christoph Hellwig
2022-10-18 15:21     ` Serge Semin
2022-10-18 15:23       ` Christoph Hellwig
2022-10-18 15:25         ` Serge Semin
2022-10-18 15:15 ` Keith Busch
2022-10-18 15:23   ` Christoph Hellwig
2022-10-18 15:26     ` Keith Busch
2022-10-18 15:31       ` Christoph Hellwig
2022-10-18 15:31       ` Serge Semin
2022-10-18 15:38         ` Christoph Hellwig
2022-10-18 15:44           ` Serge Semin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.