Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp14724rwi; Sun, 9 Oct 2022 17:30:56 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7ZQDxwOSWyeC2TbHyoRYmnGN3EQz6Jq12bzPUXlkbYgMhUjXgvA8qT/qiZImMHQ6OKSQ31 X-Received: by 2002:a05:6402:11ce:b0:45b:f851:2941 with SMTP id j14-20020a05640211ce00b0045bf8512941mr5160073edw.177.1665361856112; Sun, 09 Oct 2022 17:30:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665361856; cv=none; d=google.com; s=arc-20160816; b=TrkD+QaYggcFTs7Kt5qW4oSz0TbRulp6+D+wM/Rr0ebf6zmndPw0SuE1nYjp4hL29S h36hk4hCDHOaK7Pc/nnBUaemrnH3EsokMCnOK4lo/LENx9hSADYf+P5Dt8asmK+pIsMR yhXcIp4erFXyL/ZMg9EFQN0X5tAHqyBwst8Bkh4tuZ4juXCMiZ260+NLG8Jb/CRGnufJ l9faQDWCMlUzPFMSlOtnHpWgGBLX0jngGyu1+tcIqlrR3tsEVktRG3phZpAMEcKJnb68 DCrGCo9se/jerQrN3WSJ9YeEjOwkSE87KSvLAqus2J+TsFVf0NGz9/o/CULfwXnIcig6 nbQA== 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=86Tzfm407mQTA/k5JCLfS2ZDe8GlqE9oSkmvMF4v0/c=; b=ElFZZxhE9frJalFwWErj+tozDYiejamULGznoq7/gLpb83coWfcBIBkfH1pgqvjldt GuHyomkGN4EOm89nBjyNa8hcDWCDubWyU1+YFHFx02Js8KWUeDwEzySWOFdGXAU1rL92 jpO7r+Q0KWlNVmmIvxqK+k4/oq5GRJ87u0Z91XGzT/6otyQR6fMltPoM5o7xfHNXsLoU JpQNKn5ObSj0gY+469EUfu0h6QKsb+kVMAQ3sD6g2qMtF0XOlm7WjfvzE6awGt9Zn2pE FJqWDUlZsEUdxQ05rRpvUMziwQCRBmkmPicHsfqQSmQeLWxx7HOhOgTFWuA8nV9xf/bU IqaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="geDk/Lcm"; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ji4-20020a170907980400b0078d4b9e68cbsi10133687ejc.1002.2022.10.09.17.30.30; Sun, 09 Oct 2022 17:30:56 -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=@kernel.org header.s=k20201202 header.b="geDk/Lcm"; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231489AbiJJAZf (ORCPT + 99 others); Sun, 9 Oct 2022 20:25:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232702AbiJJAWH (ORCPT ); Sun, 9 Oct 2022 20:22:07 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC61412D24; Sun, 9 Oct 2022 16:56:09 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 787BF60D57; Sun, 9 Oct 2022 23:56:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C1A59C433B5; Sun, 9 Oct 2022 23:56:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1665359768; bh=+AaMpEEtbRsAd0445XliC1VO8cMNV1cNMNF7QtsWu+Y=; h=From:To:Cc:Subject:Date:From; b=geDk/LcmP/PU1i85xStmOqWaEqcWeKeh/ry5HjqItxtmZhdIB8daZC878ja0PstfE dhGWFggVnkNJ66J8AA/dyPtlDD/FhIE3YJ5Jvowzh2n/r/HQZuKTy5o+yc3FF5TAnm 9b9wRr9z8ZFEVAVpz48xgL4jLpDzFZyVvLyrr/LNEMf1Jd4DlPFa9pG2kMV5XkvPGR F3QYL7cEcMx9y0hTOIJeNMJMoGntRa5pEdFGcI2LmVlyENtCrGTo76S9dLtxSVzkMf yo1rM+jMJrywvLnmfLh4rEn05vP3UXzLfptgeH0sXquCFV2KL+0ulSipzcaFpYblkt 0vvDDCnioFrVw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Jianglei Nie , Lyude Paul , Sasha Levin , bskeggs@redhat.com, kherbst@redhat.com, airlied@gmail.com, daniel@ffwll.ch, dri-devel@lists.freedesktop.org, nouveau@lists.freedesktop.org Subject: [PATCH AUTOSEL 5.10 01/22] drm/nouveau/nouveau_bo: fix potential memory leak in nouveau_bo_alloc() Date: Sun, 9 Oct 2022 19:55:19 -0400 Message-Id: <20221009235540.1231640-1-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 From: Jianglei Nie [ Upstream commit 6dc548745d5b5102e3c53dc5097296ac270b6c69 ] nouveau_bo_alloc() allocates a memory chunk for "nvbo" with kzalloc(). When some error occurs, "nvbo" should be released. But when WARN_ON(pi < 0)) equals true, the function return ERR_PTR without releasing the "nvbo", which will lead to a memory leak. We should release the "nvbo" with kfree() if WARN_ON(pi < 0)) equals true. Signed-off-by: Jianglei Nie Signed-off-by: Lyude Paul Reviewed-by: Lyude Paul Link: https://patchwork.freedesktop.org/patch/msgid/20220705094306.2244103-1-niejianglei2021@163.com Signed-off-by: Sasha Levin --- drivers/gpu/drm/nouveau/nouveau_bo.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.c b/drivers/gpu/drm/nouveau/nouveau_bo.c index b4946b595d86..b57dcad8865f 100644 --- a/drivers/gpu/drm/nouveau/nouveau_bo.c +++ b/drivers/gpu/drm/nouveau/nouveau_bo.c @@ -279,8 +279,10 @@ nouveau_bo_alloc(struct nouveau_cli *cli, u64 *size, int *align, u32 domain, break; } - if (WARN_ON(pi < 0)) + if (WARN_ON(pi < 0)) { + kfree(nvbo); return ERR_PTR(-EINVAL); + } /* Disable compression if suitable settings couldn't be found. */ if (nvbo->comp && !vmm->page[pi].comp) { -- 2.35.1