Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4141523imw; Thu, 7 Jul 2022 13:30:11 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sJivVQExFj9GDrSrCCTKdP4Upp/L00JuW13hbXxwnEiDzuMi8FZqfc3R1K/LKCjX4M2cEa X-Received: by 2002:a63:2a4e:0:b0:412:518c:213 with SMTP id q75-20020a632a4e000000b00412518c0213mr19042639pgq.42.1657225811170; Thu, 07 Jul 2022 13:30:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657225811; cv=none; d=google.com; s=arc-20160816; b=GzFN4JFfAz8/FN/BtSNkN6nFEdCMvOUoR7OVWPesByEdHEXe8FAyMYzX3gx6c9nCqz 625iiUfkJ34fjI86Fff8UzGDSdpnEvDWD2y3iLAcmN9DBU1Bx/rW6OB2p1g5LV4RDZWc 3evBQqMouK/B9NEFeK5JU9VOo0lydz5gsb7DocvkKr8fw9umX69D7cqGXAHCSsm439mK MGa7O+jZA5TN+3Pp3l9CwdtfS2w8UFY1GxgcpWZ+1TWV2gyp0LPiOYMIpLSo3V9HBuky 5cOI1Vo2YCxZtaNN+iAMQ/XfVnGjVEv6yNEMsJDfFevMGsLMIeQprwmdNFbAl9l/pjPS Igqg== 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:organization:references:in-reply-to:date:cc:to:from :subject:message-id:dkim-signature; bh=4Mo3Zl8VhFZlmNu+vKliCf9PrnP4k8cuE7bMp/19zYQ=; b=pHp8+y/O9rxkrhl/DhptHEjsOsH8Nsk4jl0SRYz/3EZmoaHEnHJU2dxWfts4CVGreI 1vDuCv3Tqvf+7qAMo6m363eJhYKq3yucJeMUH1JF+TnFjOK9n49jxi1rKZJRBtkgjAss oo3SPt0WhH86HtbAwN3DISX8V82B8J21AI/0GC6SjQtHSuItCtU8QHshkg1C0Z6WOezh z9thhIEs4FvkgNFFwXlO89yHjrlOWaCvuOXztFM0Oo52nVy6zeWcPKPdnQU+2USkwSAI 6I50yduVMGWhNXSfoc/YLBQUL8+vGecpeq0I69ZuBQFXnfMVpJ7rbr9MSHnISArYlnt5 6z9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="OzN/Xhf1"; 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=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g130-20020a636b88000000b0040dbb3c4c1esi46917218pgc.567.2022.07.07.13.29.56; Thu, 07 Jul 2022 13:30:11 -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=@redhat.com header.s=mimecast20190719 header.b="OzN/Xhf1"; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232257AbiGGTz5 (ORCPT + 99 others); Thu, 7 Jul 2022 15:55:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235622AbiGGTz4 (ORCPT ); Thu, 7 Jul 2022 15:55:56 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 940F55C9CA for ; Thu, 7 Jul 2022 12:55:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657223752; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4Mo3Zl8VhFZlmNu+vKliCf9PrnP4k8cuE7bMp/19zYQ=; b=OzN/Xhf1hf+AanqN1tXztTnyitNhJGBIcK6suPyLwcza+4LpQQYdXCccXWnJ5eJTAvl/tI 79BH0lu9o4lfduoudoiaZTU2nvhwpUb1BakwbL3fxvXOjFX3SM84bjIRBt+MEpehNfu72m wjCD+9ahC8I6/zqKqhPG133a/SIoFuM= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-316-evkr0Y9jPJqbklOO5xXjOQ-1; Thu, 07 Jul 2022 15:55:48 -0400 X-MC-Unique: evkr0Y9jPJqbklOO5xXjOQ-1 Received: by mail-qk1-f200.google.com with SMTP id z9-20020a376509000000b006af1048e0caso18904986qkb.17 for ; Thu, 07 Jul 2022 12:55:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:organization:user-agent:mime-version :content-transfer-encoding; bh=4Mo3Zl8VhFZlmNu+vKliCf9PrnP4k8cuE7bMp/19zYQ=; b=R/N+EytWN5FmEa8aiihV8y9UvwX2tHTM0Wx/l3RVb/jHw/rhdrBTqeX7sT0Z0ekgQG 3lSYD0k0M3xbvZ4CR0LcEZMcwwr0MLlLQwCwtVB7mONhORdL9VIZYU4wUl4ji2/5uEZ6 wOu2jj6YIPXNfmBhI2F/VuGoV65Alrm5rnGbsv5h27EPJZLMdOAPRpLgw4HOncaBqjQx cvYCHUZgwfwSAmcZ8wDF4cACgU0AGiH0/r5C07EZP16zW+a9TvrdpeeSzBgswhEnRPh0 UBqIf3AcAD1Bkqw+TfIZtVbkJaayBW8NHrrB7wxDbGOgxkQjwvYUx61Ba9YzlIE8Opmt cuPw== X-Gm-Message-State: AJIora+v5x5b4xXpwFJma0BGCm0d+Kn2y4fhuTV2hIvqM57xW7wHH5ki rjDHGbtoS09rP0sMK5WC6XhHYDc8gA5nq05tHKWVkEh9sOzTzkj2g6CDZg7UOOSkCOtm0+Kv9Kl 2eV9jepiuDpxD0UQsacseBJyQ X-Received: by 2002:a05:620a:a97:b0:6af:1394:1966 with SMTP id v23-20020a05620a0a9700b006af13941966mr31924311qkg.348.1657223748324; Thu, 07 Jul 2022 12:55:48 -0700 (PDT) X-Received: by 2002:a05:620a:a97:b0:6af:1394:1966 with SMTP id v23-20020a05620a0a9700b006af13941966mr31924302qkg.348.1657223748010; Thu, 07 Jul 2022 12:55:48 -0700 (PDT) Received: from [192.168.8.138] ([141.154.49.182]) by smtp.gmail.com with ESMTPSA id u12-20020a05620a454c00b006afd667535asm23648140qkp.83.2022.07.07.12.55.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Jul 2022 12:55:47 -0700 (PDT) Message-ID: <62827a27253727d92d6bfcf833a9ec4d3f7c7cd3.camel@redhat.com> Subject: Re: [PATCH] drm/nouveau/nouveau_bo: fix potential memory leak in nouveau_bo_alloc() From: Lyude Paul To: Jianglei Nie , bskeggs@redhat.com, kherbst@redhat.com, airlied@linux.ie, daniel@ffwll.ch Cc: ri-devel@lists.freedesktop.org, nouveau@lists.freedesktop.org, linux-kernel@vger.kernel.org Date: Thu, 07 Jul 2022 15:55:46 -0400 In-Reply-To: <20220705094306.2244103-1-niejianglei2021@163.com> References: <20220705094306.2244103-1-niejianglei2021@163.com> Organization: Red Hat Inc. Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.42.4 (3.42.4-2.fc35) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,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 Reviewed-by: Lyude Paul Will push On Tue, 2022-07-05 at 17:43 +0800, Jianglei Nie wrote: > 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 > --- >  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 05076e530e7d..d0887438b07e 100644 > --- a/drivers/gpu/drm/nouveau/nouveau_bo.c > +++ b/drivers/gpu/drm/nouveau/nouveau_bo.c > @@ -281,8 +281,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) { -- Cheers, Lyude Paul (she/her) Software Engineer at Red Hat