mirror of
git://nv-tegra.nvidia.com/linux-hwpm.git
synced 2025-12-24 10:13:00 +03:00
tegra: hwpm: fix cert-c errors
Fix coding standard cert-c violations because of unsafe calculations. Introduce safe subtract, add, multiply and cast APIs and use throughout the hwpm driver. Bug 3512545 Change-Id: If374629ac75b48a8bc08b1b7a9a41ea5ef0526b1 Signed-off-by: Vedashree Vidwans <vvidwans@nvidia.com> Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvidia/+/2677160 Reviewed-by: svc_kernel_abi <svc_kernel_abi@nvidia.com> Reviewed-by: Vasuki Shankar <vasukis@nvidia.com> Reviewed-by: Seema Khowala <seemaj@nvidia.com> Reviewed-by: Prateek Patel <prpatel@nvidia.com> GVS: Gerrit_Virtual_Submit
This commit is contained in:
committed by
mobile promotions
parent
aaf8e7f5e1
commit
edb9e2c245
@@ -26,6 +26,7 @@
|
||||
#include <tegra_hwpm_log.h>
|
||||
#include <tegra_hwpm.h>
|
||||
#include <tegra_hwpm_common.h>
|
||||
#include <tegra_hwpm_static_analysis.h>
|
||||
|
||||
int tegra_soc_hwpm_get_allowlist_size(struct tegra_soc_hwpm *hwpm)
|
||||
{
|
||||
@@ -52,8 +53,8 @@ int tegra_soc_hwpm_update_allowlist(struct tegra_soc_hwpm *hwpm,
|
||||
void *ioctl_struct)
|
||||
{
|
||||
int err = 0;
|
||||
long pinned_pages = 0;
|
||||
long page_idx = 0;
|
||||
u64 pinned_pages = 0;
|
||||
u64 page_idx = 0;
|
||||
u64 alist_buf_size = 0;
|
||||
u64 num_pages = 0;
|
||||
u64 *full_alist_u64 = NULL;
|
||||
@@ -74,11 +75,17 @@ int tegra_soc_hwpm_update_allowlist(struct tegra_soc_hwpm *hwpm,
|
||||
tegra_hwpm_err(hwpm, "alist_buf_size uninitialized");
|
||||
return -ENODEV;
|
||||
}
|
||||
alist_buf_size = hwpm->full_alist_size *
|
||||
hwpm->active_chip->get_alist_buf_size(hwpm);
|
||||
alist_buf_size = tegra_hwpm_safe_mult_u64(hwpm->full_alist_size,
|
||||
hwpm->active_chip->get_alist_buf_size(hwpm));
|
||||
|
||||
/* Memory map user buffer into kernel address space */
|
||||
num_pages = DIV_ROUND_UP(offset + alist_buf_size, PAGE_SIZE);
|
||||
alist_buf_size = tegra_hwpm_safe_add_u64(offset, alist_buf_size);
|
||||
|
||||
/* Round-up and Divide */
|
||||
alist_buf_size = tegra_hwpm_safe_sub_u64(
|
||||
tegra_hwpm_safe_add_u64(alist_buf_size, PAGE_SIZE), 1ULL);
|
||||
num_pages = alist_buf_size / PAGE_SIZE;
|
||||
|
||||
pages = (struct page **)kzalloc(sizeof(*pages) * num_pages, GFP_KERNEL);
|
||||
if (!pages) {
|
||||
tegra_hwpm_err(hwpm,
|
||||
@@ -121,7 +128,7 @@ alist_unmap:
|
||||
if (full_alist)
|
||||
vunmap(full_alist);
|
||||
if (pinned_pages > 0) {
|
||||
for (page_idx = 0; page_idx < pinned_pages; page_idx++) {
|
||||
for (page_idx = 0ULL; page_idx < pinned_pages; page_idx++) {
|
||||
set_page_dirty(pages[page_idx]);
|
||||
put_page(pages[page_idx]);
|
||||
}
|
||||
|
||||
@@ -25,13 +25,15 @@
|
||||
#include <tegra_hwpm_log.h>
|
||||
#include <tegra_hwpm.h>
|
||||
#include <tegra_hwpm_common.h>
|
||||
#include <tegra_hwpm_static_analysis.h>
|
||||
|
||||
static int tegra_hwpm_dma_map_stream_buffer(struct tegra_soc_hwpm *hwpm,
|
||||
struct tegra_soc_hwpm_alloc_pma_stream *alloc_pma_stream)
|
||||
{
|
||||
tegra_hwpm_fn(hwpm, " ");
|
||||
|
||||
hwpm->stream_dma_buf = dma_buf_get(alloc_pma_stream->stream_buf_fd);
|
||||
hwpm->stream_dma_buf = dma_buf_get(tegra_hwpm_safe_cast_u64_to_s32(
|
||||
alloc_pma_stream->stream_buf_fd));
|
||||
if (IS_ERR(hwpm->stream_dma_buf)) {
|
||||
tegra_hwpm_err(hwpm, "Unable to get stream dma_buf");
|
||||
return PTR_ERR(hwpm->stream_dma_buf);
|
||||
@@ -56,8 +58,8 @@ static int tegra_hwpm_dma_map_mem_bytes_buffer(struct tegra_soc_hwpm *hwpm,
|
||||
{
|
||||
tegra_hwpm_fn(hwpm, " ");
|
||||
|
||||
hwpm->mem_bytes_dma_buf =
|
||||
dma_buf_get(alloc_pma_stream->mem_bytes_buf_fd);
|
||||
hwpm->mem_bytes_dma_buf = dma_buf_get(tegra_hwpm_safe_cast_u64_to_s32(
|
||||
alloc_pma_stream->mem_bytes_buf_fd));
|
||||
if (IS_ERR(hwpm->mem_bytes_dma_buf)) {
|
||||
tegra_hwpm_err(hwpm, "Unable to get mem bytes dma_buf");
|
||||
return PTR_ERR(hwpm->mem_bytes_dma_buf);
|
||||
@@ -325,7 +327,7 @@ int tegra_hwpm_update_mem_bytes(struct tegra_soc_hwpm *hwpm,
|
||||
return -ENODEV;
|
||||
}
|
||||
update_get_put->b_overflowed =
|
||||
hwpm->active_chip->membuf_overflow_status(hwpm);
|
||||
(u8) hwpm->active_chip->membuf_overflow_status(hwpm);
|
||||
tegra_hwpm_dbg(hwpm, hwpm_verbose, "OVERFLOWED = %u",
|
||||
update_get_put->b_overflowed);
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include <tegra_hwpm_log.h>
|
||||
#include <tegra_hwpm.h>
|
||||
#include <tegra_hwpm_common.h>
|
||||
#include <tegra_hwpm_static_analysis.h>
|
||||
|
||||
int tegra_soc_hwpm_reserve_resource(struct tegra_soc_hwpm *hwpm, u32 resource)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user