Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp980884imm; Thu, 4 Oct 2018 06:32:15 -0700 (PDT) X-Google-Smtp-Source: ACcGV61xZYI5PBMUNPg54DkQCL2Vh641/ajk4kmgHe2pV9hvobsWJo10JlkvMzsmWqmDITU10RqI X-Received: by 2002:a63:cd45:: with SMTP id a5-v6mr5864788pgj.43.1538659935716; Thu, 04 Oct 2018 06:32:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538659935; cv=none; d=google.com; s=arc-20160816; b=M3R7K7h29CyH1c/cRYZnxN6rk0FnUgeeZ/941AQUgveLaNfjB3VAtDYNLBp7knWSk7 FjkmL3vDZx1GywuyOUstAVDMOvLjqqhNYMXf8WZ+3htFPhBKKqYk8vuMMrBCltGIZN5I dx0moyoNMl1OXeTvPUxbIdRQom2rtmPmOWfubJBMLpwn3FnHwzyTNLDG5TnuR128pPKX NLJhej85jf8PA9tdjNvCF0L6In3Aob5+xycQE9Ohvs4jEWHjx+hJi5bRfeMuWRfo/F6a 6Z1v3JLFbUeMOMwhPjR+b5noMS8emhv7gQHRtxlfXvo86LTEpQclSGvoTkTudQ1OcSre kpXQ== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=raX5qEj7fRXQ/iQULa01jf7rlvPVsAVNG0zX/XpZs5g=; b=np59unP0M44GwF3MFA8H4g1udUSwWU/R3lk+rwNeimps1tlhyOMAsTdqIUHTzEyZE0 6PMVMmwHbDbyGHPEnpofYQnExQP2IvGxlLlEbeJaCpw9IMnwUTO6hFqDf591KYaTLcqQ 9gnQwA09xtEC7RXcLoPRQXrxozu1YX+5b9snzxa+cYFRmzgt2YWx7Uq2WLu792K8mxOU Qg86pHbfJ5oIRdjxaUZVkXPT6OdrH4lK+NRFsISmRKDFh/DtHqfPfjWLVpGudmGxfz4o +fISms71lwo5Wu5gZ70Km9jX8DHwq9nk0nvPjMY+sgCjiXqR8CR47jgr+In/aKLn71TC 2Mlw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Bs1dYuEw; 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 k5-v6si4176701pgq.413.2018.10.04.06.31.59; Thu, 04 Oct 2018 06:32:15 -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=Bs1dYuEw; 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 S1727580AbeJDUZK (ORCPT + 99 others); Thu, 4 Oct 2018 16:25:10 -0400 Received: from mail-ed1-f68.google.com ([209.85.208.68]:40316 "EHLO mail-ed1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727415AbeJDUZK (ORCPT ); Thu, 4 Oct 2018 16:25:10 -0400 Received: by mail-ed1-f68.google.com with SMTP id j62-v6so8563441edd.7 for ; Thu, 04 Oct 2018 06:31:50 -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:mime-version :content-transfer-encoding; bh=raX5qEj7fRXQ/iQULa01jf7rlvPVsAVNG0zX/XpZs5g=; b=Bs1dYuEw88RWdvlU/QKrnpxanvvHnNSDQFMCUNnhGfgzRk38FPRYfrPXesa9G65Oje fwRe9wYuwkFuMHMbDQVywWy0puErljO1BsdC14RW/NNTvwxWb8BfhHufi/Mu1zGHoLYQ XshtXDFHCNh6FQG9vZr3wBdxltd7ojT5Unb5R+5qLKhZgvqIsFpGjlwdYbC2Eum7HiIH 8aXlt8Ar4pCksyzMcwMdxcBJw5zGPfWZuLsjLjKqhniXvfjB6uU2uOECG84l4wNSln0I lw/LGF0zTqdtpiC3FODvL+vXK4M03SA7WeNws9RfG/dbLQZ+f4+YXFBCEqvhAkU3mhjQ pOqg== 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:mime-version :content-transfer-encoding; bh=raX5qEj7fRXQ/iQULa01jf7rlvPVsAVNG0zX/XpZs5g=; b=E6tXi+524PA4+HMiQUu3zEZyo9smcPKCg4AycztOd046Oe9s5Xjbn3xvk79iz1T00Y b2dbPS2uuTF2tUz0xwOohFbA3FQVLunLUC+vKbFkW0znGxE3ylfd6omZiesdb+/OGtG+ WsT/i2aTfAJxzpzRzVnwT8tGbi8UcThCt6Qove+4MDdxo6uFnO+wVe3X8GWO/0sS/Kp3 kHjSeGMdb07amyERQrYOvpgEkJYfPvqJQf5zmdQ83fTAUBd6wkWg2ijgGZKU0Imjm2aZ OIcCOUO6YI/wA6NOmNKwdEXj9pyC77TrvAqeloloxOBqqz5rBvrR20W5FYkTBoNj1ira jNhA== X-Gm-Message-State: ABuFfohwfo16nodF2PFDB9Kpt4IBjpv9I5KDHlM8EUzrZauvVc/+gT4Q ptg5qDsB/E8M+ALSuPHSAWc= X-Received: by 2002:a50:8a96:: with SMTP id j22-v6mr8461277edj.189.1538659910169; Thu, 04 Oct 2018 06:31:50 -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 c24-v6sm1440569ede.73.2018.10.04.06.31.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 04 Oct 2018 06:31:49 -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 v8 01/10] mtd: physmap_of: Release resources on error Date: Thu, 4 Oct 2018 15:31:46 +0200 Message-Id: <20181004133147.20215-1-ricardo.ribalda@gmail.com> X-Mailer: git-send-email 2.19.0 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 During probe, if there was an error the memory region and the memory map were not properly released.This can lead a system unusable if deferred probe is in use. Replace mem_request and map with devm_ioremap_resource Signed-off-by: Ricardo Ribalda Delgado --- drivers/mtd/maps/physmap_of_core.c | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/drivers/mtd/maps/physmap_of_core.c b/drivers/mtd/maps/physmap_of_core.c index 4129535b8e46..ed75f1781c37 100644 --- a/drivers/mtd/maps/physmap_of_core.c +++ b/drivers/mtd/maps/physmap_of_core.c @@ -31,7 +31,6 @@ struct of_flash_list { struct mtd_info *mtd; struct map_info map; - struct resource *res; }; struct of_flash { @@ -56,18 +55,10 @@ static int of_flash_remove(struct platform_device *dev) mtd_concat_destroy(info->cmtd); } - for (i = 0; i < info->list_size; i++) { + for (i = 0; i < info->list_size; i++) if (info->list[i].mtd) map_destroy(info->list[i].mtd); - if (info->list[i].map.virt) - iounmap(info->list[i].map.virt); - - if (info->list[i].res) { - release_resource(info->list[i].res); - kfree(info->list[i].res); - } - } return 0; } @@ -215,10 +206,11 @@ static int of_flash_probe(struct platform_device *dev) err = -EBUSY; res_size = resource_size(&res); - info->list[i].res = request_mem_region(res.start, res_size, - dev_name(&dev->dev)); - if (!info->list[i].res) + info->list[i].map.virt = devm_ioremap_resource(&dev->dev, &res); + if (IS_ERR(info->list[i].map.virt)){ + err = PTR_ERR(info->list[i].map.virt); goto err_out; + } err = -ENXIO; width = of_get_property(dp, "bank-width", NULL); @@ -246,15 +238,6 @@ static int of_flash_probe(struct platform_device *dev) if (err) goto err_out; - err = -ENOMEM; - info->list[i].map.virt = ioremap(info->list[i].map.phys, - info->list[i].map.size); - if (!info->list[i].map.virt) { - dev_err(&dev->dev, "Failed to ioremap() flash" - " region\n"); - goto err_out; - } - simple_map_init(&info->list[i].map); /* -- 2.19.0