lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <Pine.LNX.4.64.0810221103550.13366@melkki.cs.Helsinki.FI>
Date:	Wed, 22 Oct 2008 11:04:23 +0300 (EEST)
From:	Pekka J Enberg <penberg@...helsinki.fi>
To:	Greg Kroah-Hartman <greg@...ah.com>
cc:	Pavel Machek <pavel@...e.cz>, linux-kernel@...r.kernel.org
Subject: [PATCH 6/6] w35und: wb35_probe() cleanup

From: Pekka Enberg <penberg@...helsinki.fi>

Fix error handling in wb35_probe() function and clean it up a bit.

Cc: Pavel Machek <pavel@...e.cz>
Signed-off-by: Pekka Enberg <penberg@...helsinki.fi>
---
 drivers/staging/winbond/linux/wbusb.c |  101 +++++++++++++++------------------
 1 files changed, 45 insertions(+), 56 deletions(-)

diff --git a/drivers/staging/winbond/linux/wbusb.c b/drivers/staging/winbond/linux/wbusb.c
index 9f1064d..b4be0d8 100644
--- a/drivers/staging/winbond/linux/wbusb.c
+++ b/drivers/staging/winbond/linux/wbusb.c
@@ -181,26 +181,32 @@ int wb35_probe(struct usb_interface *intf, const struct usb_device_id *id_table)
 	PWBUSB		pWbUsb;
         struct usb_host_interface *interface;
 	struct usb_endpoint_descriptor *endpoint;
-	int	ret = -1;
 	u32	ltmp;
 	struct usb_device *udev = interface_to_usbdev(intf);
+	struct wbsoft_priv *priv;
+	struct ieee80211_hw *dev;
+	int err;
 
 	usb_get_dev(udev);
 
-	printk("[w35und]wb35_probe ->\n");
-
 	// 20060630.2 Check the device if it already be opened
-	ret = usb_control_msg(udev, usb_rcvctrlpipe( udev, 0 ),
+	err = usb_control_msg(udev, usb_rcvctrlpipe( udev, 0 ),
 			      0x01, USB_TYPE_VENDOR|USB_RECIP_DEVICE|USB_DIR_IN,
 			      0x0, 0x400, &ltmp, 4, HZ*100 );
-	if (ret < 0)
+	if (err)
 		goto error;
 
 	ltmp = cpu_to_le32(ltmp);
-	if (ltmp)  // Is already initialized?
+	if (ltmp) {  // Is already initialized?
+		err = -EBUSY;
 		goto error;
+	}
 
 	adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
+	if (!adapter) {
+		err = -ENOMEM;
+		goto error;
+	}
 
 	my_adapter = adapter;
 	pWbUsb = &adapter->sHwData.WbUsb;
@@ -215,70 +221,53 @@ int wb35_probe(struct usb_interface *intf, const struct usb_device_id *id_table)
 	}
 
 	if (!WbWLanInitialize(adapter)) {
-		printk("[w35und]WbWLanInitialize fail\n");
-		goto error;
+		err = -EINVAL;
+		goto error_free_adapter;
 	}
 
-	{
-		struct wbsoft_priv *priv;
-		struct ieee80211_hw *dev;
-		int res;
-
-		dev = ieee80211_alloc_hw(sizeof(*priv), &wbsoft_ops);
-
-		if (!dev) {
-			printk("w35und: ieee80211 alloc failed\n" );
-			BUG();
-		}
+	dev = ieee80211_alloc_hw(sizeof(*priv), &wbsoft_ops);
+	if (!dev)
+		goto error_free_adapter;
 
-		my_dev = dev;
+	my_dev = dev;
 
-		SET_IEEE80211_DEV(dev, &udev->dev);
-		{
-			phw_data_t pHwData = &adapter->sHwData;
-			unsigned char		dev_addr[MAX_ADDR_LEN];
-			hal_get_permanent_address(pHwData, dev_addr);
-			SET_IEEE80211_PERM_ADDR(dev, dev_addr);
-		}
-
-
-		dev->extra_tx_headroom = 12;	/* FIXME */
-		dev->flags = 0;
-
-		dev->channel_change_time = 1000;
-//		dev->max_rssi = 100;
+	SET_IEEE80211_DEV(dev, &udev->dev);
+	{
+		phw_data_t pHwData = &adapter->sHwData;
+		unsigned char		dev_addr[MAX_ADDR_LEN];
+		hal_get_permanent_address(pHwData, dev_addr);
+		SET_IEEE80211_PERM_ADDR(dev, dev_addr);
+	}
 
-		dev->queues = 1;
+	dev->extra_tx_headroom = 12;	/* FIXME */
+	dev->flags = 0;
 
-		static struct ieee80211_supported_band band;
+	dev->channel_change_time = 1000;
+	dev->queues = 1;
 
-		band.channels = wbsoft_channels;
-		band.n_channels = ARRAY_SIZE(wbsoft_channels);
-		band.bitrates = wbsoft_rates;
-		band.n_bitrates = ARRAY_SIZE(wbsoft_rates);
+	static struct ieee80211_supported_band band;
 
-		dev->wiphy->bands[IEEE80211_BAND_2GHZ] = &band;
-#if 0
-		wbsoft_modes[0].num_channels = 1;
-		wbsoft_modes[0].channels = wbsoft_channels;
-		wbsoft_modes[0].mode = MODE_IEEE80211B;
-		wbsoft_modes[0].num_rates = ARRAY_SIZE(wbsoft_rates);
-		wbsoft_modes[0].rates = wbsoft_rates;
+	band.channels = wbsoft_channels;
+	band.n_channels = ARRAY_SIZE(wbsoft_channels);
+	band.bitrates = wbsoft_rates;
+	band.n_bitrates = ARRAY_SIZE(wbsoft_rates);
 
-		res = ieee80211_register_hwmode(dev, &wbsoft_modes[0]);
-		BUG_ON(res);
-#endif
+	dev->wiphy->bands[IEEE80211_BAND_2GHZ] = &band;
 
-		res = ieee80211_register_hw(dev);
-		BUG_ON(res);
-	}
+	err = ieee80211_register_hw(dev);
+	if (err)
+		goto error_free_hw;
 
-	usb_set_intfdata( intf, adapter );
+	usb_set_intfdata(intf, adapter);
 
-	printk("[w35und] _probe OK\n");
 	return 0;
+
+error_free_hw:
+	ieee80211_free_hw(dev);
+error_free_adapter:
+	kfree(adapter);
 error:
-	return -ENOMEM;
+	return err;
 }
 
 void packet_came(char *pRxBufferAddress, int PacketSize)
-- 
1.5.3.7

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ