OSDN Git Service

drm/amdgpu: Off by one sanity checks
authorDan Carpenter <dan.carpenter@oracle.com>
Tue, 11 Jul 2017 19:53:29 +0000 (22:53 +0300)
committerAlex Deucher <alexander.deucher@amd.com>
Fri, 14 Jul 2017 15:06:40 +0000 (11:06 -0400)
This is just future proofing code, not something that can be triggered
in real life.  We're testing to make sure we don't shift wrap when we
do "1ull << i" so "i" has to be in the 0-63 range.  If it's 64 then we
have gone too far.

Acked-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c

index 4bb12ee..3fbc7b2 100644 (file)
@@ -4564,7 +4564,7 @@ static int gfx_v8_0_kiq_kcq_enable(struct amdgpu_device *adev)
                /* This situation may be hit in the future if a new HW
                 * generation exposes more than 64 queues. If so, the
                 * definition of queue_mask needs updating */
-               if (WARN_ON(i > (sizeof(queue_mask)*8))) {
+               if (WARN_ON(i >= (sizeof(queue_mask)*8))) {
                        DRM_ERROR("Invalid KCQ enabled: %d\n", i);
                        break;
                }
index 3a0b69b..e63925d 100644 (file)
@@ -2425,7 +2425,7 @@ static int gfx_v9_0_kiq_kcq_enable(struct amdgpu_device *adev)
                /* This situation may be hit in the future if a new HW
                 * generation exposes more than 64 queues. If so, the
                 * definition of queue_mask needs updating */
-               if (WARN_ON(i > (sizeof(queue_mask)*8))) {
+               if (WARN_ON(i >= (sizeof(queue_mask)*8))) {
                        DRM_ERROR("Invalid KCQ enabled: %d\n", i);
                        break;
                }
index 955aa30..0def783 100644 (file)
@@ -671,7 +671,7 @@ static int set_sched_resources(struct device_queue_manager *dqm)
                /* This situation may be hit in the future if a new HW
                 * generation exposes more than 64 queues. If so, the
                 * definition of res.queue_mask needs updating */
-               if (WARN_ON(i > (sizeof(res.queue_mask)*8))) {
+               if (WARN_ON(i >= (sizeof(res.queue_mask)*8))) {
                        pr_err("Invalid queue enabled by amdgpu: %d\n", i);
                        break;
                }