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:
Vedashree Vidwans
2022-08-23 14:27:43 -07:00
committed by mobile promotions
parent d58dbfe5a9
commit 14d527e97a
4 changed files with 51 additions and 38 deletions

View File

@@ -265,7 +265,9 @@ int tegra_hwpm_clear_mem_pipeline(struct tegra_soc_hwpm *hwpm)
u32 *mem_bytes_kernel_u32 =
(u32 *)(hwpm->mem_mgmt->mem_bytes_kernel);
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 {
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, " ");
if (hwpm->alist_map->full_alist_size == 0ULL) {
tegra_hwpm_err(hwpm, "Invalid allowlist size");
return -EINVAL;
}
if (hwpm->alist_map == NULL) {
/* Allocate tegra_hwpm_allowlist_map */
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 =
tegra_hwpm_safe_mult_u64(hwpm->alist_map->full_alist_size,
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;
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->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);
}
}