Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp989833pxu; Wed, 2 Dec 2020 08:20:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJy/vASc/m7NJtdYttmUr1f02GdwWSDmaSnlhuxkd9jxDRNk93cFI6EDBqzrFYS5FBvxWNs/ X-Received: by 2002:a17:906:c244:: with SMTP id bl4mr501251ejb.430.1606926011160; Wed, 02 Dec 2020 08:20:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606926011; cv=none; d=google.com; s=arc-20160816; b=0tyDc/pZ7L4UZHJEOuXmcJ1nVBz4nal56GS2DH+1k/mK2XoF4ETeRMxv5YrRa/MiEC XLE8/hii0zlykHfdVO57tYTGCYmYnOu6X31zdlNC7ukuWTJz+f6iagUuAlYWxbhOSNyQ wx1nGpRMS/Dlqkf/81llQhvZT/WLdvzuDj2WMdr05pA33jiNsong9ZTV8EdfHPHzA3xk DLKKb7juhcBP9OWCBS8YTzRAXtWKkztIoJhAcMAgylX34v1/QBdRwQZcwMWzsxpqZ09F qn/RB/U30+TEEtrHd9ikrdjLjyCJzf+wGXz5QdSvKoUxoUcwd6at92Z6/2BJGszGXaMQ qr8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=32wijpVRZam48n6WcEbTQm6X2gRK0yzC2hG6Y0Y2+Lk=; b=bTTDJI1GQD6vJBTmO/wpT355XrzfGBEmn8J5FpgXP/jE4MFlYLthmRsUmArYYWndXq JnvVJgDaQsw5HhluUudz9P/h6KotTD7KAkqzfPMJ9B2/fPie8gsMGR2wQWLIoyVMQIIQ 1l4wk+bslpeCjMiCS2TaVkp9NtDwB+1dAvWmVUzs3cPrly0hRxUEdkj6RaPEr1ZohuVj GEqyyZ8+x0dU1UTChrpwzP8/yVpL/mtrctnzUmPUlZ589Je5KyJO+LSEvU1p2qTuaBTL kdK8nx/95WA/duxjmCflcPEGDUMl3UdGpMZxNWL2yCR7IYrd8E/Qoe1O/c7epc24hWJK geoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@essensium.com header.s=google header.b=PlyX+bAb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=essensium.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n6si233217ejc.567.2020.12.02.08.19.47; Wed, 02 Dec 2020 08:20:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@essensium.com header.s=google header.b=PlyX+bAb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=essensium.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389051AbgLBQQ7 (ORCPT + 99 others); Wed, 2 Dec 2020 11:16:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59230 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387401AbgLBQQ7 (ORCPT ); Wed, 2 Dec 2020 11:16:59 -0500 Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC36DC0617A7 for ; Wed, 2 Dec 2020 08:16:18 -0800 (PST) Received: by mail-wr1-x444.google.com with SMTP id s8so4591881wrw.10 for ; Wed, 02 Dec 2020 08:16:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=essensium.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=32wijpVRZam48n6WcEbTQm6X2gRK0yzC2hG6Y0Y2+Lk=; b=PlyX+bAbaCJ+ViZ3xFGoPUhiuB+2K2BHJQpYjSn9xuCgAlXPdGx9ck4kZMLiKNqYPw 4YOSSXkVExGyKM71Um3KGpNbXs0B7shbuN5VRCT349Vd89LzeWx78sobdQxuea2b3LDY lIO2LXf0l1cgInR6lZnW/HDihBMsku+m/dB+0DLs3Lo1Nn5cyCkOVOs4cOo7zWiAfYYm J+tArr0vo9cKRrLuI+5D/rEA7Q7rPFtx+ENisJL+tn0YEit3M+xHE8NXY9VVkzWDbMbP O3ZjN7YhhUX9o2b04DH+eiMt6fix3aRcHgtU7miug3d1EF/lCG8mc5YDQZF2V3ufGBS1 aXLw== 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=32wijpVRZam48n6WcEbTQm6X2gRK0yzC2hG6Y0Y2+Lk=; b=C6c+TbBelBVIzmesQMXP70EHv36AMlI/JpYOzS+ITQlXsnKQoGY+s5BTjGPI4eEagA VDABKneAU9amrDnAVj6+skXYnxP91q8GqSgccIPkRXjz9KXL6iewsFlMEymF/ITWlicp rNnYiB3EyDXA96f74p5sOM1hQhbSoFaOxX4up1PXP2xBPq9dRiaPnzT2rATmgd4vADoB HuJghSzMsFN0lVS65mEF7KfOYSW9Eg0etcCI2EPgx+WduiCjapD6Mx90zx/Mhx8IegCF XbSQ/rs5EHzzO5/DA5Keh11zbYEMLb2EdRfhvMYQFFh8FPWcpmWbPN43LzyN45TIGGkp +36A== X-Gm-Message-State: AOAM533/0MO8Upo24ZUwyjUcJ+GsYgOPs4AB8ss6R4Vop8aj5eCTiVdu iutCo5yUmJN0nZN7EVYu789PVA== X-Received: by 2002:adf:eb91:: with SMTP id t17mr4358566wrn.330.1606925777480; Wed, 02 Dec 2020 08:16:17 -0800 (PST) Received: from belels006.local.ess-mail.com (ip-188-118-3-185.reverse.destiny.be. [188.118.3.185]) by smtp.gmail.com with ESMTPSA id s4sm2644505wru.56.2020.12.02.08.16.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2020 08:16:16 -0800 (PST) From: Patrick Havelange To: Madalin Bucur , "David S. Miller" , Jakub Kicinski , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Patrick Havelange Subject: [PATCH 2/4] net: freescale/fman-port: remove direct use of __devm_request_region Date: Wed, 2 Dec 2020 17:15:58 +0100 Message-Id: <20201202161600.23738-2-patrick.havelange@essensium.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201202161600.23738-1-patrick.havelange@essensium.com> References: <20201202161600.23738-1-patrick.havelange@essensium.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This driver was directly calling __devm_request_region with a specific resource on the stack as parameter. This is invalid as __devm_request_region expects the given resource passed as parameter to live longer than the call itself, as the pointer to the resource will be stored inside the internal struct used by the devres management. In addition to this issue, a related bug has been found by kmemleak with this trace : unreferenced object 0xc0000001efc01880 (size 64): comm "swapper/0", pid 1, jiffies 4294669078 (age 3620.536s) hex dump (first 32 bytes): 00 00 00 0f fe 4a c0 00 00 00 00 0f fe 4a cf ff .....J.......J.. c0 00 00 00 00 ee 9d 98 00 00 00 00 80 00 02 00 ................ backtrace: [] .alloc_resource+0xb8/0xe0 [] .__request_region+0x70/0x1c4 [] .__devm_request_region+0x8c/0x138 [] .fman_port_probe+0x170/0x420 [] .platform_drv_probe+0x84/0x108 [] .driver_probe_device+0x2c4/0x394 [] .__driver_attach+0x124/0x128 [] .bus_for_each_dev+0xb4/0x110 [] .driver_attach+0x34/0x4c [] .bus_add_driver+0x264/0x2a4 [] .driver_register+0x94/0x160 [] .__platform_driver_register+0x60/0x7c [] .fman_port_load+0x28/0x64 [] .do_one_initcall+0xd4/0x1a8 [] .kernel_init_freeable+0x1bc/0x2a4 [] .kernel_init+0x24/0x138 Indeed, the new resource (created in __request_region) will be linked to the given resource living on the stack, which will end its lifetime after the function calling __devm_request_region has finished. Meaning the new resource allocated is no longer reachable. Now that the main fman driver is no longer reserving the region used by fman-port, this previous hack is no longer needed and we can use the regular call to devm_request_mem_region instead, solving those bugs at the same time. Signed-off-by: Patrick Havelange --- drivers/net/ethernet/freescale/fman/fman_port.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/freescale/fman/fman_port.c b/drivers/net/ethernet/freescale/fman/fman_port.c index d9baac0dbc7d..354974939d9d 100644 --- a/drivers/net/ethernet/freescale/fman/fman_port.c +++ b/drivers/net/ethernet/freescale/fman/fman_port.c @@ -1878,10 +1878,10 @@ static int fman_port_probe(struct platform_device *of_dev) of_node_put(port_node); - dev_res = __devm_request_region(port->dev, &res, res.start, - resource_size(&res), "fman-port"); + dev_res = devm_request_mem_region(port->dev, res.start, + resource_size(&res), "fman-port"); if (!dev_res) { - dev_err(port->dev, "%s: __devm_request_region() failed\n", + dev_err(port->dev, "%s: devm_request_mem_region() failed\n", __func__); err = -EINVAL; goto free_port; -- 2.17.1