Received: by 2002:ac0:8f67:0:0:0:0:0 with SMTP id z94-v6csp1749952imb; Mon, 1 Oct 2018 05:46:36 -0700 (PDT) X-Google-Smtp-Source: ACcGV62Y6Vp3joqYhOGPRms2U28fWouK/4qbFgDHQeXb5RVyB4Vh74WBjTBO2yXYpsZaQfWdLdzg X-Received: by 2002:a62:86c6:: with SMTP id x189-v6mr11384965pfd.252.1538397996234; Mon, 01 Oct 2018 05:46:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538397996; cv=none; d=google.com; s=arc-20160816; b=gT/Sy5p5YB0WTDDjMIZB6hoa154p7EYxbbvAp5d6/WDKAJ7qy/eMauVU3SE8OqYmfA zb0cAV95z9Nbz6SwmSvgRRl4vG5JbaxoLIxp7tk06X0eStrMjuoxiN6W6FoFh5wvtAGA StiidlVSZmEaiXmqFQsmGxrQjeHs2S9xdti+QaocVOLMaMIKDPDC4IUGrN6M/7HH7Qut L/I6NRyyDA4lsDx6HeuCoPfyUnasGkpfToTFKzE/LKsb2urvyHuQqbDQMsMb+RqsVlQP mi/jwdiFHUcz8fTtcyxe90Zb1HLUOdF4C9CGprqLfuYgKLC0C0FjVF52eI9VM38jBm7t g8LQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=hZUbn50UsHuR5ct+6gyJtPRAN067Ky0FADOBnmfRKwk=; b=tVj6pVTEXKkLyX1engv/6FNnESklCAiJjjQsHFY3tUvJUrHh0DDeTmXBxoSUyEe7S1 1StRzMOjCIk+OGhL81c4lpjnQiiLMX7gQAvvvgUTqxINLBnLSGYsYVudv9nplf9Jfr0f ajHYWTFDCJhNP6lu6AWynXts3XGv3dtCy9fAXKForqjMBvmcZvyGwMFYJCmtAQgr8Wue hbIh8gGm3a59hYMnBeMbecklFBloaWRVNavllzXEKZsLzX3hdhlMZic6gwsuPOekdAtv HrQpqt+Zi6oiDIdo01E7EcvafVhzdXR2XQKE4Utrd/UQ1l7h8ZW1tQHf70K9Xah5m0Xe d9ig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=er7sHnp8; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r28-v6si2909251pgk.263.2018.10.01.05.46.21; Mon, 01 Oct 2018 05:46:36 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=er7sHnp8; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729468AbeJATVj (ORCPT + 99 others); Mon, 1 Oct 2018 15:21:39 -0400 Received: from mail-ed1-f66.google.com ([209.85.208.66]:40822 "EHLO mail-ed1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729245AbeJATVi (ORCPT ); Mon, 1 Oct 2018 15:21:38 -0400 Received: by mail-ed1-f66.google.com with SMTP id j62-v6so14042722edd.7 for ; Mon, 01 Oct 2018 05:43:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hZUbn50UsHuR5ct+6gyJtPRAN067Ky0FADOBnmfRKwk=; b=er7sHnp8+EEuHm3NSyIVwJTG/X/IaJKI5GvTlpw/I8yVuJ1HoPIrcZFS0kk200FEtF 8h7VPRy9qYj+pGHUwz45pxwYFyODYfIfLzK131miMqsbrN1KscXvIsc7qlQltNcGf+hF h4syNmPIXxWL25YpeGc/Q7fBezF5KzZBcIOVz8ZEW1oCEJ3YjyfoKeensnRv8Wz7ZsHB iGKp/QTdVhC5nb+HJLp1OKIMunO8Qi/5lSq3GkC2K3eFmcSGWFWIzvkppN5jYyHBFcc1 Wh5Egw6Ji3MD+/Mn8tGkv5xx9B+urM4DfSU5qF1SCCNd7RudhkxvPamtfg3qgV5rvcbC T2WA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hZUbn50UsHuR5ct+6gyJtPRAN067Ky0FADOBnmfRKwk=; b=mWFMoluPzCGufijZYX0KXgY00bP/m9wvOF2vRvvQCU9i6aA7HvypCRnEDO+64wGYRQ qOiKWffzihCnFGtYoXsuW3O5wVz8PU8D45yD7w60c0FJVu5xYmaCi71qKtaP/4iNpi0C DDrM+CMFxCoBCZW+K0nQ1EO8f2Mnhx/2Xcbh1cQJ1EtX5eP+AasHw430FDOLHHfpRRGx LC5dhwLAWft8i5Nt9wap249K1t0O0ntzpQQR2zWjXS2PLQmI4KwYEZ9VGltpzNOmfDNB Uc+pOsEbwdUZE47G3WQTj+Tkcv0JXlwXCdzM7Z4nIim9ogPB5db1FMf1h4XSJIQTywYP G54w== X-Gm-Message-State: ABuFfohGBgTXbQuIjAw5ZuCVITV4v88O9M3F/EE4fCnQwFbidOlxckW9 8mk+TWgK/VlXmHCyH3VZpvI= X-Received: by 2002:aa7:c549:: with SMTP id s9-v6mr17808771edr.73.1538397838271; Mon, 01 Oct 2018 05:43:58 -0700 (PDT) Received: from neopili.qtec.com (cpe.xe-3-0-1-778.vbrnqe10.dk.customer.tdc.net. [80.197.57.18]) by smtp.gmail.com with ESMTPSA id h3-v6sm5278700ede.42.2018.10.01.05.43.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 01 Oct 2018 05:43:57 -0700 (PDT) From: Ricardo Ribalda Delgado To: David Woodhouse , Brian Norris , Boris Brezillon , Marek Vasut , Richard Weinberger , Zhouyang Jia , linux-mtd@lists.infradead.org, open list Cc: Ricardo Ribalda Delgado Subject: [PATCH v4 3/8] mtd: maps: gpio-addr-flash: Use devm_* functions Date: Mon, 1 Oct 2018 14:43:46 +0200 Message-Id: <20181001124351.31615-3-ricardo.ribalda@gmail.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181001124351.31615-1-ricardo.ribalda@gmail.com> References: <20181001124351.31615-1-ricardo.ribalda@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org By using devm functions we can make the code cleaner. Signed-off-by: Ricardo Ribalda Delgado --- drivers/mtd/maps/gpio-addr-flash.c | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/drivers/mtd/maps/gpio-addr-flash.c b/drivers/mtd/maps/gpio-addr-flash.c index 6de16e81994c..84404dcc7824 100644 --- a/drivers/mtd/maps/gpio-addr-flash.c +++ b/drivers/mtd/maps/gpio-addr-flash.c @@ -213,7 +213,7 @@ static int gpio_flash_probe(struct platform_device *pdev) return -EINVAL; arr_size = sizeof(int) * gpios->end; - state = kzalloc(sizeof(*state) + arr_size, GFP_KERNEL); + state = devm_kzalloc(&pdev->dev, sizeof(*state) + arr_size, GFP_KERNEL); if (!state) return -ENOMEM; @@ -234,9 +234,9 @@ static int gpio_flash_probe(struct platform_device *pdev) state->map.copy_to = gf_copy_to; state->map.bankwidth = pdata->width; state->map.size = state->win_size * (1 << state->gpio_count); - state->map.virt = ioremap_nocache(memory->start, state->win_size); - if (!state->map.virt) - return -ENOMEM; + state->map.virt = devm_ioremap_resource(&pdev->dev, memory); + if (IS_ERR(state->map.virt)) + return PTR_ERR(state->map.virt); state->map.phys = NO_XIP; state->map.map_priv_1 = (unsigned long)state; @@ -245,12 +245,10 @@ static int gpio_flash_probe(struct platform_device *pdev) i = 0; do { - if (gpio_request(state->gpio_addrs[i], DRIVER_NAME)) { + if (devm_gpio_request(&pdev->dev, state->gpio_addrs[i], + DRIVER_NAME)) { dev_err(&pdev->dev, "failed to request gpio %d\n", state->gpio_addrs[i]); - while (i--) - gpio_free(state->gpio_addrs[i]); - kfree(state); return -EBUSY; } gpio_direction_output(state->gpio_addrs[i], 0); @@ -259,12 +257,8 @@ static int gpio_flash_probe(struct platform_device *pdev) dev_notice(&pdev->dev, "probing %d-bit flash bus\n", state->map.bankwidth * 8); state->mtd = do_map_probe(memory->name, &state->map); - if (!state->mtd) { - for (i = 0; i < state->gpio_count; ++i) - gpio_free(state->gpio_addrs[i]); - kfree(state); + if (!state->mtd) return -ENXIO; - } state->mtd->dev.parent = &pdev->dev; mtd_device_parse_register(state->mtd, part_probe_types, NULL, @@ -276,13 +270,9 @@ static int gpio_flash_probe(struct platform_device *pdev) static int gpio_flash_remove(struct platform_device *pdev) { struct async_state *state = platform_get_drvdata(pdev); - size_t i = 0; - do { - gpio_free(state->gpio_addrs[i]); - } while (++i < state->gpio_count); + mtd_device_unregister(state->mtd); map_destroy(state->mtd); - kfree(state); return 0; } -- 2.19.0