scsi: fcoe: add missed kfree() in an error path
Subsystems (2)
PATCH v2 1/1 scsi: fcoe: add missed kfree() in an error path
fcoe_fdmi_info() misses to call kfree() in an error path. Add a label 'free_fdmi' and jump to it.
--- drivers/scsi/fcoe/fcoe.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/scsi/fcoe/fcoe.c +2 -1
@@ -830,7 +830,7 @@ static void fcoe_fdmi_info(struct fc_lport *lport, struct net_device *netdev)if (rc) {printk (KERN_INFO "fcoe: Failed to retrieve FDMI " "information from netdev.\n" ); -return ; + goto free_fdmi; } snprintf(fc_host_serial_number(lport->host),
@@ -868,6 +868,7 @@ static void fcoe_fdmi_info(struct fc_lport *lport, struct net_device *netdev)/* Enable FDMI lport states */ lport->fdmi_enabled =1 ; +free_fdmi:kfree (fdmi); }else { lport->fdmi_enabled =0 ;
Signature · 1 line
2.17.1
See below.
Quoted 33 lines · Jing Xiangfeng
fcoe_fdmi_info()misses to callkfree()in an error path. Add a label 'free_fdmi' and jump to it.Fixes f07d46bbc9ba ("fcoe: Fix smatch warning in fcoe_fdmi_infofunction")
Signed-off-by Jing Xiangfeng <[email protected]>--- drivers/scsi/fcoe/fcoe.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/scsi/fcoe/fcoe.c +0
-0@@ -830,7 +830,7 @@ static void fcoe_fdmi_info(struct fc_lport *lport, struct net_device *netdev) if (rc) { printk(KERN_INFO "fcoe: Failed to retrieve FDMI"
drivers/scsi/fcoe/fcoe.c +2
-1"information from netdev.\n"); -return ; + goto free_fdmi; } snprintf(fc_host_serial_number(lport->host),@@ -868,6 +868,7 @@ static void fcoe_fdmi_info(struct fc_lport *lport, struct net_device *netdev)/* Enable FDMI lport states */ lport->fdmi_enabled =1 ; +free_fdmi:kfree (fdmi); }else {
Quoted 1 line
lport->fdmi_enabled= 0;
Normally I would like to see goto labels for error paths outside conditionals and at the end of the function. In this case it would seem to be cleaner to put an else { } clause in the if (rc) above around the snprintf() calls.
-Ewan
Quoted 31 lines · Ewan D. Milne
See below.
Quoted 28 lines · Jing Xiangfeng
fcoe_fdmi_info()misses to callkfree()in an error path. Add a label 'free_fdmi' and jump to it.Fixes f07d46bbc9ba ("fcoe: Fix smatch warning in fcoe_fdmi_infofunction")
Signed-off-by Jing Xiangfeng <[email protected]>--- drivers/scsi/fcoe/fcoe.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/scsi/fcoe/fcoe.c +0
-0@@ -830,7 +830,7 @@ static void fcoe_fdmi_info(struct fc_lport *lport, struct net_device *netdev) if (rc) { printk(KERN_INFO "fcoe: Failed to retrieve FDMI"
"information from netdev.\n");drivers/scsi/fcoe/fcoe.c +1
-1-return ; + goto free_fdmi; } snprintf(fc_host_serial_number(lport->host),@@ -868,6 +868,7 @@ static void fcoe_fdmi_info(struct fc_lport *lport, struct net_device *netdev)
Quoted 9 lines
Quoted 6 lines
drivers/scsi/fcoe/fcoe.c +1
-0/* Enable FDMI lport states */ lport->fdmi_enabled =1 ; +free_fdmi:kfree (fdmi); }else {lport->fdmi_enabled = 0;Normally I would like to see goto labels for error paths outside conditionals and at the end of the function.
I agree.
In this case it would
Quoted 2 lines
seem to be cleaner to put an else { } clause in the if (rc) above around the
snprintf()calls.
It is ok with me. v1 is also a simpler way.
+Hannes, Which is preferable?
Thanks
Quoted 5 lines
-Ewan
.