Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp5179759imm; Tue, 21 Aug 2018 07:33:25 -0700 (PDT) X-Google-Smtp-Source: AA+uWPyACzxX6AzYtJbaQIEINsGhS3YucXt44+4qSw1wqR2bqqUioHfjB3sMCz7FVfroJTb8HZNE X-Received: by 2002:a17:902:d710:: with SMTP id w16-v6mr50043775ply.93.1534862005070; Tue, 21 Aug 2018 07:33:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534862005; cv=none; d=google.com; s=arc-20160816; b=jr7VPdmOssnVOYHWe1134FXj0wQrumSgycOu0rjE7TtNDzyg4grLFRod83XUCPS9us XiF2ZzzsRX65rYzDAyTb9dApr6TV3cDI6wDuXvlor/BT7eBq38RIsUKSvX537Bp6GOMk duablMLIh/chJaigvhkYq7oheD0kYeqLnz726Ii2xjbWgc2aVp1I6KdN6O3bh3C2KzVx trm6NfiNUkMDQ8edaqGUCHs+78uS9ee27OA4R+HchYvoboHMZqIj31tpI3v3+QQ8tqKb igRqqkI840BGu1vF69SuwSNfXvJubkbQgHXXvF4xUNmwY2tJYOY7S6GLRHJrLaWPeIhp EUdA== 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:arc-authentication-results; bh=6KQbJ/ehvzhLslRbh5pUWhc24N5jVaSmzwXXeaMc0Zo=; b=uJKWkTOHlb/Q3g7keSoPVNVO6k/nrVfJ5fsCZC6BLOo7PqUXOn/rnvh6o2W48f7QeN /a8w9rRiNtTkpFFKdNsyfZkZIOH+euIwX3dq6p1zOVP2vCSzpV15acRAYUydyV1frG38 Jr7LleUCmPKmsieHQ9qEm6kD3eAG0ev2F+QB1IuQxjUMnzB5wHoAmmiPf00O5gOiOnv9 j/j15Q7KNQFISN5BBBymukrrd/uq1++204GHZudfdgo/kzwEIqAaladIMyIG9snG6p3j JhTAYjne+bSvfcaiJ7zY5xc2DeK89CyYjnH4CXp5TUIhwlj6d1RCZYST8BcAzwMR7/xT /+Dg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ZSUHNlxT; 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 w12-v6si12359867pld.362.2018.08.21.07.33.08; Tue, 21 Aug 2018 07:33:25 -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=ZSUHNlxT; 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 S1727537AbeHURw0 (ORCPT + 99 others); Tue, 21 Aug 2018 13:52:26 -0400 Received: from mail-ed1-f65.google.com ([209.85.208.65]:38597 "EHLO mail-ed1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727238AbeHURwZ (ORCPT ); Tue, 21 Aug 2018 13:52:25 -0400 Received: by mail-ed1-f65.google.com with SMTP id q15-v6so1221877eds.5 for ; Tue, 21 Aug 2018 07:32:01 -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=ZSUHNlxT2LqvIN/gOnN9RFwtXBiJKKJRVwhdOai3RqGPAAwnoa08zMSgN4KdJabT1z qEcPEsqs1fym+8U8e/TX2MW3tM9LHa9qZ2cmP/w6OVpN4BlauqlksnI5/aHleJN4Ny5g qtQlXbIF+qB35wDkFHZwP+5gUdUH3uncoVLWDewlHtNC2vhdP32NJbJBR4mu9Hh6lxQe CPXjvfnO6xdlLiAhtCulICqJ6NhqVXaMPaK4eE0V01kRHNGatGtsXHxYl6uLJkhO2SM2 t26FwmiF3TzZlz54nry5+uu51OmLZ72Q40HFXPRWz8fggGowUrOj2v+UkE1lX8KyIWzc P5NQ== 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=kHfZHrXYkHwYPugi2Rd9tiyLkiLZX3Dt7MGti1bye3rX5dD4c6HkJza0HTzssjuo8j CFE9amWrkR0U70ocbySOjcTmWRk9hFr044D+Mea8H9QTFxd96lwraelF3LoHJlRgZLHf WL+7ZSJJk3LlO/9iUxr00a+EicOY4fDkH5dbPj1nlJSjocLstkVQ0V2HDLE0WGI8S0ec GuOKDEAX+7uqOTc1BhwYGhu7MnpwijKTel/lukq62klwxWxXZcE3O5e/qEpbSWGgWMa5 d+8Tck/+BKhH8aRhLFZ+rS3O8/M3f+QOnhpig5dGVBAVMswM5uZ5qsA5eZUykGoNERnh ZHvQ== X-Gm-Message-State: AOUpUlFjM7klvdL/XPkUnat0xhtwA8+0Ipd7FWqRSR+9Ct8o5qN8JE1f 7aqXqteWJMwZssziumYULdtsfaw5 X-Received: by 2002:aa7:d2cd:: with SMTP id k13-v6mr61720111edr.311.1534861920560; Tue, 21 Aug 2018 07:32:00 -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 n17-v6sm6766144edq.10.2018.08.21.07.31.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 Aug 2018 07:31:59 -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 Cc: Ricardo Ribalda Delgado Subject: [PATCH 3/8] mtd: maps: gpio-addr-flash: Use devm_* functions Date: Tue, 21 Aug 2018 16:31:47 +0200 Message-Id: <20180821143152.32293-4-ricardo.ribalda@gmail.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180821143152.32293-1-ricardo.ribalda@gmail.com> References: <20180821143152.32293-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