Skip to content

Commit

Permalink
bus/cdx: fix resources leak in scan
Browse files Browse the repository at this point in the history
Free the allocated device memory and interrupt handler
on error scenarios.

Coverity issue: 385377
Fixes: f29fb5c ("bus/cdx: support MSI")

Signed-off-by: Abhijit Gangurde <abhijit.gangurde@amd.com>
Acked-by: Nipun Gupta <nipun.gupta@amd.com>
  • Loading branch information
abhijitG-xlnx authored and tmonjalo committed Jun 27, 2023
1 parent a1c0d5d commit 87337f1
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions drivers/bus/cdx/cdx.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ cdx_scan_one(const char *dirname, const char *dev_name)
ret = cdx_get_kernel_driver_by_path(filename, driver, sizeof(driver));
if (ret < 0) {
CDX_BUS_ERR("Fail to get kernel driver");
ret = -1;
goto err;
free(dev);
return -1;
}

/* Allocate interrupt instance for cdx device */
Expand All @@ -218,6 +218,7 @@ cdx_scan_one(const char *dirname, const char *dev_name)
if (dev->intr_handle == NULL) {
CDX_BUS_ERR("Failed to create interrupt instance for %s",
dev->device.name);
free(dev);
return -ENOMEM;
}

Expand All @@ -241,8 +242,8 @@ cdx_scan_one(const char *dirname, const char *dev_name)
/* get device id */
snprintf(filename, sizeof(filename), "%s/device", dirname);
if (eal_parse_sysfs_value(filename, &tmp) < 0) {
free(dev);
return -1;
ret = -1;
goto err;
}
dev->id.device_id = (uint16_t)tmp;

Expand All @@ -251,6 +252,7 @@ cdx_scan_one(const char *dirname, const char *dev_name)
return 0;

err:
rte_intr_instance_free(dev->intr_handle);
free(dev);
return ret;
}
Expand Down

0 comments on commit 87337f1

Please sign in to comment.