Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp14380691pxu; Mon, 4 Jan 2021 23:12:45 -0800 (PST) X-Google-Smtp-Source: ABdhPJwIlA37eR9N67qutiXFEfNl0Rsv+LDFahi5LbscCZUDX1bzIqq3NbQ5eXtBWOfspSwxeGEg X-Received: by 2002:a17:906:cd06:: with SMTP id oz6mr70077809ejb.25.1609830765293; Mon, 04 Jan 2021 23:12:45 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1609830765; cv=pass; d=google.com; s=arc-20160816; b=vFtFvR05j2vSN/18vhpFZyg7SqIFguFM2I72uTPvgrXs3fG23ryucMQpZ8hIW3EK7v iDllDIZZA0NTqkpv7hX2oFct0nTyvtFxumlZiLmx9Xrekgpix2c60xUrEk/pJgBF3k1B a2eWukj32d2u1OT9rMBPDbXpPfKly++VNoBqW2MTqHCebAtAPcX/uyUZVtId2aL+bys7 LKss0aUyk238fJxsRrSEFdmcHGcahOq3CUcejdyxAnDwRx+THv24AzKJ3HbHilMqLP99 /dFHK2lDWG4iBqriZrISR6xjKRlwH7/C6hyM1ZL1F3ZlbAHkhcAUDgt4+B/YfZgZ+2rK i5nQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from :dkim-signature; bh=8uds2PUKq8slRfAPNIQ2H7UGBb9JdhOPhydlG3zSfWA=; b=wr3SvMceOuqq871r8v1DruVRR7bnGDddoHbMNZdz2zukbhr5uoBmDIsXcWX3hYy7nc or9Wn9rpjbvhJ5nR0cLAiuyYkZ0RkKRE2SYUERNWaQsgt64E2HQmni6kq9XtNqahTxzZ QKo7k+WmoVtaYkuYWXIdNTPtwPkDltJPSGlDnOXUKp+4g6A864wKASqyuzGGQQJhSue/ OBDI4+D1w4OUoHfV/0i8o3YilOv2cPgTfONMCuapKT53B0UgQWM+oaFYfMOXmqPVUePi QtjllxYiZZZ5R+UUDiaF0dbcdK1ZyeMGc3bWakBtmmE+nz4xdpM6j2GC6DgcXWs15ugJ oEMw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@windriversystems.onmicrosoft.com header.s=selector2-windriversystems-onmicrosoft-com header.b="e/st6aEP"; arc=pass (i=1 spf=pass spfdomain=windriver.com dkim=pass dkdomain=windriver.com dmarc=pass fromdomain=windriver.com); 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e15si32679204edr.313.2021.01.04.23.12.22; Mon, 04 Jan 2021 23:12:45 -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=@windriversystems.onmicrosoft.com header.s=selector2-windriversystems-onmicrosoft-com header.b="e/st6aEP"; arc=pass (i=1 spf=pass spfdomain=windriver.com dkim=pass dkdomain=windriver.com dmarc=pass fromdomain=windriver.com); 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725797AbhAEHKg (ORCPT + 99 others); Tue, 5 Jan 2021 02:10:36 -0500 Received: from mail-mw2nam10on2041.outbound.protection.outlook.com ([40.107.94.41]:38327 "EHLO NAM10-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725730AbhAEHKf (ORCPT ); Tue, 5 Jan 2021 02:10:35 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FkZs/ABd0CItIA/fEx1yx6VH+UrKIwkXHp4is9ucqeMp68KikEniwjLCph7B4lPXPrCa87u8i1TKEdoDo+7vlAUj/+yIpVsciL+FCo7XRDLD5tfWbKbAVr84bIXpMACpoG+YuaJrr9efjRQzgi7yatyRvGstR1v50Ua1QEPiR9o0lZnfYDi1DtAWzInt8RgwN5gE0KmvwaEDUvBQXCzOJTohuks1qQpIsqqqOQBeH+CB/kJ+wjeKSf91iIe8B9v1m4J1AE9O6nZQZRClqBiUamadKuDwExyJv43fqknty/cZ0AxxSWZ2ulm0sPu+a+3jP7ngZc/aFuXHK36/CgICMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=8uds2PUKq8slRfAPNIQ2H7UGBb9JdhOPhydlG3zSfWA=; b=XDe7txTVyI0ANGTTWe4JxH2hliLMXNTfQBPn8KNXW3qSUzcREnv3TlAi/hE6HZsPD+D9Smpi8IM5PtSvOUkTB5ybb7voBmFlShjT5MsnA87dTADf3YJGfs6Qjritx+zWDpeDdgUUn4vPRhilRCDQ9TJm8ofHjfmWboViJbQwbSlp7B6WhWY86s9hr43yQAADPn4D4rPzNv+omfarbJkfuf5F3ry2TXbxma/Zv5qBe502SCZIBHDfIzwErz7SPsLMKQ0t5p+2Lm/MY2mV9tMjSJAQZMikuO8dPJjhkpb/Sz5Ghp+JbinSh/j5sEjmecKJEoxghqrlCSBq/37f3evnng== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=windriver.com; dmarc=pass action=none header.from=windriver.com; dkim=pass header.d=windriver.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=windriversystems.onmicrosoft.com; s=selector2-windriversystems-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=8uds2PUKq8slRfAPNIQ2H7UGBb9JdhOPhydlG3zSfWA=; b=e/st6aEP7Wm1MtnkDj83t7SZdpoQp79zqv/gB9itjuMXFZsj04jc0A/5si/PjT+ImsN5fZx3wmjHpeiJp1qpqppENwhBUNJ7fMXPpYKT33hRgjMfcbdnS8EYLsaw748URaiX2kw1NoHDBAWYIqYZxuCQh24ahFQujHz9nRl29VU= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=windriver.com; Received: from SJ0PR11MB5072.namprd11.prod.outlook.com (2603:10b6:a03:2db::18) by BYAPR11MB3703.namprd11.prod.outlook.com (2603:10b6:a03:b2::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3721.20; Tue, 5 Jan 2021 07:09:48 +0000 Received: from SJ0PR11MB5072.namprd11.prod.outlook.com ([fe80::4934:bf21:e093:8c3e]) by SJ0PR11MB5072.namprd11.prod.outlook.com ([fe80::4934:bf21:e093:8c3e%6]) with mapi id 15.20.3721.024; Tue, 5 Jan 2021 07:09:48 +0000 From: Meng.Li@windriver.com To: linux-kernel@vger.kernel.org Cc: gregkh@linuxfoundation.org, rafael@kernel.org, james.quinlan@broadcom.com, Kexin.Hao@windriver.com, meng.li@windriver.com Subject: [PATCH v2] drivers core: Free dma_range_map when driver probe failed Date: Tue, 5 Jan 2021 15:09:27 +0800 Message-Id: <20210105070927.14968-1-Meng.Li@windriver.com> X-Mailer: git-send-email 2.17.1 Content-Type: text/plain X-Originating-IP: [60.247.85.82] X-ClientProxiedBy: YTXPR0101CA0072.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b00:1::49) To SJ0PR11MB5072.namprd11.prod.outlook.com (2603:10b6:a03:2db::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from pek-mli1-d2.wrs.com (60.247.85.82) by YTXPR0101CA0072.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b00:1::49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3721.19 via Frontend Transport; Tue, 5 Jan 2021 07:09:45 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c4f47fea-3a3c-4866-54a4-08d8b148e386 X-MS-TrafficTypeDiagnostic: BYAPR11MB3703: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:268; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: dBsCTqMDHsVd3IfA5QdBil6H/fAgFUy73siNis5xC7ia8M/ZtAHbfs6E/kELgPX0/hLjKFAxCq0knzjvCxN83aSVDzox1RHnhCItI23V7bA/TgWtWY8PRv6xwWzP/+hHydMpvj7uH8fZ/vv9cG5U9YN34ce5EAD8J2jS4iBTEokR4/ljdaoKuaN384+iLLwFXLp/67vjhiVCAWYVCHuJOVpS4xqXIv6WNWj46N4bxL+Q6NptdZwnOpttQrgVGJZ9qYWoI8ib/z+DbuY2jMB6cVwHuOdDM0PQfN/+rEZaW371n2VAocDv/EjEj+Bgx/Mm1sHBdsWaNTfTIuWF3nblRrxy0ougL4gOVEo1ycSbzgFUokNoYoR4ZNo/BGgmdq75 X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SJ0PR11MB5072.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(39850400004)(376002)(396003)(366004)(136003)(346002)(956004)(6486002)(4326008)(16526019)(8936002)(2906002)(36756003)(5660300002)(86362001)(2616005)(26005)(186003)(107886003)(52116002)(6506007)(6916009)(8676002)(9686003)(83380400001)(316002)(66556008)(66946007)(66476007)(1076003)(6666004)(478600001)(6512007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?bweaqVxnqX9vYLk744qg1uebQ2JRZ/z+WFZ/vuXF38h55tMZZgNGKh8Pb+NU?= =?us-ascii?Q?wKPEV1zEshHVmIdNWEJqsSEYqtx/q7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?us-ascii?Q?DhQ6MWM9cQtAI1B0flJXS4MMWWI6/O8JjBxk326+M5f7twgz8QoKMDBbVhCZ?= =?us-ascii?Q?oxcc?= X-OriginatorOrg: windriver.com X-MS-Exchange-CrossTenant-AuthSource: SJ0PR11MB5072.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Jan 2021 07:09:48.4146 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ddb2873-a1ad-4a18-ae4e-4644631433be X-MS-Exchange-CrossTenant-Network-Message-Id: c4f47fea-3a3c-4866-54a4-08d8b148e386 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: u+2TEzZj2UtVKmwbq8+6l5q4FvlMJxsim1CjYzvtvt2KUerZnn4YXDO0w+OseF9m8vvK4m/+0gH4zv0/whhyPQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR11MB3703 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Meng Li There will be memory leak if driver probe failed. Trace as below: backtrace: [<000000002415258f>] kmemleak_alloc+0x3c/0x50 [<00000000f447ebe4>] __kmalloc+0x208/0x530 [<0000000048bc7b3a>] of_dma_get_range+0xe4/0x1b0 [<0000000041e39065>] of_dma_configure_id+0x58/0x27c [<000000006356866a>] platform_dma_configure+0x2c/0x40 ...... [<000000000afcf9b5>] ret_from_fork+0x10/0x3c This issue is introduced by commit e0d072782c73("dma-mapping: introduce DMA range map, supplanting dma_pfn_offset "). It doesn't free dma_range_map when driver probe failed and cause above memory leak. So, add code to free it in error path. v2: set dev->dma_range_map as NULL after memory free. Fixes: e0d072782c73("dma-mapping: introduce DMA range map, supplanting dma_pfn_offset ") Cc: stable@vger.kernel.org Signed-off-by: Meng Li --- drivers/base/dd.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/base/dd.c b/drivers/base/dd.c index 148e81969e04..3c94ebc8d4bb 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c @@ -612,6 +612,8 @@ static int really_probe(struct device *dev, struct device_driver *drv) else if (drv->remove) drv->remove(dev); probe_failed: + kfree(dev->dma_range_map); + dev->dma_range_map = NULL; if (dev->bus) blocking_notifier_call_chain(&dev->bus->p->bus_notifier, BUS_NOTIFY_DRIVER_NOT_BOUND, dev); -- 2.17.1