drm/vmwgfx: Fix some static checker warnings
[ 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>
This commit is contained in:

committed by
Greg Kroah-Hartman

parent
dc7cd107ce
commit
675ebda69c
@@ -431,8 +431,10 @@ int ttm_mem_global_init(struct ttm_mem_global *glob)
|
|||||||
|
|
||||||
si_meminfo(&si);
|
si_meminfo(&si);
|
||||||
|
|
||||||
|
spin_lock(&glob->lock);
|
||||||
/* set it as 0 by default to keep original behavior of OOM */
|
/* set it as 0 by default to keep original behavior of OOM */
|
||||||
glob->lower_mem_limit = 0;
|
glob->lower_mem_limit = 0;
|
||||||
|
spin_unlock(&glob->lock);
|
||||||
|
|
||||||
ret = ttm_mem_init_kernel_zone(glob, &si);
|
ret = ttm_mem_init_kernel_zone(glob, &si);
|
||||||
if (unlikely(ret != 0))
|
if (unlikely(ret != 0))
|
||||||
|
@@ -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
|
* without checking which bindings actually need to be emitted
|
||||||
*
|
*
|
||||||
* @cbs: Pointer to the context's struct vmw_ctx_binding_state
|
* @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.
|
* @max_num: Maximum number of entries in the @bi array.
|
||||||
*
|
*
|
||||||
* Scans the @bi array for bindings and builds a buffer of view id data.
|
* 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.
|
* contains the command data.
|
||||||
*/
|
*/
|
||||||
static void vmw_collect_view_ids(struct vmw_ctx_binding_state *cbs,
|
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)
|
u32 max_num)
|
||||||
{
|
{
|
||||||
const struct vmw_ctx_bindinfo_view *biv =
|
|
||||||
container_of(bi, struct vmw_ctx_bindinfo_view, bi);
|
|
||||||
unsigned long i;
|
unsigned long i;
|
||||||
|
|
||||||
cbs->bind_cmd_count = 0;
|
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)
|
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 {
|
struct {
|
||||||
SVGA3dCmdHeader header;
|
SVGA3dCmdHeader header;
|
||||||
SVGA3dCmdDXSetRenderTargets body;
|
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
|
* without checking which bindings actually need to be emitted
|
||||||
*
|
*
|
||||||
* @cbs: Pointer to the context's struct vmw_ctx_binding_state
|
* @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.
|
* @max_num: Maximum number of entries in the @bi array.
|
||||||
*
|
*
|
||||||
* Scans the @bi array for bindings and builds a buffer of SVGA3dSoTarget data.
|
* 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.
|
* contains the command data.
|
||||||
*/
|
*/
|
||||||
static void vmw_collect_so_targets(struct vmw_ctx_binding_state *cbs,
|
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)
|
u32 max_num)
|
||||||
{
|
{
|
||||||
const struct vmw_ctx_bindinfo_so_target *biso =
|
|
||||||
container_of(bi, struct vmw_ctx_bindinfo_so_target, bi);
|
|
||||||
unsigned long i;
|
unsigned long i;
|
||||||
SVGA3dSoTarget *so_buffer = (SVGA3dSoTarget *) cbs->bind_cmd_buffer;
|
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)
|
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 {
|
struct {
|
||||||
SVGA3dCmdHeader header;
|
SVGA3dCmdHeader header;
|
||||||
SVGA3dCmdDXSetSOTargets body;
|
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)
|
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 {
|
struct {
|
||||||
SVGA3dCmdHeader header;
|
SVGA3dCmdHeader header;
|
||||||
SVGA3dCmdDXSetUAViews body;
|
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)
|
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 {
|
struct {
|
||||||
SVGA3dCmdHeader header;
|
SVGA3dCmdHeader header;
|
||||||
SVGA3dCmdDXSetCSUAViews body;
|
SVGA3dCmdDXSetCSUAViews body;
|
||||||
|
@@ -514,7 +514,7 @@ static void vmw_cmdbuf_work_func(struct work_struct *work)
|
|||||||
struct vmw_cmdbuf_man *man =
|
struct vmw_cmdbuf_man *man =
|
||||||
container_of(work, struct vmw_cmdbuf_man, work);
|
container_of(work, struct vmw_cmdbuf_man, work);
|
||||||
struct vmw_cmdbuf_header *entry, *next;
|
struct vmw_cmdbuf_header *entry, *next;
|
||||||
uint32_t dummy;
|
uint32_t dummy = 0;
|
||||||
bool send_fence = false;
|
bool send_fence = false;
|
||||||
struct list_head restart_head[SVGA_CB_CONTEXT_MAX];
|
struct list_head restart_head[SVGA_CB_CONTEXT_MAX];
|
||||||
int i;
|
int i;
|
||||||
|
@@ -160,6 +160,7 @@ void vmw_cmdbuf_res_commit(struct list_head *list)
|
|||||||
void vmw_cmdbuf_res_revert(struct list_head *list)
|
void vmw_cmdbuf_res_revert(struct list_head *list)
|
||||||
{
|
{
|
||||||
struct vmw_cmdbuf_res *entry, *next;
|
struct vmw_cmdbuf_res *entry, *next;
|
||||||
|
int ret;
|
||||||
|
|
||||||
list_for_each_entry_safe(entry, next, list, head) {
|
list_for_each_entry_safe(entry, next, list, head) {
|
||||||
switch (entry->state) {
|
switch (entry->state) {
|
||||||
@@ -167,7 +168,8 @@ void vmw_cmdbuf_res_revert(struct list_head *list)
|
|||||||
vmw_cmdbuf_res_free(entry->man, entry);
|
vmw_cmdbuf_res_free(entry->man, entry);
|
||||||
break;
|
break;
|
||||||
case VMW_CMDBUF_RES_DEL:
|
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_del(&entry->head);
|
||||||
list_add_tail(&entry->head, &entry->man->list);
|
list_add_tail(&entry->head, &entry->man->list);
|
||||||
entry->state = VMW_CMDBUF_RES_COMMITTED;
|
entry->state = VMW_CMDBUF_RES_COMMITTED;
|
||||||
|
@@ -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);
|
so_type = vmw_so_cmd_to_type(header->id);
|
||||||
res = vmw_context_cotable(ctx_node->ctx, vmw_so_cotables[so_type]);
|
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);
|
cmd = container_of(header, typeof(*cmd), header);
|
||||||
ret = vmw_cotable_notify(res, cmd->defined_id);
|
ret = vmw_cotable_notify(res, cmd->defined_id);
|
||||||
|
|
||||||
|
@@ -494,11 +494,13 @@ static void vmw_mob_pt_setup(struct vmw_mob *mob,
|
|||||||
{
|
{
|
||||||
unsigned long num_pt_pages = 0;
|
unsigned long num_pt_pages = 0;
|
||||||
struct ttm_buffer_object *bo = mob->pt_bo;
|
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;
|
struct vmw_piter pt_iter;
|
||||||
const struct vmw_sg_table *vsgt;
|
const struct vmw_sg_table *vsgt;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
BUG_ON(num_data_pages == 0);
|
||||||
|
|
||||||
ret = ttm_bo_reserve(bo, false, true, NULL);
|
ret = ttm_bo_reserve(bo, false, true, NULL);
|
||||||
BUG_ON(ret != 0);
|
BUG_ON(ret != 0);
|
||||||
|
|
||||||
|
@@ -154,6 +154,7 @@ static unsigned long vmw_port_hb_out(struct rpc_channel *channel,
|
|||||||
/* HB port can't access encrypted memory. */
|
/* HB port can't access encrypted memory. */
|
||||||
if (hb && !mem_encrypt_active()) {
|
if (hb && !mem_encrypt_active()) {
|
||||||
unsigned long bp = channel->cookie_high;
|
unsigned long bp = channel->cookie_high;
|
||||||
|
u32 channel_id = (channel->channel_id << 16);
|
||||||
|
|
||||||
si = (uintptr_t) msg;
|
si = (uintptr_t) msg;
|
||||||
di = channel->cookie_low;
|
di = channel->cookie_low;
|
||||||
@@ -161,7 +162,7 @@ static unsigned long vmw_port_hb_out(struct rpc_channel *channel,
|
|||||||
VMW_PORT_HB_OUT(
|
VMW_PORT_HB_OUT(
|
||||||
(MESSAGE_STATUS_SUCCESS << 16) | VMW_PORT_CMD_HB_MSG,
|
(MESSAGE_STATUS_SUCCESS << 16) | VMW_PORT_CMD_HB_MSG,
|
||||||
msg_len, si, di,
|
msg_len, si, di,
|
||||||
VMWARE_HYPERVISOR_HB | (channel->channel_id << 16) |
|
VMWARE_HYPERVISOR_HB | channel_id |
|
||||||
VMWARE_HYPERVISOR_OUT,
|
VMWARE_HYPERVISOR_OUT,
|
||||||
VMW_HYPERVISOR_MAGIC, bp,
|
VMW_HYPERVISOR_MAGIC, bp,
|
||||||
eax, ebx, ecx, edx, si, di);
|
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 */
|
/* HB port can't access encrypted memory */
|
||||||
if (hb && !mem_encrypt_active()) {
|
if (hb && !mem_encrypt_active()) {
|
||||||
unsigned long bp = channel->cookie_low;
|
unsigned long bp = channel->cookie_low;
|
||||||
|
u32 channel_id = (channel->channel_id << 16);
|
||||||
|
|
||||||
si = channel->cookie_high;
|
si = channel->cookie_high;
|
||||||
di = (uintptr_t) reply;
|
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(
|
VMW_PORT_HB_IN(
|
||||||
(MESSAGE_STATUS_SUCCESS << 16) | VMW_PORT_CMD_HB_MSG,
|
(MESSAGE_STATUS_SUCCESS << 16) | VMW_PORT_CMD_HB_MSG,
|
||||||
reply_len, si, di,
|
reply_len, si, di,
|
||||||
VMWARE_HYPERVISOR_HB | (channel->channel_id << 16),
|
VMWARE_HYPERVISOR_HB | channel_id,
|
||||||
VMW_HYPERVISOR_MAGIC, bp,
|
VMW_HYPERVISOR_MAGIC, bp,
|
||||||
eax, ebx, ecx, edx, si, di);
|
eax, ebx, ecx, edx, si, di);
|
||||||
|
|
||||||
|
@@ -114,6 +114,7 @@ static void vmw_resource_release(struct kref *kref)
|
|||||||
container_of(kref, struct vmw_resource, kref);
|
container_of(kref, struct vmw_resource, kref);
|
||||||
struct vmw_private *dev_priv = res->dev_priv;
|
struct vmw_private *dev_priv = res->dev_priv;
|
||||||
int id;
|
int id;
|
||||||
|
int ret;
|
||||||
struct idr *idr = &dev_priv->res_idr[res->func->res_type];
|
struct idr *idr = &dev_priv->res_idr[res->func->res_type];
|
||||||
|
|
||||||
spin_lock(&dev_priv->resource_lock);
|
spin_lock(&dev_priv->resource_lock);
|
||||||
@@ -122,7 +123,8 @@ static void vmw_resource_release(struct kref *kref)
|
|||||||
if (res->backup) {
|
if (res->backup) {
|
||||||
struct ttm_buffer_object *bo = &res->backup->base;
|
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) &&
|
if (vmw_resource_mob_attached(res) &&
|
||||||
res->func->unbind != NULL) {
|
res->func->unbind != NULL) {
|
||||||
struct ttm_validate_buffer val_buf;
|
struct ttm_validate_buffer val_buf;
|
||||||
@@ -1001,7 +1003,9 @@ int vmw_resource_pin(struct vmw_resource *res, bool interruptible)
|
|||||||
if (res->backup) {
|
if (res->backup) {
|
||||||
vbo = 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) {
|
if (!vbo->base.pin_count) {
|
||||||
ret = ttm_bo_validate
|
ret = ttm_bo_validate
|
||||||
(&vbo->base,
|
(&vbo->base,
|
||||||
|
@@ -538,7 +538,8 @@ const SVGACOTableType vmw_so_cotables[] = {
|
|||||||
[vmw_so_ds] = SVGA_COTABLE_DEPTHSTENCIL,
|
[vmw_so_ds] = SVGA_COTABLE_DEPTHSTENCIL,
|
||||||
[vmw_so_rs] = SVGA_COTABLE_RASTERIZERSTATE,
|
[vmw_so_rs] = SVGA_COTABLE_RASTERIZERSTATE,
|
||||||
[vmw_so_ss] = SVGA_COTABLE_SAMPLER,
|
[vmw_so_ss] = SVGA_COTABLE_SAMPLER,
|
||||||
[vmw_so_so] = SVGA_COTABLE_STREAMOUTPUT
|
[vmw_so_so] = SVGA_COTABLE_STREAMOUTPUT,
|
||||||
|
[vmw_so_max]= SVGA_COTABLE_MAX
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@@ -585,13 +585,13 @@ int vmw_validation_bo_validate(struct vmw_validation_context *ctx, bool intr)
|
|||||||
container_of(entry->base.bo, typeof(*vbo), base);
|
container_of(entry->base.bo, typeof(*vbo), base);
|
||||||
|
|
||||||
if (entry->cpu_blit) {
|
if (entry->cpu_blit) {
|
||||||
struct ttm_operation_ctx ctx = {
|
struct ttm_operation_ctx ttm_ctx = {
|
||||||
.interruptible = intr,
|
.interruptible = intr,
|
||||||
.no_wait_gpu = false
|
.no_wait_gpu = false
|
||||||
};
|
};
|
||||||
|
|
||||||
ret = ttm_bo_validate(entry->base.bo,
|
ret = ttm_bo_validate(entry->base.bo,
|
||||||
&vmw_nonfixed_placement, &ctx);
|
&vmw_nonfixed_placement, &ttm_ctx);
|
||||||
} else {
|
} else {
|
||||||
ret = vmw_validation_bo_validate_single
|
ret = vmw_validation_bo_validate_single
|
||||||
(entry->base.bo, intr, entry->as_mob);
|
(entry->base.bo, intr, entry->as_mob);
|
||||||
|
Reference in New Issue
Block a user