From patchwork Sat Nov 19 07:33:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zheng Yongjun X-Patchwork-Id: 23226 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp602303wrr; Fri, 18 Nov 2022 23:55:12 -0800 (PST) X-Google-Smtp-Source: AA0mqf6NkNLj+/WxOYJU2C7utm3bzxPYZpsFPzXuzVzdV3BAB/CeQky+7SI1NnGyqZRbTUSiLOFS X-Received: by 2002:a17:906:2e96:b0:7ad:8f76:17c7 with SMTP id o22-20020a1709062e9600b007ad8f7617c7mr8573018eji.315.1668844512014; Fri, 18 Nov 2022 23:55:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668844512; cv=none; d=google.com; s=arc-20160816; b=ijjpe96HXuuQAhVoullIwGGWLBiD+vE49+xncTy0da90Wwt9QFgAgEI+JnzJOcvfUe UgrgxZowLE7Kh6IkeWdwEcrR9bZFkcGRc9YNGKAQoWTwbu2ggQFP+K0TU9+LRugDRLQ2 4q4+U0ynom3bZ+yqxRcuklH2dqUr91Hxtx3ctf51DlAe5Nb8ouDhZxiXNMCA+zA5/ntd /KSQYm7Z7ayS/rEhz9SVSKBqkmfZZ07JUah8LqG3n5cAyxpeMX6cPOICx0TSrMmB9pnU ZwsGwEU9lBSoQ6A65nwu1zoAfQ7FMdBuI4MP7KUoG02X7KOEP4uwR0+VHsBim/JUlILM cb2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:to:from; bh=n8ph+y9/yp6NIN9tvZuvrGyaXj5g0tETHDgTrQYBAh0=; b=Lsm9pdsBKyZs/0SPvcl+zkLGOzSBT3NjXTpr+B4vgbDGC+SEAxjhdJ/E+o1V6VhrN2 A6qcDzPbnD1pkmytAPDDi42HuFHjoV5LK7j7dGIt9BSnlpiiMZw+dlMq7iF7+52jBPwW 7+TGamW2NtDcz6gCBWF88MouHqS8XPBlU8jaFRhEthrgBA1yt5wGSjUPfPyyTUwmj1+0 gjYI1POzZb9tP/guZxv0OmSkmjIi4XAOnWQGJM5WduYvNEmbeCYxKiU0hjdUyYbEmeFn FrRJpZi9wnSDCTbJwGIlSKT+H0RkgOjJKRhFGeDFPun+BQLpTYqWxEfqw0O/Wku4I3fn C1vw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w20-20020a05640234d400b0045945eed10asi49864edc.5.2022.11.18.23.54.47; Fri, 18 Nov 2022 23:55:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232544AbiKSHfE (ORCPT + 99 others); Sat, 19 Nov 2022 02:35:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42322 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229500AbiKSHfC (ORCPT ); Sat, 19 Nov 2022 02:35:02 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB2E082BF3 for ; Fri, 18 Nov 2022 23:35:01 -0800 (PST) Received: from kwepemi500013.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4NDlgx1JxyzqSTv; Sat, 19 Nov 2022 15:31:09 +0800 (CST) Received: from huawei.com (10.175.112.208) by kwepemi500013.china.huawei.com (7.221.188.120) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Sat, 19 Nov 2022 15:34:59 +0800 From: Zheng Yongjun To: , , , , Subject: [PATCH] mtd: fix memory leak in pxa2xx_flash_probe() Date: Sat, 19 Nov 2022 07:33:07 +0000 Message-ID: <20221119073307.22929-1-zhengyongjun3@huawei.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-Originating-IP: [10.175.112.208] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To kwepemi500013.china.huawei.com (7.221.188.120) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749910302873867257?= X-GMAIL-MSGID: =?utf-8?q?1749910302873867257?= If '!info->map.virt' or '!info->mtd' success, 'info' should be freed before return. Otherwise there is a memory leak. Fixes: e644f7d62894 ("[MTD] MAPS: Merge Lubbock and Mainstone drivers into common PXA2xx driver") Signed-off-by: Zheng Yongjun --- drivers/mtd/maps/pxa2xx-flash.c | 2 ++ 1 file changed, 2 insertions(+) -- 2.17.1 diff --git a/drivers/mtd/maps/pxa2xx-flash.c b/drivers/mtd/maps/pxa2xx-flash.c index 1749dbbacc13..62a5bf41a6d7 100644 --- a/drivers/mtd/maps/pxa2xx-flash.c +++ b/drivers/mtd/maps/pxa2xx-flash.c @@ -64,6 +64,7 @@ static int pxa2xx_flash_probe(struct platform_device *pdev) if (!info->map.virt) { printk(KERN_WARNING "Failed to ioremap %s\n", info->map.name); + kfree(info); return -ENOMEM; } info->map.cached = ioremap_cache(info->map.phys, info->map.size); @@ -85,6 +86,7 @@ static int pxa2xx_flash_probe(struct platform_device *pdev) iounmap((void *)info->map.virt); if (info->map.cached) iounmap(info->map.cached); + kfree(info); return -EIO; } info->mtd->dev.parent = &pdev->dev;