Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp500073pxu; Thu, 3 Dec 2020 05:54:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJyYenOI94kx3oUIhL1dXe4f+YZUpREEQsGJGBUdm/rU8QEMhZrgsCTpwadjMLkiipkJd2nE X-Received: by 2002:a50:9eae:: with SMTP id a43mr2867133edf.109.1607003668774; Thu, 03 Dec 2020 05:54:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607003668; cv=none; d=google.com; s=arc-20160816; b=hn3CyC4GfRji6jQ5sGuN68WUioKvaTLPvt3yUrola/8cE5LpfudrVc1lJ9jPcQL/Q7 1N2tJW8JmMHOPfze1IFs07aL0GKle/KSmtmHo7QrKyRQvl/JaJO7BbJa4uwAJG9iyQRY /VkqpmG+/nfhi4nh9M8rcORSDh3DhljsD+7HDmaOeFgamvT+Z1tBDeiL5i9WttDO3FqW DXQGBxde4tgWIC8G+DJkJJ6P1+gKplCLiMG3RrbfLJalkkgQFrYU3ZlHLpt7CjS7TJnC c0H85n2JV5xmL3vp5p/PQ3a1FX0ObY7q375FbPDXUPtfieKBh14b/Nks5yEZpuqo2RsR b8xQ== 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=iHIA6yYVAP3n8QA7ri6Rsp3nOokKfUWij2o+jnWGjkQcEQEoFfMu9MFqlvIv6wyRb6 0AfpcwdPlECMjkifBOK72dAiTDR1BuMnoJUq7KQshMvh2C5wddsiUZI10YdptM7ujoVj peAI2x0YGWSXyBUt8fwJGAmTtW9jKtV0B82hutYucqLWnV3AF4yYNY8paaoIFlPurifj jnMj0opbhvHOdmdm2+KZA1eEtxDfGNj5rDZJfwWFbbD7q+YzJKFhXtgs6QW3h4beIu33 yKAw1/cqK1JeY0hat2iO/hvWQb2dLU5cp6CdeDE+i6A8eaKRXLsiIw/w+gJN+Nl1jpHk rutQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@essensium.com header.s=google header.b="Y8z/8EuF"; 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 p15si996663edx.69.2020.12.03.05.54.05; Thu, 03 Dec 2020 05:54:28 -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="Y8z/8EuF"; 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 S1730594AbgLCNvy (ORCPT + 99 others); Thu, 3 Dec 2020 08:51:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730556AbgLCNvy (ORCPT ); Thu, 3 Dec 2020 08:51:54 -0500 Received: from mail-ed1-x544.google.com (mail-ed1-x544.google.com [IPv6:2a00:1450:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2501DC061A55 for ; Thu, 3 Dec 2020 05:50:55 -0800 (PST) Received: by mail-ed1-x544.google.com with SMTP id ck29so2138527edb.8 for ; Thu, 03 Dec 2020 05:50:55 -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=Y8z/8EuFA6ejo6uNXN3hvgjf2bBiWOtpkVqtVbJc39AD0hDdwCfH7jMRp0Fqviek6h vzoeCESVCdFOLPy01jeD5p3DY2c7O7hvTDdciTZNvNTLnu+Z296xanf6RLanEfDF8a/0 Y2xXyJPGoOsQHcUYyvelkmMu5Xnsyott645gcYSbEILzmnOxCYQclATF4tm4k8LPgpLE Dfuo5mjL9/dN7rNxpUuURAUIKJYARMYl8XJEQu681tZ2PlKQCof4/AcC7n7xUjMW88nW Mc9bL/oaRgFotODx9ppFbGNV/34SIE87WOGwAluESGyCfL0kD7hUYCseosyvp/V6J7LK WoSw== 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=ZlWAhkVAjwUmV3esWfxE0wLkrnyFpicY7NmBOtTWpo03WzmXdxpZeq5gr4zvCPHqBx ybk9Rf/ri1NkRWZmEtJe7PeboqpBB8qWOJePIh6c8HUW1GHhinWb3uXnetibJ+QX8dtz PHPwLJwZ+aDqzANBjQat62wSsUjabSypgySrJNDgIQqelxFzKRq8iK7iuvvDA0UHTBh5 AkoNA6iIkHTcHxe0E5Ri/cxmwXMmBSlWgir/Ok+8eauqCbMxby/iR3AjT4b+r/Fn3l/p ei9EHeELp9xBiyKG03wYnG+JRzy8YzmzbExW6AMhSd6FImr+Pl+zYSMZme2OU2nKwSHY 21UA== X-Gm-Message-State: AOAM531m5s12X7aagReTtwoUdKyeuk0nVegojaW9sXoEtJJNTpno0cOU ecURNqgteTP0bup+3LzCVwVAZGVfNC0Fng== X-Received: by 2002:a05:6402:17ad:: with SMTP id j13mr2937991edy.347.1607003453896; Thu, 03 Dec 2020 05:50:53 -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 t19sm903192eje.86.2020.12.03.05.50.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2020 05:50:53 -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 net 2/4] net: freescale/fman-port: remove direct use of __devm_request_region Date: Thu, 3 Dec 2020 14:50:37 +0100 Message-Id: <20201203135039.31474-3-patrick.havelange@essensium.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201203135039.31474-1-patrick.havelange@essensium.com> References: <20201203135039.31474-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