mirror of
git://nv-tegra.nvidia.com/linux-hwpm.git
synced 2025-12-22 09:12:05 +03:00
tegra: hwpm: fix reported coverity violations
- Declare and initialize timeout and mem_bytes_kernel_u32 variables. - alist_map NULL pointer check is done after alist_map structure references. Modify update_allowlist ioctl and release alist_map functions to check alist_map NULL pointer before it's use. - Checking if unsigned _IOC_NR(cmd) is less than zero has no effect. Remove this check. - Correct printf format specifier for mem_bytes_addr. Bug 3461002 Change-Id: I79a97942e667c173d112bcaafb14ddcb8dd7d47f Signed-off-by: Vedashree Vidwans <vvidwans@nvidia.com> Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvidia/+/2765676 Reviewed-by: Vasuki Shankar <vasukis@nvidia.com> Reviewed-by: Seema Khowala <seemaj@nvidia.com> GVS: Gerrit_Virtual_Submit <buildbot_gerritrpt@nvidia.com>
This commit is contained in:
committed by
mobile promotions
parent
d58dbfe5a9
commit
14d527e97a
@@ -22,14 +22,28 @@ int tegra_hwpm_get_allowlist_size(struct tegra_soc_hwpm *hwpm)
|
|||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
hwpm->alist_map->full_alist_size = 0ULL;
|
|
||||||
|
|
||||||
tegra_hwpm_fn(hwpm, " ");
|
tegra_hwpm_fn(hwpm, " ");
|
||||||
|
|
||||||
ret = tegra_hwpm_func_all_ip(hwpm, NULL, TEGRA_HWPM_GET_ALIST_SIZE);
|
if (hwpm->alist_map == NULL) {
|
||||||
if (ret != 0) {
|
/* Allocate tegra_hwpm_allowlist_map */
|
||||||
tegra_hwpm_err(hwpm, "get_alist_size failed");
|
hwpm->alist_map = tegra_hwpm_kzalloc(hwpm,
|
||||||
return ret;
|
sizeof(struct tegra_hwpm_allowlist_map));
|
||||||
|
if (!hwpm->alist_map) {
|
||||||
|
tegra_hwpm_err(NULL,
|
||||||
|
"Couldn't allocate allowlist map structure");
|
||||||
|
return -ENOMEM;
|
||||||
|
}
|
||||||
|
hwpm->alist_map->full_alist_size = 0ULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hwpm->alist_map->full_alist_size == 0) {
|
||||||
|
/* Full alist size is not computed yet */
|
||||||
|
ret = tegra_hwpm_func_all_ip(hwpm, NULL,
|
||||||
|
TEGRA_HWPM_GET_ALIST_SIZE);
|
||||||
|
if (ret != 0) {
|
||||||
|
tegra_hwpm_err(hwpm, "get_alist_size failed");
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ int t234_hwpm_enable_mem_mgmt(struct tegra_soc_hwpm *hwpm)
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
tegra_hwpm_dbg(hwpm, hwpm_verbose,
|
tegra_hwpm_dbg(hwpm, hwpm_verbose,
|
||||||
"MEM_BYTES_ADDR = 0x%x", mem_bytes_addr);
|
"MEM_BYTES_ADDR = 0x%llx", mem_bytes_addr);
|
||||||
|
|
||||||
err = tegra_hwpm_writel(hwpm, pma_perfmux,
|
err = tegra_hwpm_writel(hwpm, pma_perfmux,
|
||||||
pmasys_channel_mem_block_r(0),
|
pmasys_channel_mem_block_r(0),
|
||||||
|
|||||||
@@ -191,14 +191,11 @@ static int tegra_hwpm_query_allowlist_ioctl(struct tegra_soc_hwpm *hwpm,
|
|||||||
|
|
||||||
if (query_allowlist->allowlist == NULL) {
|
if (query_allowlist->allowlist == NULL) {
|
||||||
/* Userspace is querying allowlist size only */
|
/* Userspace is querying allowlist size only */
|
||||||
if (hwpm->alist_map->full_alist_size == 0) {
|
ret = tegra_hwpm_get_allowlist_size(hwpm);
|
||||||
/*Full alist size is not computed yet */
|
if (ret != 0) {
|
||||||
ret = tegra_hwpm_get_allowlist_size(hwpm);
|
tegra_hwpm_err(hwpm,
|
||||||
if (ret != 0) {
|
"failed to get alist_size");
|
||||||
tegra_hwpm_err(hwpm,
|
return ret;
|
||||||
"failed to get alist_size");
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
query_allowlist->allowlist_size =
|
query_allowlist->allowlist_size =
|
||||||
hwpm->alist_map->full_alist_size;
|
hwpm->alist_map->full_alist_size;
|
||||||
@@ -248,12 +245,11 @@ static long tegra_hwpm_ioctl(struct file *file,
|
|||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
struct tegra_soc_hwpm *hwpm = NULL;
|
struct tegra_soc_hwpm *hwpm = NULL;
|
||||||
u8 *buf;
|
u8 *buf = NULL;
|
||||||
|
|
||||||
if ((_IOC_TYPE(cmd) != TEGRA_SOC_HWPM_IOC_MAGIC) ||
|
if ((_IOC_TYPE(cmd) != TEGRA_SOC_HWPM_IOC_MAGIC) ||
|
||||||
(_IOC_NR(cmd) < 0) ||
|
(_IOC_NR(cmd) >= TERGA_SOC_HWPM_NUM_IOCTLS) ||
|
||||||
(_IOC_NR(cmd) >= TERGA_SOC_HWPM_NUM_IOCTLS) ||
|
(_IOC_SIZE(cmd) > TEGRA_SOC_HWPM_MAX_ARG_SIZE)) {
|
||||||
(_IOC_SIZE(cmd) > TEGRA_SOC_HWPM_MAX_ARG_SIZE)) {
|
|
||||||
tegra_hwpm_err(hwpm, "Invalid IOCTL call");
|
tegra_hwpm_err(hwpm, "Invalid IOCTL call");
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|||||||
@@ -265,7 +265,9 @@ int tegra_hwpm_clear_mem_pipeline(struct tegra_soc_hwpm *hwpm)
|
|||||||
u32 *mem_bytes_kernel_u32 =
|
u32 *mem_bytes_kernel_u32 =
|
||||||
(u32 *)(hwpm->mem_mgmt->mem_bytes_kernel);
|
(u32 *)(hwpm->mem_mgmt->mem_bytes_kernel);
|
||||||
u32 sleep_msecs = 100;
|
u32 sleep_msecs = 100;
|
||||||
struct tegra_hwpm_timeout timeout;
|
struct tegra_hwpm_timeout timeout = {0};
|
||||||
|
|
||||||
|
*mem_bytes_kernel_u32 = TEGRA_HWPM_MEM_BYTES_INVALID;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
ret = hwpm->active_chip->stream_mem_bytes(hwpm);
|
ret = hwpm->active_chip->stream_mem_bytes(hwpm);
|
||||||
@@ -372,11 +374,6 @@ int tegra_hwpm_map_update_allowlist(struct tegra_soc_hwpm *hwpm,
|
|||||||
|
|
||||||
tegra_hwpm_fn(hwpm, " ");
|
tegra_hwpm_fn(hwpm, " ");
|
||||||
|
|
||||||
if (hwpm->alist_map->full_alist_size == 0ULL) {
|
|
||||||
tegra_hwpm_err(hwpm, "Invalid allowlist size");
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hwpm->alist_map == NULL) {
|
if (hwpm->alist_map == NULL) {
|
||||||
/* Allocate tegra_hwpm_allowlist_map */
|
/* Allocate tegra_hwpm_allowlist_map */
|
||||||
hwpm->alist_map = tegra_hwpm_kzalloc(hwpm,
|
hwpm->alist_map = tegra_hwpm_kzalloc(hwpm,
|
||||||
@@ -388,6 +385,12 @@ int tegra_hwpm_map_update_allowlist(struct tegra_soc_hwpm *hwpm,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (hwpm->alist_map->full_alist_size == 0ULL) {
|
||||||
|
tegra_hwpm_err(hwpm,
|
||||||
|
"Allowlist size should be computed before");
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
alist_buf_size =
|
alist_buf_size =
|
||||||
tegra_hwpm_safe_mult_u64(hwpm->alist_map->full_alist_size,
|
tegra_hwpm_safe_mult_u64(hwpm->alist_map->full_alist_size,
|
||||||
hwpm->active_chip->get_alist_buf_size(hwpm));
|
hwpm->active_chip->get_alist_buf_size(hwpm));
|
||||||
@@ -448,20 +451,20 @@ void tegra_hwpm_release_alist_map(struct tegra_soc_hwpm *hwpm)
|
|||||||
{
|
{
|
||||||
u64 idx = 0U;
|
u64 idx = 0U;
|
||||||
|
|
||||||
if (hwpm->alist_map->full_alist_map) {
|
|
||||||
vunmap(hwpm->alist_map->full_alist_map);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (idx = 0ULL; idx < hwpm->alist_map->num_pages; idx++) {
|
|
||||||
set_page_dirty(hwpm->alist_map->pages[idx]);
|
|
||||||
put_page(hwpm->alist_map->pages[idx]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hwpm->alist_map->pages) {
|
|
||||||
tegra_hwpm_kfree(hwpm, hwpm->alist_map->pages);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hwpm->alist_map) {
|
if (hwpm->alist_map) {
|
||||||
|
if (hwpm->alist_map->full_alist_map) {
|
||||||
|
vunmap(hwpm->alist_map->full_alist_map);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (idx = 0ULL; idx < hwpm->alist_map->num_pages; idx++) {
|
||||||
|
set_page_dirty(hwpm->alist_map->pages[idx]);
|
||||||
|
put_page(hwpm->alist_map->pages[idx]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hwpm->alist_map->pages) {
|
||||||
|
tegra_hwpm_kfree(hwpm, hwpm->alist_map->pages);
|
||||||
|
}
|
||||||
|
|
||||||
tegra_hwpm_kfree(hwpm, hwpm->alist_map);
|
tegra_hwpm_kfree(hwpm, hwpm->alist_map);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user