All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] net: cxgb3: add error handling for sysfs_create_group
@ 2018-06-14 13:56 Zhouyang Jia
  2018-06-15  2:00 ` David Miller
  2018-06-15  3:06 ` [PATCH v2] " Zhouyang Jia
  0 siblings, 2 replies; 4+ messages in thread
From: Zhouyang Jia @ 2018-06-14 13:56 UTC (permalink / raw)
  Cc: Zhouyang Jia, Santosh Raspatur, David S. Miller, netdev, linux-kernel

When sysfs_create_group fails, the lack of error-handling code may
cause unexpected results.

This patch adds error-handling code after calling sysfs_create_group.

Signed-off-by: Zhouyang Jia <jiazhouyang09@gmail.com>
---
 drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c b/drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c
index 2edfdbd..73d6aa9 100644
--- a/drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c
+++ b/drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c
@@ -3362,6 +3362,10 @@ static int init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 
 	err = sysfs_create_group(&adapter->port[0]->dev.kobj,
 				 &cxgb3_attr_group);
+	if (err) {
+		dev_err(&pdev->dev, "cannot create sysfs group\n");
+		goto out_free_dev;
+	}
 
 	print_port_info(adapter, ai);
 	return 0;
-- 
2.7.4


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

* Re: [PATCH] net: cxgb3: add error handling for sysfs_create_group
  2018-06-14 13:56 [PATCH] net: cxgb3: add error handling for sysfs_create_group Zhouyang Jia
@ 2018-06-15  2:00 ` David Miller
  2018-06-15  3:06 ` [PATCH v2] " Zhouyang Jia
  1 sibling, 0 replies; 4+ messages in thread
From: David Miller @ 2018-06-15  2:00 UTC (permalink / raw)
  To: jiazhouyang09; +Cc: santosh, netdev, linux-kernel

From: Zhouyang Jia <jiazhouyang09@gmail.com>
Date: Thu, 14 Jun 2018 21:56:11 +0800

> diff --git a/drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c b/drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c
> index 2edfdbd..73d6aa9 100644
> --- a/drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c
> +++ b/drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c
> @@ -3362,6 +3362,10 @@ static int init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
>  
>  	err = sysfs_create_group(&adapter->port[0]->dev.kobj,
>  				 &cxgb3_attr_group);
> +	if (err) {
> +		dev_err(&pdev->dev, "cannot create sysfs group\n");
> +		goto out_free_dev;
> +	}

You have to do more than this to cleanup.  For example, you have to
change the LED state back, as it has just been set to indicate that
the interface is operational.

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

* [PATCH v2] net: cxgb3: add error handling for sysfs_create_group
  2018-06-14 13:56 [PATCH] net: cxgb3: add error handling for sysfs_create_group Zhouyang Jia
  2018-06-15  2:00 ` David Miller
@ 2018-06-15  3:06 ` Zhouyang Jia
  2018-06-15 16:15   ` David Miller
  1 sibling, 1 reply; 4+ messages in thread
From: Zhouyang Jia @ 2018-06-15  3:06 UTC (permalink / raw)
  Cc: Zhouyang Jia, Santosh Raspatur, David S. Miller, netdev, linux-kernel

When sysfs_create_group fails, the lack of error-handling code may
cause unexpected results.

This patch adds error-handling code after calling sysfs_create_group.

Signed-off-by: Zhouyang Jia <jiazhouyang09@gmail.com>
---
v1->v2:
- Turn off led when sysfs_create_group fails
---
 drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c b/drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c
index 2edfdbd..7b795ed 100644
--- a/drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c
+++ b/drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c
@@ -3362,10 +3362,17 @@ static int init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 
 	err = sysfs_create_group(&adapter->port[0]->dev.kobj,
 				 &cxgb3_attr_group);
+	if (err) {
+		dev_err(&pdev->dev, "cannot create sysfs group\n");
+		goto out_close_led;
+	}
 
 	print_port_info(adapter, ai);
 	return 0;
 
+out_close_led:
+	t3_set_reg_field(adapter, A_T3DBG_GPIO_EN, F_GPIO0_OUT_VAL, 0);
+
 out_free_dev:
 	iounmap(adapter->regs);
 	for (i = ai->nports0 + ai->nports1 - 1; i >= 0; --i)
-- 
2.7.4


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

* Re: [PATCH v2] net: cxgb3: add error handling for sysfs_create_group
  2018-06-15  3:06 ` [PATCH v2] " Zhouyang Jia
@ 2018-06-15 16:15   ` David Miller
  0 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2018-06-15 16:15 UTC (permalink / raw)
  To: jiazhouyang09; +Cc: santosh, netdev, linux-kernel

From: Zhouyang Jia <jiazhouyang09@gmail.com>
Date: Fri, 15 Jun 2018 11:06:17 +0800

> When sysfs_create_group fails, the lack of error-handling code may
> cause unexpected results.
> 
> This patch adds error-handling code after calling sysfs_create_group.
> 
> Signed-off-by: Zhouyang Jia <jiazhouyang09@gmail.com>
> ---
> v1->v2:
> - Turn off led when sysfs_create_group fails

Applied, thank you.

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

end of thread, other threads:[~2018-06-15 16:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-14 13:56 [PATCH] net: cxgb3: add error handling for sysfs_create_group Zhouyang Jia
2018-06-15  2:00 ` David Miller
2018-06-15  3:06 ` [PATCH v2] " Zhouyang Jia
2018-06-15 16:15   ` David Miller

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.