@@ -1226,6 +1226,7 @@ static ssize_t hns3_dbg_read(struct file *filp, char __user *buffer,
1226
1226
if (ret )
1227
1227
return ret ;
1228
1228
1229
+ mutex_lock (& handle -> dbgfs_lock );
1229
1230
save_buf = & hns3_dbg_cmd [index ].buf ;
1230
1231
1231
1232
if (!test_bit (HNS3_NIC_STATE_INITED , & priv -> state ) ||
@@ -1238,15 +1239,15 @@ static ssize_t hns3_dbg_read(struct file *filp, char __user *buffer,
1238
1239
read_buf = * save_buf ;
1239
1240
} else {
1240
1241
read_buf = kvzalloc (hns3_dbg_cmd [index ].buf_len , GFP_KERNEL );
1241
- if (!read_buf )
1242
- return - ENOMEM ;
1242
+ if (!read_buf ) {
1243
+ ret = - ENOMEM ;
1244
+ goto out ;
1245
+ }
1243
1246
1244
1247
/* save the buffer addr until the last read operation */
1245
1248
* save_buf = read_buf ;
1246
- }
1247
1249
1248
- /* get data ready for the first time to read */
1249
- if (!* ppos ) {
1250
+ /* get data ready for the first time to read */
1250
1251
ret = hns3_dbg_read_cmd (dbg_data , hns3_dbg_cmd [index ].cmd ,
1251
1252
read_buf , hns3_dbg_cmd [index ].buf_len );
1252
1253
if (ret )
@@ -1255,8 +1256,10 @@ static ssize_t hns3_dbg_read(struct file *filp, char __user *buffer,
1255
1256
1256
1257
size = simple_read_from_buffer (buffer , count , ppos , read_buf ,
1257
1258
strlen (read_buf ));
1258
- if (size > 0 )
1259
+ if (size > 0 ) {
1260
+ mutex_unlock (& handle -> dbgfs_lock );
1259
1261
return size ;
1262
+ }
1260
1263
1261
1264
out :
1262
1265
/* free the buffer for the last read operation */
@@ -1265,6 +1268,7 @@ static ssize_t hns3_dbg_read(struct file *filp, char __user *buffer,
1265
1268
* save_buf = NULL ;
1266
1269
}
1267
1270
1271
+ mutex_unlock (& handle -> dbgfs_lock );
1268
1272
return ret ;
1269
1273
}
1270
1274
@@ -1337,6 +1341,8 @@ int hns3_dbg_init(struct hnae3_handle *handle)
1337
1341
debugfs_create_dir (hns3_dbg_dentry [i ].name ,
1338
1342
handle -> hnae3_dbgfs );
1339
1343
1344
+ mutex_init (& handle -> dbgfs_lock );
1345
+
1340
1346
for (i = 0 ; i < ARRAY_SIZE (hns3_dbg_cmd ); i ++ ) {
1341
1347
if ((hns3_dbg_cmd [i ].cmd == HNAE3_DBG_CMD_TM_NODES &&
1342
1348
ae_dev -> dev_version <= HNAE3_DEVICE_VERSION_V2 ) ||
@@ -1363,6 +1369,7 @@ int hns3_dbg_init(struct hnae3_handle *handle)
1363
1369
return 0 ;
1364
1370
1365
1371
out :
1372
+ mutex_destroy (& handle -> dbgfs_lock );
1366
1373
debugfs_remove_recursive (handle -> hnae3_dbgfs );
1367
1374
handle -> hnae3_dbgfs = NULL ;
1368
1375
return ret ;
@@ -1378,6 +1385,7 @@ void hns3_dbg_uninit(struct hnae3_handle *handle)
1378
1385
hns3_dbg_cmd [i ].buf = NULL ;
1379
1386
}
1380
1387
1388
+ mutex_destroy (& handle -> dbgfs_lock );
1381
1389
debugfs_remove_recursive (handle -> hnae3_dbgfs );
1382
1390
handle -> hnae3_dbgfs = NULL ;
1383
1391
}
0 commit comments