diff --git a/drivers/gpu/drm/apple/iomfb_v26_6_link.c b/drivers/gpu/drm/apple/iomfb_v26_6_link.c index 36d9a6d38691e..3b5c0d08f5c62 100644 --- a/drivers/gpu/drm/apple/iomfb_v26_6_link.c +++ b/drivers/gpu/drm/apple/iomfb_v26_6_link.c @@ -63,9 +63,17 @@ struct dcp_v26_event { /* Called with the lock held. */ static void link_fail(struct dcp_v26_link *link) { + struct dcp_v26_event *e, *next; + if (!link->failed) dev_err(link->dev, "DCP link stopped; firmware buffers are kept until reboot\n"); link->failed = true; + /* Nothing dequeues events from a failed link. */ + list_for_each_entry_safe(e, next, &link->events, list) { + list_del(&e->list); + kfree(e); + } + link->event_count = 0; wake_up(&link->wait); } @@ -409,6 +417,7 @@ int dcp_v26_link_pump(struct dcp_v26_link *link, unsigned long timeout, /* * Calls @tag and handles the callbacks that arrive until its reply, and, for * a non-zero @completion_id, until the swap-complete callback for that swap. + * A call that fails once submitted, including by timing out, stops the link. * Must not be called concurrently with itself or dcp_v26_link_pump(), except * from inside a callback handler. */ @@ -443,6 +452,10 @@ int dcp_v26_link_call(struct dcp_v26_link *link, u32 tag, const void *input, ret = dcp_v26_link_pump(link, 0, callback, cookie); if (ret) { kfree(packet); + /* The caller gives up on the session: stop queueing. */ + mutex_lock(&link->lock); + link_fail(link); + mutex_unlock(&link->lock); return ret; } } @@ -450,6 +463,7 @@ int dcp_v26_link_call(struct dcp_v26_link *link, u32 tag, const void *input, mutex_lock(&link->lock); nested = link->callback_depth != 0; if (nested && !link->callback_count) { + link_fail(link); mutex_unlock(&link->lock); kfree(packet); return -EPROTO; @@ -471,8 +485,10 @@ int dcp_v26_link_call(struct dcp_v26_link *link, u32 tag, const void *input, struct dcp_v26_event *e = link_next_event(link, max_t(long, deadline - jiffies, 0)); struct apple_dcp_link_rpc_header *h; - if (IS_ERR(e)) - return PTR_ERR(e); + if (IS_ERR(e)) { + ret = PTR_ERR(e); + goto abandon; + } h = (void *)e->data; if (e->kind == DCP_V26_EVENT_REPLY) { if (replied || e->size != size || e->message != expected || @@ -494,9 +510,16 @@ int dcp_v26_link_call(struct dcp_v26_link *link, u32 tag, const void *input, } kfree(e); if (ret) - return ret; + goto abandon; if (replied && (!completion_id || completed == completion_id)) return 0; } - return -ETIMEDOUT; + ret = -ETIMEDOUT; +abandon: + /* The firmware may still answer: queue nothing for a call nobody waits for. */ + mutex_lock(&link->lock); + link->calls[nested].active = false; + link_fail(link); + mutex_unlock(&link->lock); + return ret; }