diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index c1a6cc2a33624..672da2a64b761 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -279,8 +279,8 @@ struct fastrpc_invoke_ctx { bool is_work_done; /* process updates poll memory instead of glink response */ bool is_polled; - /* set once put_work has been scheduled for this ctx, guarded by fl->lock */ - bool put_work_scheduled; + /* set once put_work is queued; atomic as it's set from IRQ context */ + atomic_t put_work_scheduled; struct kref refcount; struct list_head node; /* list of ctxs */ struct completion work; @@ -680,17 +680,13 @@ static void fastrpc_context_put_wq(struct work_struct *work) fastrpc_context_put(ctx); } -/* Ensures put_work is scheduled at most once per ctx; racing callers may both try. */ +/* + * Schedules put_work at most once per ctx. Must stay lock-free: it runs from + * the glink rx hard-IRQ and from fastrpc_notify_users() with fl->lock held. + */ static void fastrpc_context_schedule_put_work(struct fastrpc_invoke_ctx *ctx) { - bool do_schedule; - - spin_lock(&ctx->fl->lock); - do_schedule = !ctx->put_work_scheduled; - ctx->put_work_scheduled = true; - spin_unlock(&ctx->fl->lock); - - if (do_schedule) + if (!atomic_xchg(&ctx->put_work_scheduled, 1)) schedule_work(&ctx->put_work); } @@ -3084,10 +3080,7 @@ static void fastrpc_notify_users(struct fastrpc_user *user) list_for_each_entry(ctx, &user->interrupted, node) { ctx->retval = -EPIPE; complete(&ctx->work); - if (!ctx->put_work_scheduled) { - ctx->put_work_scheduled = true; - schedule_work(&ctx->put_work); - } + fastrpc_context_schedule_put_work(ctx); } spin_unlock(&user->lock); }