[PATCH] libertas: fix error handling

Marcelo Tosatti marcelo at kvack.org
Wed Mar 7 13:05:19 EST 2007


Holger,

Follows a simple version of the error handling correction patch:

diff --git a/drivers/net/wireless/libertas/if_usb.c b/drivers/net/wireless/libertas/if_usb.c
index 95c7782..88d4f66 100644
--- a/drivers/net/wireless/libertas/if_usb.c
+++ b/drivers/net/wireless/libertas/if_usb.c
@@ -198,10 +198,10 @@ static int if_usb_probe(struct usb_inter
 		goto dealloc;
 	
 	if (wlan_add_mesh(priv))
-		goto dealloc;
+		goto err_add_mesh;
 
 	if (libertas_activate_card(priv))
-		goto dealloc;
+		goto err_activate_card;
 
 	if (libertas_found < MAX_DEVS) {
 		libertas_devs[libertas_found] = priv->wlan_dev.netdev;
@@ -218,6 +218,12 @@ static int if_usb_probe(struct usb_inter
 	 */
 	return 0;
 
+err_activate_card:
+	unregister_netdev(priv->mesh_dev);	
+	free_netdev(priv->mesh_dev);
+err_add_mesh:
+	free_netdev(priv->wlan_dev.netdev);
+	kfree(priv->adapter);
 dealloc:
 	if_usb_free(usb_cardp);
 
diff --git a/drivers/net/wireless/libertas/main.c b/drivers/net/wireless/libertas/main.c
index cf36012..5e74f79 100644
--- a/drivers/net/wireless/libertas/main.c
+++ b/drivers/net/wireless/libertas/main.c
@@ -816,6 +816,7 @@ #define NETIF_F_DYNALLOC 16
 
 err_kzalloc:
 	free_netdev(dev);
+	priv = NULL;
 done:
 	lbs_deb_leave_args(LBS_DEB_NET, "priv %p", priv);
 	return priv;

On Tue, Feb 27, 2007 at 01:23:48PM +0100, Holger Schurig wrote:
> > I understand... But I think its cleaner and less bugprone if
> > we handle errors right at the callers, not later by a common
> > function.
> 
> Hm, either I backout the the split of wlan_add_card() into two 
> functions and do something like outlined in my last mail.
> 
> Or I add a new function, libertas_deactive_card(), which just 
> un-does what libertas_active_card() did. And 
> libertas_remove_card() would undo what libertas_add_card() did. 
> This way, we can code in if_usb.c and if_cs.c:
> 
> if_usb_probe()
> {
>    ...
> 
>    priv = libertas_add_card();
>    if (!priv) {
>       /* add_card() removed it's own mess */
>       goto error;
>    }
> 
>    priv->hw_XXXX = if_usb_XXXX;
>    priv->hw_YYYY = if_usb_YYYY;
> 
>    ret = libertas_activate_card(priv);
>    if (ret) {
>        /* activate_card removed it's own mess */
>        /* but not the mess of add_card */
>        goto error_remove;
>    }
> 
>    ret = libertas_add_mesh(priv);
>    if (ret) {
>        /* add_mesh removed it's own mess */
>        /* but not the mess of activate_card and add_card */
>       error_deactivate;
>    }
> 
>    ...
>    return 0;
>    
> error_deactivate:
>    libertas_deactivate_card(priv);
> error_remove:
>    libertas_remove_card(priv);
> error:
>    return -1;
> }
> 
> _______________________________________________
> libertas-dev mailing list
> libertas-dev at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/libertas-dev



More information about the libertas-dev mailing list