Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp3893657imm; Wed, 5 Sep 2018 07:38:41 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaKNa2I9cD7zynJEfxEySGTPQNOVW+42E6IbbDBoWGsZdCbLFyDL+xA/zEePNTdPtX37dQv X-Received: by 2002:a62:4704:: with SMTP id u4-v6mr41432789pfa.76.1536158321106; Wed, 05 Sep 2018 07:38:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536158321; cv=none; d=google.com; s=arc-20160816; b=B+YwcMMoKwT/m8xDLXGe9R0Qfzc84duFhxjzyksBgj6n7aqecCsMAlYXvt9JWRzeWH n9YBQDl78bZ4ei+OVIxXZ2KnWFilD698NZnM7r7im1Nqi1wJ56eF+lz+aLouZnE4ceVI wKT3ucq+/9iSM8IHOvnSf83TSYX2uD2fEpxvSWgwVYNHafE0GObEFgu1LedN9z3zKL9V 4L4gP0RUIBWNlchw6Z0JcOxZ43lG4pz2YT7WJu7blkLLKdNFIyeiMpL2SSSeZTzoLlL9 oLLKLKrDrazXtEReEYggL1cM4H8yqsvgWAXCHrZsssU9P8NesWuilOcQf5xyb0WwyMNb u8oQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=6KQbJ/ehvzhLslRbh5pUWhc24N5jVaSmzwXXeaMc0Zo=; b=DnviBklZ/QINhAng4zT1OqfdBIMCuRhPWK/8MepzAD49h2OkXEeZc6gvMM22JOC+EU L/LqwOIaU8J0AQZ6R+lVmAlmsmyD02Ujigy41+/zG//2vPqOVAnaG5sTEfNWjuLagMhO NNDyCgGcg+g97toK08gE2WIiDxn/UwO9+HL1ZddX2P4Mnrk5FR6XGwqfWt4ImXIipyb1 vc2yEq5ITGvEM7Bxsi1IalvFMzm8d3VbvpYamQrGqIUTKrWJqTwEPmHhbDdS/LWkZSPl NLhUvR0BexkUGhf0ppHgzsPA5m8i3jjv4dDeTDrdIy5kzRD15Y+NlBvvbllalVpjVXUV fYZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=FG9cVbRm; 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 h1-v6si2054969pld.152.2018.09.05.07.38.25; Wed, 05 Sep 2018 07:38:41 -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=FG9cVbRm; 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 S1727781AbeIETH0 (ORCPT + 99 others); Wed, 5 Sep 2018 15:07:26 -0400 Received: from mail-ed1-f65.google.com ([209.85.208.65]:33507 "EHLO mail-ed1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726366AbeIETH0 (ORCPT ); Wed, 5 Sep 2018 15:07:26 -0400 Received: by mail-ed1-f65.google.com with SMTP id d8-v6so6302538edv.0 for ; Wed, 05 Sep 2018 07:36:57 -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; bh=6KQbJ/ehvzhLslRbh5pUWhc24N5jVaSmzwXXeaMc0Zo=; b=FG9cVbRmQGuNVU960LtLOeeUXIzZ31PxXbqhAfYgsXZ8FUnzB/1o5O6z2X7Bvr6PtY V/99EMnnfMFWo85D0HWFM5JIEbN9UXQQ2FWMK1F+CHaXKOryWlyihhYwNcwuo4UJuABU qsoT5e5sS4sMjgwbFI7Ol5W01LIAYNClFBbd9ig8mxJHfCKZXAwc2I1vdGbLBkVnCJrb xtBWgomYYPP/ZLLrgUmN7eFrN9LfC+j0X+VdrDBkChZP3E0jYDN+fFuKYqLybArXAj20 +7QO43nGcGZLKSoe/0wvAvJhC5j48LNfBaNXf33zYAYXksHE+cPqji4i7FLoJDVa9MdU jYew== 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; bh=6KQbJ/ehvzhLslRbh5pUWhc24N5jVaSmzwXXeaMc0Zo=; b=cGh0P6BjUvmoW21HAFn9InYeAA04lVFTW1FNejFOn6K+PbuyZiYzcg+TUqfztyHVhJ V05UeKGOEUOcu8PEZbyN0NyvTaP5u04flk71KVnRgeFm3HU7xA8VqvXjlqakMkcn8BXS 7M11cYYPxtrs+0Q+u6LAgW5uIcdUhv9EExYKumZBax8pvLpiYE9rVob6Tv+0V42L/mUK Z5T9jnKWff0R8b7ywwDSV0Rb9EF+OyCNwtblWOM5tn9h4Vek2rl/JL42dEtUQknnC4OP sjNq9DoffanUWGjfaecx+YsNDxbE2paDXJxoWAuhl64JZvg4zrkRUnpFkg4IZ3rZpwSr Ef0A== X-Gm-Message-State: APzg51DMbAVI5+z/VVbihmHF/+Wi662OAVTi+jR1kEU2ECuvZx3k2eiw De9hHvmYtOop8k86O1+MRmw= X-Received: by 2002:a50:c201:: with SMTP id n1-v6mr42670279edf.11.1536158216658; Wed, 05 Sep 2018 07:36:56 -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 u53-v6sm1556413edm.51.2018.09.05.07.36.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Sep 2018 07:36:55 -0700 (PDT) From: Ricardo Ribalda Delgado To: David Woodhouse , Brian Norris , Boris Brezillon , Marek Vasut , Richard Weinberger , Zhouyang Jia , linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org (open list) Cc: Ricardo Ribalda Delgado Subject: [PATCH v2 3/8] mtd: maps: gpio-addr-flash: Use devm_* functions Date: Wed, 5 Sep 2018 16:36:38 +0200 Message-Id: <20180905143643.9871-4-ricardo.ribalda@gmail.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180905143643.9871-1-ricardo.ribalda@gmail.com> References: <20180905143643.9871-1-ricardo.ribalda@gmail.com> 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 | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/drivers/mtd/maps/gpio-addr-flash.c b/drivers/mtd/maps/gpio-addr-flash.c index 6de16e81994c..54a0d7d2365a 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,11 @@ 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)) { + dev_err(&pdev->dev, "failed to map memory\n"); + return PTR_ERR(state->map.virt); + } state->map.phys = NO_XIP; state->map.map_priv_1 = (unsigned long)state; @@ -245,12 +247,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 +259,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 +272,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.18.0