Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp944360imm; Thu, 4 Oct 2018 06:02:03 -0700 (PDT) X-Google-Smtp-Source: ACcGV63SjC2b/g+5kkaFPY59IGmvq+v2NpNjyAChRSwTavFOLbeIZgeOoQuTw/JlOxh14mkjQiHl X-Received: by 2002:a65:6249:: with SMTP id q9-v6mr5593832pgv.392.1538658123894; Thu, 04 Oct 2018 06:02:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538658123; cv=none; d=google.com; s=arc-20160816; b=KweUzgkKE+4el8MQGRZ7ZYmLoyw/geOvPqtsG5blfav6fl0UsVONARPGxgQsvg8zGF /CJWJxi05iysgFuszZXAF1BTQMJJLH3FhdbbSNWeXXmJb2jFrqm0Cbwa4qVevELMVV3g ciErG4ouMFEQBPIXqICflOtRCsYFhvs4JwbUfwsZ2zYirSaygsIzrz6SGL2XmXIkrdQy hsI241UNsldkJTskoO6bBimMgOFtjJ+5be2zHITlJB2nPh1SZB5o1EAEJjN6f3aZijka SghGMK0bQ/A1wijVFQfbCdHgqvBOYyy+yuUdgD6jSVuWT1Ga15UBXc6GmgD8HYZIPNBD BLxQ== 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=H6vZgwaQDNsB6NWcy0fRoJEaUPjlf8uumt8LyhcEvgxygHqIa/IQ+Y1ePXv8VJl4qL bVouj3wfz5s8Aqlc5R9Rddyyv0ph2Fvn4LQx6Z8zf7sd+88D9wxowFjQ7VXUnVt0rnSw 2Bur+TigTWD6+Z634D1uk8lDWfL+h2Sa5SAmOkPEEIRJmUCiJUUKN8uQ7Z04wmLe9GFj DeMUiq+IxJiQiE4gYV7La3zT4GGREk1XLxDl9zA0hLdnSyRa+UaIVI2BhOBVyUK3Ncud Dop8xRgSFgGx2hOQHq9wO7reSFvgaoGmP+e581ZxI8i/2+EZrwVJlAXLTVeE6t0VBsVi Dabg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=TzK6udkx; 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 y9-v6si4767459pfn.128.2018.10.04.06.01.48; Thu, 04 Oct 2018 06:02:03 -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=TzK6udkx; 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 S1727634AbeJDTyp (ORCPT + 99 others); Thu, 4 Oct 2018 15:54:45 -0400 Received: from mail-lf1-f68.google.com ([209.85.167.68]:39232 "EHLO mail-lf1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727264AbeJDTyn (ORCPT ); Thu, 4 Oct 2018 15:54:43 -0400 Received: by mail-lf1-f68.google.com with SMTP id w21-v6so6707556lff.6 for ; Thu, 04 Oct 2018 06:01:31 -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=TzK6udkx40T+yB4Jkdo3zG+dO3MlND4TaMmjCwny6HA9wgto/bQwMu7PEj/az/SB0Y cPV0NWqbGj37xNVZSpgpxPkKtoWihf2BP6Ds1ZZGD9xH91Z7KeRR+J1JUlvNim6qyr8f uIF79i81cN+917iD+EIthwt0dqJd70JVVaF4hKpxZaSqxSYvvlRG7TovePFISdJWPn1z Vj1NonbiUNPvzFssshuDlhcaovLZkcMDlCnbAiNcTVcIS/zf8OmmcHSgQjJ9jJaI1q0O ooWl6rv9BFyWrv+FeiPBVXnWMzFeh2PcyBYcSfdzfNyAj8V8l3vxqvjPRuabE+4apQUB t5+A== 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=tXfD637XCL8pIjMtfebRJNnOrOTYMmCYBhlrzP2IX8nkXYcjzRFC6gJPrnRlTpkDDE EIwSGmYRe+j0blBWp8Lwj7K/JyJMzvVIYvUaURWVKgm30fcdtSfKsMEbLfTuyzkDN2Uf b6Tmn1ToqFw+JHRjThVXmj7abhC9rv6zGwfoPjFx6KqEFEsTaquVBnMVMqB25uLv0yol DU9BmAfXHX1fdbfP96xI7KnjmEmKIONEt/cj6/QICzUjTo161Udc7ahLoXVwVMK736Z+ bhmsPJR73tAw5fP2CS0IdK/GzxADI6QWU82SxX5da0ndcNc9w2r2iAu27Iq0gC90E7Ja bJOA== X-Gm-Message-State: ABuFfohPI38zW3ktiGfV3uTuZMPu25TueJsQGiAaKbHKGViTpy7dwuRA sXbfLFGsSiQ/K8gjykGKbZ3zVdTg X-Received: by 2002:a19:a686:: with SMTP id p128-v6mr3742306lfe.42.1538658090417; Thu, 04 Oct 2018 06:01:30 -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 a1-v6sm421415lfk.63.2018.10.04.06.01.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 04 Oct 2018 06:01:28 -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 v6 05/10] mtd: maps: gpio-addr-flash: Use devm_* functions Date: Thu, 4 Oct 2018 15:01:05 +0200 Message-Id: <20181004130110.8496-5-ricardo.ribalda@gmail.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181004130110.8496-1-ricardo.ribalda@gmail.com> References: <20181004130110.8496-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