From patchwork Sat Mar 11 18:51:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ondrej Zary X-Patchwork-Id: 68183 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp420319wrd; Sat, 11 Mar 2023 11:28:36 -0800 (PST) X-Google-Smtp-Source: AK7set8Frvy0xs2XV0GJdFOG9TMMZQ3UVlLPsZ8j9zig230ETTzVebZxzWkQO1jt92dhVYQDHYTM X-Received: by 2002:a17:90b:3b4b:b0:234:19a1:8690 with SMTP id ot11-20020a17090b3b4b00b0023419a18690mr30392976pjb.26.1678562915700; Sat, 11 Mar 2023 11:28:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678562915; cv=none; d=google.com; s=arc-20160816; b=mYrpw/6rFDPGfPZgVBiHwMCQ1A0E1LY63PFg4764WhXNPJYRYMmJSAYAgnIYD8rZfl Ie4eFNramS6LlzR5o42Bg+LhjZ5hfTbjXrx5BbKRPj0ECrSdJ7V0/0hpMZlg4rIrhNj9 /vhCnQI9lG/sIEs7+P9rFdBp0YdZpAaVD8x7ms3Mz+Ots9ecAqkx/mhulth3tTWslSeU 1TjTFCTehlts7dmt5f1pVKk6pg45ZdHMDg2IAdQbVsU5TqewznXjYyoiOntuwptXZE7l EOG/R00cAz2cUpgF38v6sfz5y6AcmEuWXJplkZfn3oCzdsJUUN7Wtfy1JgJ5KEU2qF3W nz2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=9UqTN4PGFRExKp8Sb7ViQ6iVCCacfZnFAJ0eVfzOm/E=; b=mQ8aEcHw6Io4UW55tFpZuZ/b+jbhY1wLTzXWzn0dBrAiYoaOmQjyxqxD8Yl2382+Ar Y/9Dn3f1T6oGSGWDiwss/5rbX8Kquuy4ETaP8CX5PQwBZzGu/11cgY2RE/qyNFObQMhM Q1bJlcf+41tRJL5HuDIHA7Os1U9/oNhDDyhINnqjVdal1Gwuh+lpLdfNohRW1su02t6D S5WYGVbLCgKZIfq4g3WEIEM0CH5PPyNgsbGUH9/RoNuHPYcxXuJDZvtm1GRw1XqHO7cW WtNJA6GsMvYBENcA0RPKs9ABU7UuJ96+szeSvt8Qf7mopZ4AhNdkfxg+tO8GPf/T+i5d nVJA== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w24-20020a63fb58000000b00503a029385asi2517553pgj.849.2023.03.11.11.28.23; Sat, 11 Mar 2023 11:28:35 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229783AbjCKSwR (ORCPT + 99 others); Sat, 11 Mar 2023 13:52:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229641AbjCKSwQ (ORCPT ); Sat, 11 Mar 2023 13:52:16 -0500 Received: from hosting.gsystem.sk (hosting.gsystem.sk [212.5.213.30]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2F00B91B6F; Sat, 11 Mar 2023 10:52:12 -0800 (PST) Received: from gsql.ggedos.sk (off-20.infotel.telecom.sk [212.5.213.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by hosting.gsystem.sk (Postfix) with ESMTPSA id 557E57A03CE; Sat, 11 Mar 2023 19:52:10 +0100 (CET) From: Ondrej Zary To: Damien Le Moal Cc: Dan Carpenter , Christoph Hellwig , Sergey Shtylyov , linux-ide@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] pata_parport: fix possible memory leak Date: Sat, 11 Mar 2023 19:51:49 +0100 Message-Id: <20230311185149.22957-1-linux@zary.sk> X-Mailer: git-send-email 2.20.1 In-Reply-To: <3ab89ddc-cb60-47c4-86ad-cdad94a8a3d7@kili.mountain> References: <3ab89ddc-cb60-47c4-86ad-cdad94a8a3d7@kili.mountain> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED 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?1760100787952827298?= X-GMAIL-MSGID: =?utf-8?q?1760100787952827298?= When ida_alloc() fails, "pi" is not freed although the misleading comment says otherwise. Move the ida_alloc() call up so we really don't have to free it. Reported-by: kernel test robot Reported-by: Dan Carpenter Link: https://lore.kernel.org/r/202303111822.IHNchbkp-lkp@intel.com/ Signed-off-by: Ondrej Zary Reviewed-by: Sergey Shtylyov --- drivers/ata/pata_parport/pata_parport.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/ata/pata_parport/pata_parport.c b/drivers/ata/pata_parport/pata_parport.c index 6165ee9aa7da..fb1f10afa722 100644 --- a/drivers/ata/pata_parport/pata_parport.c +++ b/drivers/ata/pata_parport/pata_parport.c @@ -503,18 +503,19 @@ static struct pi_adapter *pi_init_one(struct parport *parport, if (bus_for_each_dev(&pata_parport_bus_type, NULL, &match, pi_find_dev)) return NULL; + id = ida_alloc(&pata_parport_bus_dev_ids, GFP_KERNEL); + if (id < 0) + return NULL; + pi = kzalloc(sizeof(struct pi_adapter), GFP_KERNEL); if (!pi) - return NULL; + goto out_ida_free; /* set up pi->dev before pi_probe_unit() so it can use dev_printk() */ pi->dev.parent = &pata_parport_bus; pi->dev.bus = &pata_parport_bus_type; pi->dev.driver = &pr->driver; pi->dev.release = pata_parport_dev_release; - id = ida_alloc(&pata_parport_bus_dev_ids, GFP_KERNEL); - if (id < 0) - return NULL; /* pata_parport_dev_release will do kfree(pi) */ pi->dev.id = id; dev_set_name(&pi->dev, "pata_parport.%u", pi->dev.id); if (device_register(&pi->dev)) {