]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
drm/vmwgfx: Fix some static checker warnings
authorZack Rusin <zackr@vmware.com>
Wed, 9 Jun 2021 17:23:02 +0000 (13:23 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 13 Apr 2024 10:58:02 +0000 (12:58 +0200)
[ Upstream commit 74231041d14030f1ae6582b9233bfe782ac23e33 ]

Fix some minor issues that Coverity spotted in the code. None
of that are serious but they're all valid concerns so fixing
them makes sense.

Signed-off-by: Zack Rusin <zackr@vmware.com>
Reviewed-by: Roland Scheidegger <sroland@vmware.com>
Reviewed-by: Martin Krastev <krastevm@vmware.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20210609172307.131929-5-zackr@vmware.com
Stable-dep-of: 517621b70600 ("drm/vmwgfx: Fix possible null pointer derefence with invalid contexts")
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/gpu/drm/ttm/ttm_memory.c
drivers/gpu/drm/vmwgfx/vmwgfx_binding.c
drivers/gpu/drm/vmwgfx/vmwgfx_cmdbuf.c
drivers/gpu/drm/vmwgfx/vmwgfx_cmdbuf_res.c
drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c
drivers/gpu/drm/vmwgfx/vmwgfx_mob.c
drivers/gpu/drm/vmwgfx/vmwgfx_msg.c
drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
drivers/gpu/drm/vmwgfx/vmwgfx_so.c
drivers/gpu/drm/vmwgfx/vmwgfx_validation.c

index 89d50f38c0f2c770825daa340e2ea2b0eef26c7f..5af52012fc5c6162685885ed756eb4f3ae35f8db 100644 (file)
@@ -431,8 +431,10 @@ int ttm_mem_global_init(struct ttm_mem_global *glob)
 
        si_meminfo(&si);
 
+       spin_lock(&glob->lock);
        /* set it as 0 by default to keep original behavior of OOM */
        glob->lower_mem_limit = 0;
+       spin_unlock(&glob->lock);
 
        ret = ttm_mem_init_kernel_zone(glob, &si);
        if (unlikely(ret != 0))
index f41550797970b5f7cc39ea20fa2eec18da69367e..4da4bf3b7f0b3ae86c7b9c43ca9af6fcd2f983f9 100644 (file)
@@ -713,7 +713,7 @@ static int vmw_binding_scrub_cb(struct vmw_ctx_bindinfo *bi, bool rebind)
  * without checking which bindings actually need to be emitted
  *
  * @cbs: Pointer to the context's struct vmw_ctx_binding_state
- * @bi: Pointer to where the binding info array is stored in @cbs
+ * @biv: Pointer to where the binding info array is stored in @cbs
  * @max_num: Maximum number of entries in the @bi array.
  *
  * Scans the @bi array for bindings and builds a buffer of view id data.
@@ -723,11 +723,9 @@ static int vmw_binding_scrub_cb(struct vmw_ctx_bindinfo *bi, bool rebind)
  * contains the command data.
  */
 static void vmw_collect_view_ids(struct vmw_ctx_binding_state *cbs,
-                                const struct vmw_ctx_bindinfo *bi,
+                                const struct vmw_ctx_bindinfo_view *biv,
                                 u32 max_num)
 {
-       const struct vmw_ctx_bindinfo_view *biv =
-               container_of(bi, struct vmw_ctx_bindinfo_view, bi);
        unsigned long i;
 
        cbs->bind_cmd_count = 0;
@@ -835,7 +833,7 @@ static int vmw_emit_set_sr(struct vmw_ctx_binding_state *cbs,
  */
 static int vmw_emit_set_rt(struct vmw_ctx_binding_state *cbs)
 {
-       const struct vmw_ctx_bindinfo *loc = &cbs->render_targets[0].bi;
+       const struct vmw_ctx_bindinfo_view *loc = &cbs->render_targets[0];
        struct {
                SVGA3dCmdHeader header;
                SVGA3dCmdDXSetRenderTargets body;
@@ -871,7 +869,7 @@ static int vmw_emit_set_rt(struct vmw_ctx_binding_state *cbs)
  * without checking which bindings actually need to be emitted
  *
  * @cbs: Pointer to the context's struct vmw_ctx_binding_state
- * @bi: Pointer to where the binding info array is stored in @cbs
+ * @biso: Pointer to where the binding info array is stored in @cbs
  * @max_num: Maximum number of entries in the @bi array.
  *
  * Scans the @bi array for bindings and builds a buffer of SVGA3dSoTarget data.
@@ -881,11 +879,9 @@ static int vmw_emit_set_rt(struct vmw_ctx_binding_state *cbs)
  * contains the command data.
  */
 static void vmw_collect_so_targets(struct vmw_ctx_binding_state *cbs,
-                                  const struct vmw_ctx_bindinfo *bi,
+                                  const struct vmw_ctx_bindinfo_so_target *biso,
                                   u32 max_num)
 {
-       const struct vmw_ctx_bindinfo_so_target *biso =
-               container_of(bi, struct vmw_ctx_bindinfo_so_target, bi);
        unsigned long i;
        SVGA3dSoTarget *so_buffer = (SVGA3dSoTarget *) cbs->bind_cmd_buffer;
 
@@ -916,7 +912,7 @@ static void vmw_collect_so_targets(struct vmw_ctx_binding_state *cbs,
  */
 static int vmw_emit_set_so_target(struct vmw_ctx_binding_state *cbs)
 {
-       const struct vmw_ctx_bindinfo *loc = &cbs->so_targets[0].bi;
+       const struct vmw_ctx_bindinfo_so_target *loc = &cbs->so_targets[0];
        struct {
                SVGA3dCmdHeader header;
                SVGA3dCmdDXSetSOTargets body;
@@ -1063,7 +1059,7 @@ static int vmw_emit_set_vb(struct vmw_ctx_binding_state *cbs)
 
 static int vmw_emit_set_uav(struct vmw_ctx_binding_state *cbs)
 {
-       const struct vmw_ctx_bindinfo *loc = &cbs->ua_views[0].views[0].bi;
+       const struct vmw_ctx_bindinfo_view *loc = &cbs->ua_views[0].views[0];
        struct {
                SVGA3dCmdHeader header;
                SVGA3dCmdDXSetUAViews body;
@@ -1093,7 +1089,7 @@ static int vmw_emit_set_uav(struct vmw_ctx_binding_state *cbs)
 
 static int vmw_emit_set_cs_uav(struct vmw_ctx_binding_state *cbs)
 {
-       const struct vmw_ctx_bindinfo *loc = &cbs->ua_views[1].views[0].bi;
+       const struct vmw_ctx_bindinfo_view *loc = &cbs->ua_views[1].views[0];
        struct {
                SVGA3dCmdHeader header;
                SVGA3dCmdDXSetCSUAViews body;
index 9a9fe10d829b892c8407bbe755a84c9b70210c3b..87a39721e5bc0d08c88a03ae3b293dcb1bf1617b 100644 (file)
@@ -514,7 +514,7 @@ static void vmw_cmdbuf_work_func(struct work_struct *work)
        struct vmw_cmdbuf_man *man =
                container_of(work, struct vmw_cmdbuf_man, work);
        struct vmw_cmdbuf_header *entry, *next;
-       uint32_t dummy;
+       uint32_t dummy = 0;
        bool send_fence = false;
        struct list_head restart_head[SVGA_CB_CONTEXT_MAX];
        int i;
index 47b92d0c898a700aac06fd3d0126b04633049cb2..f212368c031295273684915b32136a2891276bb0 100644 (file)
@@ -160,6 +160,7 @@ void vmw_cmdbuf_res_commit(struct list_head *list)
 void vmw_cmdbuf_res_revert(struct list_head *list)
 {
        struct vmw_cmdbuf_res *entry, *next;
+       int ret;
 
        list_for_each_entry_safe(entry, next, list, head) {
                switch (entry->state) {
@@ -167,7 +168,8 @@ void vmw_cmdbuf_res_revert(struct list_head *list)
                        vmw_cmdbuf_res_free(entry->man, entry);
                        break;
                case VMW_CMDBUF_RES_DEL:
-                       drm_ht_insert_item(&entry->man->resources, &entry->hash);
+                       ret = drm_ht_insert_item(&entry->man->resources, &entry->hash);
+                       BUG_ON(ret);
                        list_del(&entry->head);
                        list_add_tail(&entry->head, &entry->man->list);
                        entry->state = VMW_CMDBUF_RES_COMMITTED;
index 00082c679170ac6cf2557f4045ce667c6144a00d..831291b5d1a035f457f9a236a84c54c2540a71e3 100644 (file)
@@ -2535,6 +2535,8 @@ static int vmw_cmd_dx_so_define(struct vmw_private *dev_priv,
 
        so_type = vmw_so_cmd_to_type(header->id);
        res = vmw_context_cotable(ctx_node->ctx, vmw_so_cotables[so_type]);
+       if (IS_ERR(res))
+               return PTR_ERR(res);
        cmd = container_of(header, typeof(*cmd), header);
        ret = vmw_cotable_notify(res, cmd->defined_id);
 
index 7f95ed6aa2241c9eb0512054c98dad94ddd71b8e..fb0797b380dd27ad3ab01f721d3c4c67c5f63ca0 100644 (file)
@@ -494,11 +494,13 @@ static void vmw_mob_pt_setup(struct vmw_mob *mob,
 {
        unsigned long num_pt_pages = 0;
        struct ttm_buffer_object *bo = mob->pt_bo;
-       struct vmw_piter save_pt_iter;
+       struct vmw_piter save_pt_iter = {0};
        struct vmw_piter pt_iter;
        const struct vmw_sg_table *vsgt;
        int ret;
 
+       BUG_ON(num_data_pages == 0);
+
        ret = ttm_bo_reserve(bo, false, true, NULL);
        BUG_ON(ret != 0);
 
index 15b5bde69324272a8bcfe80a43b18abce1bb5475..751582f5ab0b1154904e8a1bd175fedc2f0f80a0 100644 (file)
@@ -154,6 +154,7 @@ static unsigned long vmw_port_hb_out(struct rpc_channel *channel,
        /* HB port can't access encrypted memory. */
        if (hb && !mem_encrypt_active()) {
                unsigned long bp = channel->cookie_high;
+               u32 channel_id = (channel->channel_id << 16);
 
                si = (uintptr_t) msg;
                di = channel->cookie_low;
@@ -161,7 +162,7 @@ static unsigned long vmw_port_hb_out(struct rpc_channel *channel,
                VMW_PORT_HB_OUT(
                        (MESSAGE_STATUS_SUCCESS << 16) | VMW_PORT_CMD_HB_MSG,
                        msg_len, si, di,
-                       VMWARE_HYPERVISOR_HB | (channel->channel_id << 16) |
+                       VMWARE_HYPERVISOR_HB | channel_id |
                        VMWARE_HYPERVISOR_OUT,
                        VMW_HYPERVISOR_MAGIC, bp,
                        eax, ebx, ecx, edx, si, di);
@@ -209,6 +210,7 @@ static unsigned long vmw_port_hb_in(struct rpc_channel *channel, char *reply,
        /* HB port can't access encrypted memory */
        if (hb && !mem_encrypt_active()) {
                unsigned long bp = channel->cookie_low;
+               u32 channel_id = (channel->channel_id << 16);
 
                si = channel->cookie_high;
                di = (uintptr_t) reply;
@@ -216,7 +218,7 @@ static unsigned long vmw_port_hb_in(struct rpc_channel *channel, char *reply,
                VMW_PORT_HB_IN(
                        (MESSAGE_STATUS_SUCCESS << 16) | VMW_PORT_CMD_HB_MSG,
                        reply_len, si, di,
-                       VMWARE_HYPERVISOR_HB | (channel->channel_id << 16),
+                       VMWARE_HYPERVISOR_HB | channel_id,
                        VMW_HYPERVISOR_MAGIC, bp,
                        eax, ebx, ecx, edx, si, di);
 
index 5e922d9d5f2ccbc5dbad0edffd3bf7a72db79d3e..26f88d64879f1e2430336ed977dc84f622b0a80a 100644 (file)
@@ -114,6 +114,7 @@ static void vmw_resource_release(struct kref *kref)
            container_of(kref, struct vmw_resource, kref);
        struct vmw_private *dev_priv = res->dev_priv;
        int id;
+       int ret;
        struct idr *idr = &dev_priv->res_idr[res->func->res_type];
 
        spin_lock(&dev_priv->resource_lock);
@@ -122,7 +123,8 @@ static void vmw_resource_release(struct kref *kref)
        if (res->backup) {
                struct ttm_buffer_object *bo = &res->backup->base;
 
-               ttm_bo_reserve(bo, false, false, NULL);
+               ret = ttm_bo_reserve(bo, false, false, NULL);
+               BUG_ON(ret);
                if (vmw_resource_mob_attached(res) &&
                    res->func->unbind != NULL) {
                        struct ttm_validate_buffer val_buf;
@@ -1001,7 +1003,9 @@ int vmw_resource_pin(struct vmw_resource *res, bool interruptible)
                if (res->backup) {
                        vbo = res->backup;
 
-                       ttm_bo_reserve(&vbo->base, interruptible, false, NULL);
+                       ret = ttm_bo_reserve(&vbo->base, interruptible, false, NULL);
+                       if (ret)
+                               goto out_no_validate;
                        if (!vbo->base.pin_count) {
                                ret = ttm_bo_validate
                                        (&vbo->base,
index 3f97b61dd5d83bf87c437ccf28ec45e95c497728..9330f1a0f1743ee09c6af67f8b7fc622e6f37218 100644 (file)
@@ -538,7 +538,8 @@ const SVGACOTableType vmw_so_cotables[] = {
        [vmw_so_ds] = SVGA_COTABLE_DEPTHSTENCIL,
        [vmw_so_rs] = SVGA_COTABLE_RASTERIZERSTATE,
        [vmw_so_ss] = SVGA_COTABLE_SAMPLER,
-       [vmw_so_so] = SVGA_COTABLE_STREAMOUTPUT
+       [vmw_so_so] = SVGA_COTABLE_STREAMOUTPUT,
+       [vmw_so_max]= SVGA_COTABLE_MAX
 };
 
 
index f2e2bf6d1421fd8751348e6525ef5ea3411fdd6b..cc1cfc827bb9a8630b89c3af2091786bcc076ed0 100644 (file)
@@ -585,13 +585,13 @@ int vmw_validation_bo_validate(struct vmw_validation_context *ctx, bool intr)
                        container_of(entry->base.bo, typeof(*vbo), base);
 
                if (entry->cpu_blit) {
-                       struct ttm_operation_ctx ctx = {
+                       struct ttm_operation_ctx ttm_ctx = {
                                .interruptible = intr,
                                .no_wait_gpu = false
                        };
 
                        ret = ttm_bo_validate(entry->base.bo,
-                                             &vmw_nonfixed_placement, &ctx);
+                                             &vmw_nonfixed_placement, &ttm_ctx);
                } else {
                        ret = vmw_validation_bo_validate_single
                        (entry->base.bo, intr, entry->as_mob);