struct delayed_work work;
void *device_context;
unsigned long earliest_update;
- struct klgd_command_stream *last_stream;
size_t plugin_count;
struct klgd_plugin **plugins;
bool *dontfree;
struct klgd_command_stream *ss;
ret = plugin->get_commands(plugin, &ss, now);
+ /* Something happened while the plugin was building the command stream
+ * but the error is recoverable. Send the incomplete command stream
+ * and try again ASAP. */
+ if (ret == -EAGAIN)
+ break;
+
/* Unrecoverable error, ditch the stream and bail out. */
- if (ret == -EFAULT) {
+ if (ret) {
klgd_free_stream(ss);
klgd_free_stream(*s);
return -EFAULT;
klgd_free_stream(*s);
return -EFAULT;
}
-
- /* Something happened while the plugin was building the command stream
- * but the error is recoverable. Send the incomplete command stream
- * and try again ASAP. */
- if (ret == -EAGAIN)
- break;
}
if ((*s)->count) {
- priv->last_stream = *s;
printk(KERN_NOTICE "KLGD: Command stream built\n");
return ret;
}
struct klgd_main_private *priv = container_of(dw, struct klgd_main_private, work);
struct klgd_command_stream *s;
unsigned long now;
- int ret, ret2;
+ int ret;
priv->try_again = false;
printk(KERN_NOTICE "KLGD/WQ: --- WQ begins ---\n");
case -ENOENT:
/* Empty command stream. Plugins have no work for us, exit */
goto out;
- case -EFAULT:
+ case 0:
+ break;
+ default:
/* Unrecoverable error, consider the endpoint dead */
- printk(KERN_ERR "KLGD: Unrecoverable error while building command stream. No further commands will be sent to the device.\n");
+ printk(KERN_ERR "KLGD: Unrecoverable error while building command stream, ret code %d. No further commands will be sent to the endpoint.\n", ret);
priv->endpoint_dead = true;
mutex_unlock(&priv->send_lock);
return;
- case 0:
- break;
- default:
- /* TODO: Handle unspecified error */
- break;
}
- now = jiffies;
- ret2 = priv->send_command_stream(priv->device_context, s);
- if (ret2) {
- /* TODO: Error handling */
- printk(KERN_NOTICE "KLGD/WQ: Unable to send command stream, ret code %d\n", ret);
+ now = jiffies;
+ ret = priv->send_command_stream(priv->device_context, s);
+ if (ret) {
+ printk(KERN_ERR "KLGD/WQ: Unable to send command stream, ret code %d. Marking endpoint dead.\n", ret);
+ priv->endpoint_dead = true;
+ mutex_unlock(&priv->send_lock);
+ return;
} else
printk(KERN_NOTICE "KLGD/WQ: Commands sent, time elapsed %u [msec]\n", jiffies_to_msecs(jiffies - now));
kfree(s);
out:
mutex_unlock(&priv->send_lock);
- if (ret == -EAGAIN) {
+ if (priv->try_again) {
queue_delayed_work(priv->wq, &priv->work, TRYAGAIN_DELAY);
return;
}
priv->plugin_count = plugin_count;
priv->device_context = dev_ctx;
- priv->last_stream = NULL;
priv->send_command_stream = callback;
ctx->private = priv;
size_t idx;
/* Recovery update is scheduled. Do not allow any other updates until the recovery is done.
- * Also do not send updates to dead endpoint */
+ * Also do not send updates to a dead endpoint */
if (priv->try_again || priv->endpoint_dead)
return;