Skip to content

Commit

Permalink
xfpga: fix sysfs static code scanner issues (#1124)
Browse files Browse the repository at this point in the history
  • Loading branch information
anandaravuri committed Jan 28, 2019
1 parent 498c19f commit 803b28d
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions libopae/plugins/xfpga/sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,11 +351,13 @@ STATIC int sysfs_region_destroy(sysfs_fpga_region *region)
int sysfs_region_count(void)
{
int res = 0, count = 0;
if (!opae_mutex_lock(res, &_sysfs_region_lock)) {
opae_mutex_lock(res, &_sysfs_region_lock);
if (!res) {
count = _sysfs_region_count;
}

if (opae_mutex_unlock(res, &_sysfs_region_lock)) {
opae_mutex_unlock(res, &_sysfs_region_lock);
if (res) {
count = 0;
}

Expand All @@ -366,7 +368,8 @@ void sysfs_foreach_region(region_cb cb, void *context)
{
uint32_t i = 0;
int res = 0;
if (!opae_mutex_lock(res, &_sysfs_region_lock)) {
opae_mutex_lock(res, &_sysfs_region_lock);
if (!res) {
for ( ; i < _sysfs_region_count; ++i) {
cb(&_regions[i], context);
}
Expand Down Expand Up @@ -453,7 +456,8 @@ int sysfs_initialize(void)
int num = strtoul(dirent->d_name + num_begin, NULL, 10);
// increment our region count after filling out details
// of the discovered region in our _regions array
if (opae_mutex_lock(res, &_sysfs_region_lock)) {
opae_mutex_lock(res, &_sysfs_region_lock);
if (res) {
goto out_free;
}
if (make_region(&_regions[_sysfs_region_count++],
Expand All @@ -463,7 +467,9 @@ int sysfs_initialize(void)
dirent->d_name);
_sysfs_region_count--;
}
if (opae_mutex_unlock(res, &_sysfs_region_lock)) {

opae_mutex_unlock(res, &_sysfs_region_lock);
if (res) {
goto out_free;
}
}
Expand All @@ -484,7 +490,8 @@ int sysfs_finalize(void)
{
uint32_t i = 0;
int res = 0;
if (opae_mutex_lock(res, &_sysfs_region_lock)) {
opae_mutex_lock(res, &_sysfs_region_lock);
if (res) {
FPGA_ERR("Error locking mutex");
return FPGA_EXCEPTION;
}
Expand All @@ -493,7 +500,9 @@ int sysfs_finalize(void)
}
_sysfs_region_count = 0;
_sysfs_format_ptr = NULL;
if (opae_mutex_unlock(res, &_sysfs_region_lock)) {

opae_mutex_unlock(res, &_sysfs_region_lock);
if (res) {
FPGA_ERR("Error unlocking mutex");
return FPGA_EXCEPTION;
}
Expand All @@ -504,13 +513,15 @@ const sysfs_fpga_region *sysfs_get_region(size_t num)
{
const sysfs_fpga_region *ptr = NULL;
int res = 0;
if (!opae_mutex_lock(res, &_sysfs_region_lock)) {
opae_mutex_lock(res, &_sysfs_region_lock);
if (!res) {
if (num >= _sysfs_region_count) {
FPGA_ERR("No such region with index: %d", num);
} else {
ptr = &_regions[num];
}
if (opae_mutex_unlock(res, &_sysfs_region_lock)) {
opae_mutex_unlock(res, &_sysfs_region_lock);
if (res) {
ptr = NULL;
}
}
Expand Down

0 comments on commit 803b28d

Please sign in to comment.