drm/msm/dpu: Disallow unallocated resources to be returned
authorMarijn Suijten <marijn.suijten@somainline.org>
Mon, 9 Jan 2023 23:15:55 +0000 (00:15 +0100)
committerDmitry Baryshkov <dmitry.baryshkov@linaro.org>
Wed, 18 Jan 2023 01:30:36 +0000 (03:30 +0200)
In the event that the topology requests resources that have not been
created by the system (because they are typically not represented in
dpu_mdss_cfg ^1), the resource(s) in global_state (in this case DSC
blocks, until their allocation/assignment is being sanity-checked in
"drm/msm/dpu: Reject topologies for which no DSC blocks are available")
remain NULL but will still be returned out of
dpu_rm_get_assigned_resources, where the caller expects to get an array
containing num_blks valid pointers (but instead gets these NULLs).

To prevent this from happening, where null-pointer dereferences
typically result in a hard-to-debug platform lockup, num_blks shouldn't
increase past NULL blocks and will print an error and break instead.
After all, max_blks represents the static size of the maximum number of
blocks whereas the actual amount varies per platform.

^1: which can happen after a git rebase ended up moving additions to
_dpu_cfg to a different struct which has the same patch context.

Fixes: bb00a452d6f7 ("drm/msm/dpu: Refactor resource manager")
Signed-off-by: Marijn Suijten <marijn.suijten@somainline.org>
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Patchwork: https://patchwork.freedesktop.org/patch/517636/
Link: https://lore.kernel.org/r/20230109231556.344977-1-marijn.suijten@somainline.org
Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c

index b6090a837779784ae4c0a0d18303694cd1b06de6..396429e63756b5e82dc42f0e69587a54ea136000 100644 (file)
@@ -665,6 +665,11 @@ int dpu_rm_get_assigned_resources(struct dpu_rm *rm,
                                  blks_size, enc_id);
                        break;
                }
+               if (!hw_blks[i]) {
+                       DPU_ERROR("Allocated resource %d unavailable to assign to enc %d\n",
+                                 type, enc_id);
+                       break;
+               }
                blks[num_blks++] = hw_blks[i];
        }