void spi_unregister_controller(struct spi_controller *ctlr)
 {
        struct spi_controller *found;
+       int id = ctlr->bus_num;
        int dummy;
 
        /* First make sure that this controller was ever added */
        mutex_lock(&board_lock);
-       found = idr_find(&spi_master_idr, ctlr->bus_num);
+       found = idr_find(&spi_master_idr, id);
        mutex_unlock(&board_lock);
        if (found != ctlr) {
                dev_dbg(&ctlr->dev,
        device_unregister(&ctlr->dev);
        /* free bus id */
        mutex_lock(&board_lock);
-       idr_remove(&spi_master_idr, ctlr->bus_num);
+       idr_remove(&spi_master_idr, id);
        mutex_unlock(&board_lock);
 }
 EXPORT_SYMBOL_GPL(spi_unregister_controller);