Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp2609834rdb; Mon, 4 Dec 2023 02:26:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IFyD5ELSHWHEm5VpEPf3QQlO4OdPqTSEqSHSC4FcYGqeYEdcJ8p79eMAj6zOA5VHLBcmHNS X-Received: by 2002:a92:ce92:0:b0:35d:5dcb:7558 with SMTP id r18-20020a92ce92000000b0035d5dcb7558mr4715140ilo.60.1701685577285; Mon, 04 Dec 2023 02:26:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701685577; cv=none; d=google.com; s=arc-20160816; b=C54EnQk1HVqADW3z3cY5VxhI/KYbn8ZWG5idf/EN3WV+PKuMU+fvnIpOEwuZUip0Mn ma/oP4pGB8FEvws+1cTCETe/Vyg/6blz2k4LcMEJ6O8JQbifai5Ph57U95Ph+1KgWpCW 9moZyVfKEkThZqRBzW3EmNrDlLNG6Z9c78XXjNmXLdMwCMaiDvdqVPS298+kaC+3FaEA V5bPaIQflArn+Ds4lLBMkd+FN+Ruk8H6CP76kC55ok0zhaGlNshzVJBkc34W/7AzbBHt KEXUPSLM6oABe59VooaM0sseImlCE6bTTt4G6arhuCeF377n17v+70/MRneOKorvJi+M /cDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=YFWwDfWuYKDzJoaI6ZRY85TeV2wN7kNmrNs2cUdQvx8=; fh=pUCKY0k7ReMD+YIm66bt6pb2RJ83GRtDG5ZaBTDUx0U=; b=Q/EJJG0523CotTBA2nqkrveA3l4iaqK0bN40mz3GYXHFu5s8It1IDWuf6Fdx0GBxI5 T6ywe7gBNMYYFrxRKKmnIMWI5MnaV/SIr/GG4HlplOL3qK1nHjcHQyuq++QnChN09fP4 ul6q5mgN94uL76dFQ6Lv5TfFhtz2oUGioKcZNIXM9GlAV//RPhwPI3atb5b/V60lL0i0 kevTDNsoLDV2VMjdBbj4ijawgEgv8bZ2v7t9cecpbvV5SXWXzNuye2Qd2ihTK/EoBOAp 20wCCAoIDQ9LBK0NqbnAsNCeKy0uX7AtX84NIEvVdJyMofWTDYItQBjezrL/qVtrUtSZ cLog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=PbjqKqp7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id w62-20020a636241000000b005c65ed0f688si3608532pgb.296.2023.12.04.02.26.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 02:26:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=PbjqKqp7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 538BB809342A; Mon, 4 Dec 2023 02:25:51 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235330AbjLDKZg (ORCPT + 99 others); Mon, 4 Dec 2023 05:25:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235389AbjLDKZI (ORCPT ); Mon, 4 Dec 2023 05:25:08 -0500 Received: from mail-ot1-x329.google.com (mail-ot1-x329.google.com [IPv6:2607:f8b0:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DFA18D5B for ; Mon, 4 Dec 2023 02:24:59 -0800 (PST) Received: by mail-ot1-x329.google.com with SMTP id 46e09a7af769-6d9a6f756c3so228896a34.2 for ; Mon, 04 Dec 2023 02:24:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701685499; x=1702290299; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=YFWwDfWuYKDzJoaI6ZRY85TeV2wN7kNmrNs2cUdQvx8=; b=PbjqKqp7KXNSyyE7Co5VvuZY40kPmykj9I29LXr2lMfR961EtggDb0p7N1yPE03b2Y OPaqsN/LSxVf+5ipIwXix3gJ4VprIQ9nRIxoT6Yj6qe+g3tB5v/6iAHqoFaRRtmDLTik HEcvd9GLnvl2rzV8DPf09Sq6xQ9fFbnDWPRU2lOFFG8UhZ7txvRFVEwwq84p2KQ6wyGx AuSBgDOYJrMkNZUUsLLuc7ba1ALcvlxnhpanXLtOmhoSsEhSKhf6xKxwj+Ug8O84jvzo Giaa0bo91eu4k+OuIAq/Q33DSoXuuhXpbFGktIdFllstJmHoksuMf93tIzmfom2dcuLr QUIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701685499; x=1702290299; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YFWwDfWuYKDzJoaI6ZRY85TeV2wN7kNmrNs2cUdQvx8=; b=BdJAj80mE0/TGgZECBbFyrg1fYEMnI+G4D2x53IArSOJFNdEoNPlCjsDDWmx7CJSdv ktYkENET530q4nlMHlaK7qnNV6phOz9RZrefNyRQ8X1ECdBzsyZ+8X3bhuo+R9b5MOSq b8PpcAE0ASe1PS5w5F21vOkuMRE3ajYOSpftIuUf/PiW5sWY+0z8owH1wsiePklzztBl 1YG0dWd4xPXU0fnovcr98OyTJRkuEY1+j2gOntBIOzsOtpLryvdmpofAdLI1ByLS81j8 3KIWlbmsv1xX5FkS5FD2oxcgu1YLUp5TYO/+4q/hupSCEPSKQbr/cUQ1LTiduMNqlp8Z pdvw== X-Gm-Message-State: AOJu0YweWmcQjgOttmW1pT6F3J4C7egxchrMSS0aiIgWVur7TD/Ndauz 17jaUyJM9zUCTnqoy0ZYFmSR1edS/+PicQeKByMaul3yZCwetw== X-Received: by 2002:a05:6870:4998:b0:1fb:2c68:6c0b with SMTP id ho24-20020a056870499800b001fb2c686c0bmr2924886oab.37.1701685499014; Mon, 04 Dec 2023 02:24:59 -0800 (PST) MIME-Version: 1.0 References: <20231204034309.3290173-1-alexious@zju.edu.cn> In-Reply-To: <20231204034309.3290173-1-alexious@zju.edu.cn> From: Amos Jianjun Kong Date: Mon, 4 Dec 2023 18:24:47 +0800 Message-ID: Subject: Re: [PATCH] drm/radeon/trinity_dpm: fix a memleak in trinity_parse_power_table To: Zhipeng Lu Cc: "Pan, Xinhui" , linux-kernel@vger.kernel.org, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, Daniel Vetter , Alex Deucher , David Airlie , =?UTF-8?Q?Christian_K=C3=B6nig?= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,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 agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Mon, 04 Dec 2023 02:25:51 -0800 (PST) On Mon, Dec 4, 2023 at 5:55=E2=80=AFPM Zhipeng Lu wro= te: > > The rdev->pm.dpm.ps allocated by kcalloc should be freed in every > following error-handling path. However, in the error-handling of > rdev->pm.power_state[i].clock_info the rdev->pm.dpm.ps is not freed, > resulting in a memleak in this function. > > Fixes: d70229f70447 ("drm/radeon/kms: add dpm support for trinity asics") > Signed-off-by: Zhipeng Lu > --- > drivers/gpu/drm/radeon/trinity_dpm.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/drivers/gpu/drm/radeon/trinity_dpm.c b/drivers/gpu/drm/radeo= n/trinity_dpm.c > index 08ea1c864cb2..8bf56fb7b933 100644 > --- a/drivers/gpu/drm/radeon/trinity_dpm.c > +++ b/drivers/gpu/drm/radeon/trinity_dpm.c > @@ -1727,6 +1727,7 @@ static int trinity_parse_power_table(struct radeon_= device *rdev) > non_clock_info =3D (struct _ATOM_PPLIB_NONCLOCK_INFO *) > &non_clock_info_array->nonClockInfo[non_clock_arr= ay_index]; > if (!rdev->pm.power_state[i].clock_info) > + kfree(rdev->pm.dpm.ps); I just confirmed the memleak problem in the code. But the fix has a problem, it lacks the brackets. diff --git a/drivers/gpu/drm/radeon/trinity_dpm.c b/drivers/gpu/drm/radeon/trinity_dpm.c index 08ea1c864cb2..ef1cc7bad20a 100644 --- a/drivers/gpu/drm/radeon/trinity_dpm.c +++ b/drivers/gpu/drm/radeon/trinity_dpm.c @@ -1726,8 +1726,10 @@ static int trinity_parse_power_table(struct radeon_device *rdev) non_clock_array_index =3D power_state->v2.nonClockInfoIndex= ; non_clock_info =3D (struct _ATOM_PPLIB_NONCLOCK_INFO *) &non_clock_info_array->nonClockInfo[non_clock_array_index]; - if (!rdev->pm.power_state[i].clock_info) + if (!rdev->pm.power_state[i].clock_info) { + kfree(rdev->pm.dpm.ps); return -EINVAL; + } ps =3D kzalloc(sizeof(struct sumo_ps), GFP_KERNEL); if (ps =3D=3D NULL) { kfree(rdev->pm.dpm.ps); > return -EINVAL; > ps =3D kzalloc(sizeof(struct sumo_ps), GFP_KERNEL); > if (ps =3D=3D NULL) { > -- > 2.34.1 >