@@ -1146,25 +1146,6 @@ static int agilent_82357a_setup_urbs(gpib_board_t *board)
11461146 return retval ;
11471147}
11481148
1149- #ifdef RESET_USB_CONFIG
1150- static int agilent_82357a_reset_usb_configuration (gpib_board_t * board )
1151- {
1152- struct agilent_82357a_priv * a_priv = board -> private_data ;
1153- struct usb_device * usb_dev = interface_to_usbdev (a_priv -> bus_interface );
1154- struct usb_device * usb_dev ;
1155- int retval ;
1156-
1157- if (!a_priv -> bus_interface )
1158- return - ENODEV ;
1159- usb_dev = interface_to_usbdev (a_priv -> bus_interface );
1160- retval = usb_reset_configuration (usb_dev );
1161- if (retval )
1162- dev_err (& usb_dev -> dev , "%s: usb_reset_configuration() returned %i\n" ,
1163- __func__ , retval );
1164- return retval ;
1165- }
1166- #endif
1167-
11681149static void agilent_82357a_cleanup_urbs (struct agilent_82357a_priv * a_priv )
11691150{
11701151 if (a_priv && a_priv -> bus_interface ) {
@@ -1175,27 +1156,35 @@ static void agilent_82357a_cleanup_urbs(struct agilent_82357a_priv *a_priv)
11751156 }
11761157};
11771158
1159+ static void agilent_82357a_release_urbs (struct agilent_82357a_priv * a_priv )
1160+ {
1161+ if (a_priv ) {
1162+ usb_free_urb (a_priv -> interrupt_urb );
1163+ a_priv -> interrupt_urb = NULL ;
1164+ kfree (a_priv -> interrupt_buffer );
1165+ }
1166+ }
1167+
11781168static int agilent_82357a_allocate_private (gpib_board_t * board )
11791169{
11801170 struct agilent_82357a_priv * a_priv ;
11811171
1182- board -> private_data = kmalloc (sizeof (struct agilent_82357a_priv ), GFP_KERNEL );
1172+ board -> private_data = kzalloc (sizeof (struct agilent_82357a_priv ), GFP_KERNEL );
11831173 if (!board -> private_data )
11841174 return - ENOMEM ;
11851175 a_priv = board -> private_data ;
1186- memset (a_priv , 0 , sizeof (struct agilent_82357a_priv ));
11871176 mutex_init (& a_priv -> bulk_transfer_lock );
11881177 mutex_init (& a_priv -> bulk_alloc_lock );
11891178 mutex_init (& a_priv -> control_alloc_lock );
11901179 mutex_init (& a_priv -> interrupt_alloc_lock );
11911180 return 0 ;
11921181}
11931182
1194- static void agilent_82357a_free_private (struct agilent_82357a_priv * a_priv )
1183+ static void agilent_82357a_free_private (gpib_board_t * board )
11951184{
1196- usb_free_urb ( a_priv -> interrupt_urb );
1197- kfree ( a_priv -> interrupt_buffer ) ;
1198- kfree ( a_priv );
1185+ kfree ( board -> private_data );
1186+ board -> private_data = NULL ;
1187+
11991188}
12001189
12011190static int agilent_82357a_init (gpib_board_t * board )
@@ -1342,16 +1331,14 @@ static int agilent_82357a_attach(gpib_board_t *board, const gpib_board_config_t
13421331 a_priv -> bus_interface = agilent_82357a_driver_interfaces [i ];
13431332 usb_set_intfdata (agilent_82357a_driver_interfaces [i ], board );
13441333 usb_dev = interface_to_usbdev (a_priv -> bus_interface );
1345- dev_info (& usb_dev -> dev ,
1346- "bus %d dev num %d attached to gpib minor %d, agilent usb interface %i\n" ,
1347- usb_dev -> bus -> busnum , usb_dev -> devnum , board -> minor , i );
13481334 break ;
13491335 }
13501336 }
13511337 if (i == MAX_NUM_82357A_INTERFACES ) {
1352- mutex_unlock (& agilent_82357a_hotplug_lock );
1353- pr_err ("No Agilent 82357 gpib adapters found, have you loaded its firmware?\n" );
1354- return - ENODEV ;
1338+ dev_err (board -> gpib_dev ,
1339+ "No Agilent 82357 gpib adapters found, have you loaded its firmware?\n" );
1340+ retval = - ENODEV ;
1341+ goto attach_fail ;
13551342 }
13561343 product_id = le16_to_cpu (interface_to_usbdev (a_priv -> bus_interface )-> descriptor .idProduct );
13571344 switch (product_id ) {
@@ -1365,21 +1352,13 @@ static int agilent_82357a_attach(gpib_board_t *board, const gpib_board_config_t
13651352 break ;
13661353 default :
13671354 dev_err (& usb_dev -> dev , "bug, unhandled product_id in switch?\n" );
1368- mutex_unlock (& agilent_82357a_hotplug_lock );
1369- return - EIO ;
1370- }
1371- #ifdef RESET_USB_CONFIG
1372- retval = agilent_82357a_reset_usb_configuration (board );
1373- if (retval < 0 ) {
1374- mutex_unlock (& agilent_82357a_hotplug_lock );
1375- return retval ;
1355+ retval = - EIO ;
1356+ goto attach_fail ;
13761357 }
1377- #endif
1358+
13781359 retval = agilent_82357a_setup_urbs (board );
1379- if (retval < 0 ) {
1380- mutex_unlock (& agilent_82357a_hotplug_lock );
1381- return retval ;
1382- }
1360+ if (retval < 0 )
1361+ goto attach_fail ;
13831362
13841363 timer_setup (& a_priv -> bulk_timer , agilent_82357a_timeout_handler , 0 );
13851364
@@ -1388,11 +1367,19 @@ static int agilent_82357a_attach(gpib_board_t *board, const gpib_board_config_t
13881367 retval = agilent_82357a_init (board );
13891368
13901369 if (retval < 0 ) {
1391- mutex_unlock (& agilent_82357a_hotplug_lock );
1392- return retval ;
1370+ agilent_82357a_cleanup_urbs (a_priv );
1371+ agilent_82357a_release_urbs (a_priv );
1372+ goto attach_fail ;
13931373 }
13941374
1395- dev_info (& usb_dev -> dev , "%s: attached\n" , __func__ );
1375+ dev_info (& usb_dev -> dev ,
1376+ "bus %d dev num %d attached to gpib minor %d, agilent usb interface %i\n" ,
1377+ usb_dev -> bus -> busnum , usb_dev -> devnum , board -> minor , i );
1378+ mutex_unlock (& agilent_82357a_hotplug_lock );
1379+ return retval ;
1380+
1381+ attach_fail :
1382+ agilent_82357a_free_private (board );
13961383 mutex_unlock (& agilent_82357a_hotplug_lock );
13971384 return retval ;
13981385}
@@ -1455,7 +1442,8 @@ static void agilent_82357a_detach(gpib_board_t *board)
14551442 mutex_lock (& a_priv -> bulk_alloc_lock );
14561443 mutex_lock (& a_priv -> interrupt_alloc_lock );
14571444 agilent_82357a_cleanup_urbs (a_priv );
1458- agilent_82357a_free_private (a_priv );
1445+ agilent_82357a_release_urbs (a_priv );
1446+ agilent_82357a_free_private (board );
14591447 }
14601448 dev_info (board -> gpib_dev , "%s: detached\n" , __func__ );
14611449 mutex_unlock (& agilent_82357a_hotplug_lock );
0 commit comments