gpu: nvgpu: make entries check robust for kernel submit

Check on the number of entries for kernel mode submit needs to be more
robust to avoid overflows. The overflow can make check useless.

Bug 5045127
Bug 5079301

Signed-off-by: Shashank Singh <shashsingh@nvidia.com>
Change-Id: I2247718097bad922ac38dd7574b0fc008b1e02e4
Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/3283910
(cherry picked from commit 6ed9cc57b4ca77424da58c9a90d7a19ed6deb11c)
Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/3295258
GVS: buildbot_gerritrpt <buildbot_gerritrpt@nvidia.com>
Reviewed-by: Bibek Basu <bbasu@nvidia.com>
This commit is contained in:
Shashank Singh
2025-01-15 08:30:52 +00:00
committed by mobile promotions
parent 2eabcdb8a4
commit af45c11d05

View File

@@ -810,7 +810,8 @@ static int nvgpu_submit_channel_gpfifo(struct nvgpu_channel *c,
* So, add extra entries in user request. Also, HW with fifo size N
* can accept only N-1 entries.
*/
if (c->gpfifo.entry_num - 1U < num_entries + EXTRA_GPFIFO_ENTRIES) {
if ((c->gpfifo.entry_num < (EXTRA_GPFIFO_ENTRIES + 1U)) ||
((c->gpfifo.entry_num - EXTRA_GPFIFO_ENTRIES - 1U) < num_entries)) {
nvgpu_err(g, "not enough gpfifo space allocated");
return -ENOMEM;
}