Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp89430rwn; Wed, 14 Sep 2022 16:34:48 -0700 (PDT) X-Google-Smtp-Source: AA6agR57k73ixBPmB0CqIJw5WKV4AJM7UCz+r59Poexvu1rWSP/fuGsLqdUrUcYVdPP9S1rT7Um4 X-Received: by 2002:a17:906:fe46:b0:730:ca2b:cb7b with SMTP id wz6-20020a170906fe4600b00730ca2bcb7bmr28554000ejb.703.1663198488290; Wed, 14 Sep 2022 16:34:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663198488; cv=none; d=google.com; s=arc-20160816; b=QDdSTK8DFZNoh2QU8anglL1Wq9AoNXMiuZEJ6ZgZUILBfl1nF7JOo7cnwktnR2343O Dzoca6CiSJZXP10uNmGs3gu6dgacdCfrz2S43JIrTc/h35r1p0/JExLc4faQrXVPsMzp zlA9KLzhDBND4nVgBxgkb2hg8iwCY9of1HuuN5epLhekA+jmGzU1FDoUclnSYnnznPca MmfGnb+jpoX+jVdOvqeNchWSTGUOWMNEXMnqCZeB9rZArULJzkMrQ2n8rzaLyVKZhke/ P+hsuldGWF8bKnf0djJZmFKX1jEBQvl3+rGmPY2xwg2JF+9EhQ+2290Mx9V2aCv/6fDJ 14vA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=OG5uQgkMf39mUwpOHjonQtZ4tonh493neJjEEVg5FeY=; b=Ncp2PqzGDOVfqLPbZfJJBTAReC9Gu1/lAOys3y9mXqwb/i4FfzLnFu3b3yfoEQDgJp DXoP/0AD28suuzFNvqtaLP6//HOq1uZxaGtbIJwNPrzLzSdOzT5rOVeC7cwOQEyqaUGa LR20mdPoTwsNd+OSezy8ChOEdlwd7ht8HsW2rnUqtLpiqh7reBN5ePUw/LHLN0d2WegC WTSbi2/r/+5gbednRJbK0wAhG841LGxxvB7mEJyuuryBNnWQk1T5fdBLPDLVPIitDD1n 2OJ9X19xBSq2djDL6Ln1d9XfjPpXloBF+0eb8G4zpln1CKfHmJJvO+3G4n7CajXhzPxR nqAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=f5mZWatE; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id oz18-20020a1709077d9200b0077f01df0b03si3436623ejc.881.2022.09.14.16.34.04; Wed, 14 Sep 2022 16:34:48 -0700 (PDT) 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; dkim=pass header.i=@gmail.com header.s=20210112 header.b=f5mZWatE; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229935AbiINXI3 (ORCPT + 99 others); Wed, 14 Sep 2022 19:08:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52972 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229930AbiINXI1 (ORCPT ); Wed, 14 Sep 2022 19:08:27 -0400 Received: from mail-oa1-x34.google.com (mail-oa1-x34.google.com [IPv6:2001:4860:4864:20::34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3598987095; Wed, 14 Sep 2022 16:08:26 -0700 (PDT) Received: by mail-oa1-x34.google.com with SMTP id 586e51a60fabf-11e9a7135easo45011165fac.6; Wed, 14 Sep 2022 16:08:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date; bh=OG5uQgkMf39mUwpOHjonQtZ4tonh493neJjEEVg5FeY=; b=f5mZWatEiHtHYsjX+/2J9ybC6dBmaIliKmhjebHkOCdUcXUrcJYa0GiSw7NHSXpRk2 EqigwasC0utHelsC5d57UU3cojC3CC9+uI6AoEvc/zdm+5rGU/poVdqEFDORATWnon3z YJsLSG50uHXf3xMrJJbsJW+jlQKNxERIdIOdZ7+w3GFdbSW9r/EPRNtVyx94ZfEQHyLh uhPzJ0zZ+4BYZi/kZx93JYmkQhrxsEzfX0aKxpahNMsYmGuQAkbYwyh7n9rW8JpIxlVI XkPHF/M8WnE+0u5vZf04g/yvPBd7tcB672oQh+/KIjkfaDpCuQvYqOPwYHCbyWAayetL Cw8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date; bh=OG5uQgkMf39mUwpOHjonQtZ4tonh493neJjEEVg5FeY=; b=4sTb3j9l0tLroAk0GTy4fsL5YGLW91/upQHFZPHW46LLPxiQ49c6VXXxX+zC0bcYHc ITQnFdIhaK9Iu9SYIOvytzA/J64y70eS4ybOdcQDq/yGC6d2Ksb3b7Du6hhwJV4fZMVt BQRalfA7ii9uAZj7U76nj/bbMe6WTJbdaq4ubGpmO6xpvTlxIZQRx15C5OsjGYFrE0Uk K7F0NVB6l+yS4f+X1r1lbevYTuXDq1D7r3Ws+qVn7FO06McNWFvhPrRSunyQSS5QKu5Y RGyAd6xh6K8kpr2xXzhjDKT0d9PXWD4aWxnd7Lbag2i1uwojP1d5N4wekCqO7rn4DqUM adqA== X-Gm-Message-State: ACgBeo2D1fKMmMDipnwaUNXo7UCLJ+PHwqWvfTvcZlCdu0dCzelwGyH1 ColN0wa0O+FLNsD/7R0V6Nc= X-Received: by 2002:a05:6871:90:b0:11d:cbad:10f5 with SMTP id u16-20020a056871009000b0011dcbad10f5mr3684843oaa.295.1663196905406; Wed, 14 Sep 2022 16:08:25 -0700 (PDT) Received: from macondo.. ([2804:431:e7cd:8cb3:fcc0:78f8:fb58:8a76]) by smtp.gmail.com with ESMTPSA id s9-20020a056808008900b0034fddfc5922sm2741077oic.36.2022.09.14.16.08.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Sep 2022 16:08:25 -0700 (PDT) From: Rafael Mendonca To: Fenghua Yu , Dave Jiang , Vinod Koul Cc: Rafael Mendonca , dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] dmaengine: idxd: Fix memory leak in idxd_alloc() Date: Wed, 14 Sep 2022 20:08:14 -0300 Message-Id: <20220914230815.700702-1-rafaelmendsr@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 If the IDA id allocation fails, then the allocated memory for the idxd_device struct doesn't get freed before returning NULL, which leads to a memleak. Fixes: 47c16ac27d4c ("dmaengine: idxd: fix idxd conf_dev 'struct device' lifetime") Signed-off-by: Rafael Mendonca --- drivers/dma/idxd/init.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/dma/idxd/init.c b/drivers/dma/idxd/init.c index aa3478257ddb..fdc97519b8fb 100644 --- a/drivers/dma/idxd/init.c +++ b/drivers/dma/idxd/init.c @@ -445,8 +445,10 @@ static struct idxd_device *idxd_alloc(struct pci_dev *pdev, struct idxd_driver_d idxd->data = data; idxd_dev_set_type(&idxd->idxd_dev, idxd->data->type); idxd->id = ida_alloc(&idxd_ida, GFP_KERNEL); - if (idxd->id < 0) + if (idxd->id < 0) { + kfree(idxd); return NULL; + } device_initialize(conf_dev); conf_dev->parent = dev; -- 2.34.1