* [PATCH] net: cxgb3: add error handling for some functions
@ 2018-06-11 8:42 Zhouyang Jia
2018-06-11 21:23 ` David Miller
0 siblings, 1 reply; 2+ messages in thread
From: Zhouyang Jia @ 2018-06-11 8:42 UTC (permalink / raw)
Cc: Zhouyang Jia, Santosh Raspatur, David S. Miller, netdev,
linux-kernel
When sysfs_create_group or alloc_skb fails, the lack of error-handling
code may cause unexpected results.
This patch adds error-handling code after the functions.
Signed-off-by: Zhouyang Jia <jiazhouyang09@gmail.com>
---
drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c b/drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c
index 2edfdbd..bb51b7e 100644
--- a/drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c
+++ b/drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c
@@ -545,6 +545,8 @@ static int init_tp_parity(struct adapter *adap)
if (skb == adap->nofail_skb) {
i = await_mgmt_replies(adap, cnt, 16 + 2048 + 2048 + 1);
adap->nofail_skb = alloc_skb(sizeof(*greq), GFP_KERNEL);
+ if (!adap->nofail_skb)
+ goto alloc_skb_fail;
}
t3_tp_set_offload_mode(adap, 0);
@@ -3362,6 +3364,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] 2+ messages in thread* Re: [PATCH] net: cxgb3: add error handling for some functions
2018-06-11 8:42 [PATCH] net: cxgb3: add error handling for some functions Zhouyang Jia
@ 2018-06-11 21:23 ` David Miller
0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2018-06-11 21:23 UTC (permalink / raw)
To: jiazhouyang09; +Cc: santosh, netdev, linux-kernel
From: Zhouyang Jia <jiazhouyang09@gmail.com>
Date: Mon, 11 Jun 2018 16:42:26 +0800
> When sysfs_create_group or alloc_skb fails, the lack of error-handling
> code may cause unexpected results.
>
> This patch adds error-handling code after the functions.
>
> Signed-off-by: Zhouyang Jia <jiazhouyang09@gmail.com>
The ->nofail_skb handling is perfectly fine.
It is a backup SKB, meant to handle alloc_skb() failures for the
primary 'skb' allocation the _next_ time this function is called.
Even if the ->nofail_skb allocation fails, the primary operation
done by init_tp_parity() has succeeeded and we should return
success.
All of the code in this function is perfectly prepared to handle
the case where ->nofail_skb is NULL.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-06-11 21:23 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-06-11 8:42 [PATCH] net: cxgb3: add error handling for some functions Zhouyang Jia
2018-06-11 21:23 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).