HeapCrash / Challenges / Touch driver interrupt handler

Touch driver interrupt handler

A kernel driver for an I2C touch controller handles its level-triggered, active-low interrupt line. As soon as the panel is touched the kernel logs 'BUG: sleeping function called from invalid context' and the board locks up. Unloading the module occasionally oopses too.

The code

Embedded Linux C. It compiles. There are 3 real bugs in it: the kind that pass a bench test and fail in the field.

static irqreturn_t tp_irq(int irq, void *dev)
{
    struct tp *tp = dev;
    mutex_lock(&tp->lock);
    tp_read_points(tp);              /* I2C transfer, sleeps */
    mutex_unlock(&tp->lock);
    return IRQ_HANDLED;
}

static int tp_setup_irq(struct tp *tp)
{
    return request_irq(tp->irq, tp_irq,
                       IRQF_TRIGGER_LOW, "tp", tp);
}

static void tp_remove(struct tp *tp)
{
    kfree(tp);
    free_irq(tp->irq, tp);
}

What an interviewer expects

The bugs, reference fixes and the follow-up question are in the practice app, after you've tried it.

Companies that test this

Matched on the skills each company's embedded roles emphasise.

Related challenges

Flag the lines, say what breaks, then fix it and build it with clang in your browser.

Find the bugs