@@ -1146,25 +1146,6 @@ static int agilent_82357a_setup_urbs(gpib_board_t *board)
1146
1146
return retval ;
1147
1147
}
1148
1148
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
-
1168
1149
static void agilent_82357a_cleanup_urbs (struct agilent_82357a_priv * a_priv )
1169
1150
{
1170
1151
if (a_priv && a_priv -> bus_interface ) {
@@ -1175,27 +1156,35 @@ static void agilent_82357a_cleanup_urbs(struct agilent_82357a_priv *a_priv)
1175
1156
}
1176
1157
};
1177
1158
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
+
1178
1168
static int agilent_82357a_allocate_private (gpib_board_t * board )
1179
1169
{
1180
1170
struct agilent_82357a_priv * a_priv ;
1181
1171
1182
- board -> private_data = kmalloc (sizeof (struct agilent_82357a_priv ), GFP_KERNEL );
1172
+ board -> private_data = kzalloc (sizeof (struct agilent_82357a_priv ), GFP_KERNEL );
1183
1173
if (!board -> private_data )
1184
1174
return - ENOMEM ;
1185
1175
a_priv = board -> private_data ;
1186
- memset (a_priv , 0 , sizeof (struct agilent_82357a_priv ));
1187
1176
mutex_init (& a_priv -> bulk_transfer_lock );
1188
1177
mutex_init (& a_priv -> bulk_alloc_lock );
1189
1178
mutex_init (& a_priv -> control_alloc_lock );
1190
1179
mutex_init (& a_priv -> interrupt_alloc_lock );
1191
1180
return 0 ;
1192
1181
}
1193
1182
1194
- static void agilent_82357a_free_private (struct agilent_82357a_priv * a_priv )
1183
+ static void agilent_82357a_free_private (gpib_board_t * board )
1195
1184
{
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
+
1199
1188
}
1200
1189
1201
1190
static 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
1342
1331
a_priv -> bus_interface = agilent_82357a_driver_interfaces [i ];
1343
1332
usb_set_intfdata (agilent_82357a_driver_interfaces [i ], board );
1344
1333
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 );
1348
1334
break ;
1349
1335
}
1350
1336
}
1351
1337
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 ;
1355
1342
}
1356
1343
product_id = le16_to_cpu (interface_to_usbdev (a_priv -> bus_interface )-> descriptor .idProduct );
1357
1344
switch (product_id ) {
@@ -1365,21 +1352,13 @@ static int agilent_82357a_attach(gpib_board_t *board, const gpib_board_config_t
1365
1352
break ;
1366
1353
default :
1367
1354
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 ;
1376
1357
}
1377
- #endif
1358
+
1378
1359
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 ;
1383
1362
1384
1363
timer_setup (& a_priv -> bulk_timer , agilent_82357a_timeout_handler , 0 );
1385
1364
@@ -1388,11 +1367,19 @@ static int agilent_82357a_attach(gpib_board_t *board, const gpib_board_config_t
1388
1367
retval = agilent_82357a_init (board );
1389
1368
1390
1369
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 ;
1393
1373
}
1394
1374
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 );
1396
1383
mutex_unlock (& agilent_82357a_hotplug_lock );
1397
1384
return retval ;
1398
1385
}
@@ -1455,7 +1442,8 @@ static void agilent_82357a_detach(gpib_board_t *board)
1455
1442
mutex_lock (& a_priv -> bulk_alloc_lock );
1456
1443
mutex_lock (& a_priv -> interrupt_alloc_lock );
1457
1444
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 );
1459
1447
}
1460
1448
dev_info (board -> gpib_dev , "%s: detached\n" , __func__ );
1461
1449
mutex_unlock (& agilent_82357a_hotplug_lock );
0 commit comments