Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2188023iof; Tue, 7 Jun 2022 22:35:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzVPYUG+fRHP7EQkvi98pbbsYzqS6dnL1i/9F0nMsg27EQKWbMYk2FevDAnH95sVxtni7Y5 X-Received: by 2002:a17:902:b18e:b0:15e:c6ac:440a with SMTP id s14-20020a170902b18e00b0015ec6ac440amr32881520plr.152.1654666553061; Tue, 07 Jun 2022 22:35:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654666553; cv=none; d=google.com; s=arc-20160816; b=VnjIxSf5qYUrqtfvv6P6Rb7EkKgC7tufwv/L9EOX6FrjnVbgajNvGFQnlA+7QbuxM0 BORyskRotvwZtEzK2op8FskFIPNhII51XWLexVT+2JJ2gr7bCO+6bbxHsHpWyYwV7XJ/ 5pydoRv5gXwDfiLvhUM0x5p7KjMjG/n1+PoSBkE44uOuG262rxMmrnYZZv0stPaCU3mO pT/gs9Y4RG34zHmMM6S+bA7jnIuh//fU1y4Ho/ktt3RtmjkeT9wl+iF9j4rINUuUTR1v OcwPQrhSfMOwSOBU1NFRRFq7So24rSt4ASCxV0dNs1KFQT+QeIrk3lisi+8cZxNcp3m6 1g6g== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=L8AnWd9E7uXS86nlfcncF7d+/0OZR5qsFXXCJJqiUPY=; b=pbSjUJWN4dXZQJqGjunZxqMrWzn9yBu+PYYwt/tkDjwbTZ99aEXlpwTFZbuEYHMIdP AnVyPkoE4zi0hvv1XdtTq6Ak/hWJd7ml3OC2nGuqM1u2i+MDg1/HG7c/L+UUr42wbkVK x7ZYj9KIlGoczW5v3z0CPOk4O1fi0T7NiOoIxwnn+o64OvCsIbq+Eq8NMDi7mas2R+sA /vOBc+iRQ6A15d5m5MhnOmVgFDmR5okiVw24wEga9TBh06lqnO8MDzhXQSk4aMKHfCeI Rk5y8uQO4iKigDOE0TVk1JMwKrCi5OvOur8se0o/FUICNBEKKW9epCtSCzXnaGhLdYbT m6AA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=08WB348V; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id y17-20020a634b11000000b003aaf76cfd76si27154216pga.835.2022.06.07.22.35.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 22:35:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=08WB348V; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6E8233C0029; Tue, 7 Jun 2022 22:13:26 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1388933AbiFHAfA (ORCPT + 99 others); Tue, 7 Jun 2022 20:35:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383732AbiFGWGN (ORCPT ); Tue, 7 Jun 2022 18:06:13 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D5082534C9; Tue, 7 Jun 2022 12:17:24 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 3F462B82182; Tue, 7 Jun 2022 19:17:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9AA97C385A5; Tue, 7 Jun 2022 19:17:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654629442; bh=54oShyB5o9LvImQ36NGWJacrxO3osSvxe7sccidCXN8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=08WB348VGe1mB4x85kMoFcIfUKEIFCfvOlhjVzMEetdCyS2BU9cD5ZekyvOPYcrzB MF2sSMQ4UxGQiv+1QuxqA/tgYTLFVasOv78Bj//pkCnremycEtPs4+atVkV67JiBlI 6/W2GBo213vRdOmTHLE97g51Fk8WlFmkF9IwLI98= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Christophe JAILLET , Dave Jiang , Vinod Koul , Sasha Levin Subject: [PATCH 5.18 675/879] dmaengine: idxd: Fix the error handling path in idxd_cdev_register() Date: Tue, 7 Jun 2022 19:03:13 +0200 Message-Id: <20220607165022.441765444@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607165002.659942637@linuxfoundation.org> References: <20220607165002.659942637@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 From: Christophe JAILLET [ Upstream commit aab08c1aac01097815fbcf10fce7021d2396a31f ] If a call to alloc_chrdev_region() fails, the already allocated resources are leaking. Add the needed error handling path to fix the leak. Fixes: 42d279f9137a ("dmaengine: idxd: add char driver to expose submission portal to userland") Signed-off-by: Christophe JAILLET Acked-by: Dave Jiang Link: https://lore.kernel.org/r/1b5033dcc87b5f2a953c413f0306e883e6114542.1650521591.git.christophe.jaillet@wanadoo.fr Signed-off-by: Vinod Koul Signed-off-by: Sasha Levin --- drivers/dma/idxd/cdev.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/dma/idxd/cdev.c b/drivers/dma/idxd/cdev.c index b9b2b4a4124e..033df43db0ce 100644 --- a/drivers/dma/idxd/cdev.c +++ b/drivers/dma/idxd/cdev.c @@ -369,10 +369,16 @@ int idxd_cdev_register(void) rc = alloc_chrdev_region(&ictx[i].devt, 0, MINORMASK, ictx[i].name); if (rc) - return rc; + goto err_free_chrdev_region; } return 0; + +err_free_chrdev_region: + for (i--; i >= 0; i--) + unregister_chrdev_region(ictx[i].devt, MINORMASK); + + return rc; } void idxd_cdev_remove(void) -- 2.35.1