diff --git a/drivers/gpu/nvgpu/common/utils/enabled.c b/drivers/gpu/nvgpu/common/utils/enabled.c index eb31f4819..aa3f2d22b 100644 --- a/drivers/gpu/nvgpu/common/utils/enabled.c +++ b/drivers/gpu/nvgpu/common/utils/enabled.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2020, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2017-2021, NVIDIA CORPORATION. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -89,11 +89,19 @@ void nvgpu_free_enabled_flags(struct gk20a *g) bool nvgpu_is_enabled(struct gk20a *g, u32 flag) { - return nvgpu_test_bit(flag, g->enabled_flags); + if (flag < NVGPU_MAX_ENABLED_BITS) { + return nvgpu_test_bit(flag, g->enabled_flags); + } else { + return 0; + } } void nvgpu_set_enabled(struct gk20a *g, u32 flag, bool state) { + if (flag >= NVGPU_MAX_ENABLED_BITS) { + return; + } + if (state) { nvgpu_set_bit(flag, g->enabled_flags); } else { diff --git a/drivers/gpu/nvgpu/common/utils/string.c b/drivers/gpu/nvgpu/common/utils/string.c index a0687e097..2cb50c691 100644 --- a/drivers/gpu/nvgpu/common/utils/string.c +++ b/drivers/gpu/nvgpu/common/utils/string.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2020, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2018-2021, NVIDIA CORPORATION. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -47,6 +47,10 @@ int nvgpu_strnadd_u32(char *dst, const u32 value, size_t size, u32 radix) return 0; } + if (size > ((u64)(INT_MAX))) { + return 0; + } + /* how many digits do we need ? */ n = 0; v = value; @@ -56,7 +60,7 @@ int nvgpu_strnadd_u32(char *dst, const u32 value, size_t size, u32 radix) } while (v > 0U); /* bail out if there is not room for '\0' */ - if (n >= nvgpu_safe_cast_u64_to_s32(size)) { + if (n >= (s32)size) { return 0; }