#include <linux/gpio.h>
 #include <linux/init.h>
 #include <linux/interrupt.h>
+#include <linux/io.h>
 #include <linux/ioport.h>
 #include <linux/module.h>
 #include <linux/of.h>
        /* Assume card is present initially */
        set_bit(ATMCI_CARD_PRESENT, &slot->flags);
        if (gpio_is_valid(slot->detect_pin)) {
-               if (gpio_request(slot->detect_pin, "mmc_detect")) {
+               if (devm_gpio_request(&host->pdev->dev, slot->detect_pin,
+                                     "mmc_detect")) {
                        dev_dbg(&mmc->class_dev, "no detect pin available\n");
                        slot->detect_pin = -EBUSY;
                } else if (gpio_get_value(slot->detect_pin) ^
                mmc->caps |= MMC_CAP_NEEDS_POLL;
 
        if (gpio_is_valid(slot->wp_pin)) {
-               if (gpio_request(slot->wp_pin, "mmc_wp")) {
+               if (devm_gpio_request(&host->pdev->dev, slot->wp_pin,
+                                     "mmc_wp")) {
                        dev_dbg(&mmc->class_dev, "no WP pin available\n");
                        slot->wp_pin = -EBUSY;
                }
                        dev_dbg(&mmc->class_dev,
                                "could not request IRQ %d for detect pin\n",
                                gpio_to_irq(slot->detect_pin));
-                       gpio_free(slot->detect_pin);
                        slot->detect_pin = -EBUSY;
                }
        }
 
                free_irq(gpio_to_irq(pin), slot);
                del_timer_sync(&slot->detect_timer);
-               gpio_free(pin);
        }
-       if (gpio_is_valid(slot->wp_pin))
-               gpio_free(slot->wp_pin);
 
        slot->host->slot[id] = NULL;
        mmc_free_host(slot->mmc);
        if (irq < 0)
                return irq;
 
-       host = kzalloc(sizeof(struct atmel_mci), GFP_KERNEL);
+       host = devm_kzalloc(&pdev->dev, sizeof(*host), GFP_KERNEL);
        if (!host)
                return -ENOMEM;
 
        spin_lock_init(&host->lock);
        INIT_LIST_HEAD(&host->queue);
 
-       host->mck = clk_get(&pdev->dev, "mci_clk");
-       if (IS_ERR(host->mck)) {
-               ret = PTR_ERR(host->mck);
-               goto err_clk_get;
-       }
+       host->mck = devm_clk_get(&pdev->dev, "mci_clk");
+       if (IS_ERR(host->mck))
+               return PTR_ERR(host->mck);
 
-       ret = -ENOMEM;
-       host->regs = ioremap(regs->start, resource_size(regs));
+       host->regs = devm_ioremap(&pdev->dev, regs->start, resource_size(regs));
        if (!host->regs)
-               goto err_ioremap;
+               return -ENOMEM;
 
        ret = clk_prepare_enable(host->mck);
        if (ret)
-               goto err_request_irq;
+               return ret;
+
        atmci_writel(host, ATMCI_CR, ATMCI_CR_SWRST);
        host->bus_hz = clk_get_rate(host->mck);
        clk_disable_unprepare(host->mck);
 
        ret = request_irq(irq, atmci_interrupt, 0, dev_name(&pdev->dev), host);
        if (ret)
-               goto err_request_irq;
+               return ret;
 
        /* Get MCI capabilities and set operations according to it */
        atmci_get_cap(host);
        if (host->dma.chan)
                dma_release_channel(host->dma.chan);
        free_irq(irq, host);
-err_request_irq:
-       iounmap(host->regs);
-err_ioremap:
-       clk_put(host->mck);
-err_clk_get:
-       kfree(host);
        return ret;
 }
 
                dma_release_channel(host->dma.chan);
 
        free_irq(platform_get_irq(pdev, 0), host);
-       iounmap(host->regs);
-
-       clk_put(host->mck);
-       kfree(host);
 
        return 0;
 }