Message ID | 20221215163649.386750-1-arnd@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp477528wrn; Thu, 15 Dec 2022 08:56:49 -0800 (PST) X-Google-Smtp-Source: AA0mqf72oByIVbTiduzk6zChy7+LRkG7yi+9dsinUvWdoXA+wS3197W3gEuah/6DFasFqIGEAHoI X-Received: by 2002:a05:6a20:e68c:b0:a7:9b17:2efe with SMTP id mz12-20020a056a20e68c00b000a79b172efemr33558159pzb.60.1671123408943; Thu, 15 Dec 2022 08:56:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671123408; cv=none; d=google.com; s=arc-20160816; b=UHMycZj9C3IFkHhZU1x5BIaePF4HWOri0UL6BiTO79l2kp4YSmETBCW3N5E61vm/MT FRT8NJCUcZm11KRvjaU6aEvHmrfn0gu1CczdPlNTwU0e9a3G+/JLGQcTIxlokj8swd5O Zs1kSZTB1V5yAS5khAdByhzSSQsB3qWp09kKAcixUTB3iZanseOgivuShLHtOFVJUtfg k8rSjwMlkoigvYd9+tMScwF8esRg1pWfjUY0QQnAaGlQ/W2qg0JPzod3GI5XMtS4NU0T 42fR3kzwiw7gXPg+F17vjRm5MtQkICHYwLkl4USp2uSAn7IaAU4k6TcrUVmpvhCQ+026 rGDw== 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=L4M5Ui9+pY1wxKTsP0IJ/CJg8hYQ50yJsO62cmzevEk=; b=A5CsZFpgujKUznkeT+cX+mzhYRZquX/XY52wa6xl7JDn39SpkIT47AcPDzPh7P7KLs AjQwW8GIi80Nrf2o26fZKn+9SY6lfeMzZwENm7xdea1MgRgHJ123qt2P0Q1hJ7lHyqYp V5BUOIAkUUMizPqQ8Se/CZph/UKxprJZNGMNCWPFvq+HYcRPw1K2tG9k14NX4jKwGBJ/ Dz8iMAnthhWVLRbYum/286wqHQqhhl4tJI5hItiaQ4uZNd+WcqxYjuwzg3aif77GJyzl YfaRq4gbbCa+mJcbKTEKfxW0+lx9yfYI8HqRp04OceikCrOXgOJ0ECBsG+k9Rbg12ZaT m3tQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="s/ZJp7C9"; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l191-20020a6388c8000000b0047856c2590esi3206009pgd.35.2022.12.15.08.56.35; Thu, 15 Dec 2022 08:56:48 -0800 (PST) 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="s/ZJp7C9"; 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 S230013AbiLOQhB (ORCPT <rfc822;jeantsuru.cumc.mandola@gmail.com> + 99 others); Thu, 15 Dec 2022 11:37:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230167AbiLOQhA (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 15 Dec 2022 11:37:00 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C4091EAFF for <linux-kernel@vger.kernel.org>; Thu, 15 Dec 2022 08:36:59 -0800 (PST) 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 EAD3DB81C03 for <linux-kernel@vger.kernel.org>; Thu, 15 Dec 2022 16:36:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 07826C433EF; Thu, 15 Dec 2022 16:36:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1671122216; bh=ZJ+UjuFlAHEeqnv1r+X8Y1fN3lyrw6ECR6xLRaAEqRs=; h=From:To:Cc:Subject:Date:From; b=s/ZJp7C9+lCHF8eafSYx+Wl0LjwFFtKVRaeM6VE62PEFslr7gD0rOlWNHK8Q9aO/u IJOYYYtArmR9K6dhMjAmuTjXMsFNnBg6W3wep8Co6lTtLQsYIKH3u2M6AbVbY7jja2 ZVQ9NHhLpZr+PjJGuKeDYs1dCR8BIWWjsHfX83awoSjiyEEmswpWr0EnvUAcS+omvL Nb3YMtjm36x6088xcboN9A1ic9ArjNsJMSPpirfuQlZeJ/gwe5CfmJl9tS1pu5EmB/ B7u2G1o0fLIXH1ssDwvxusBqB/+lI+ZZD4jDgJZVsnS2bfDHZW/5RkG/5AOPrG0eLM PNwp9/RZx9cTw== From: Arnd Bergmann <arnd@kernel.org> To: Evan Quan <evan.quan@amd.com>, Alex Deucher <alexander.deucher@amd.com>, =?utf-8?q?Christian_K=C3=B6nig?= <christian.koenig@amd.com>, "Pan, Xinhui" <Xinhui.Pan@amd.com> Cc: Arnd Bergmann <arnd@arndb.de>, David Airlie <airlied@gmail.com>, Daniel Vetter <daniel@ffwll.ch>, Nathan Chancellor <nathan@kernel.org>, Nick Desaulniers <ndesaulniers@google.com>, Tom Rix <trix@redhat.com>, Kenneth Feng <kenneth.feng@amd.com>, Hawking Zhang <Hawking.Zhang@amd.com>, Yang Wang <KevinYang.Wang@amd.com>, Chengming Gui <Jack.Gui@amd.com>, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev Subject: [PATCH] drm/amd/pm: avoid large variable on kernel stack Date: Thu, 15 Dec 2022 17:36:31 +0100 Message-Id: <20221215163649.386750-1-arnd@kernel.org> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752299899786103665?= X-GMAIL-MSGID: =?utf-8?q?1752299899786103665?= |
Series |
drm/amd/pm: avoid large variable on kernel stack
|
|
Commit Message
Arnd Bergmann
Dec. 15, 2022, 4:36 p.m. UTC
From: Arnd Bergmann <arnd@arndb.de> The activity_monitor_external[] array is too big to fit on the kernel stack, resulting in this warning with clang: drivers/gpu/drm/amd/amdgpu/../pm/swsmu/smu13/smu_v13_0_7_ppt.c:1438:12: error: stack frame size (1040) exceeds limit (1024) in 'smu_v13_0_7_get_power_profile_mode' [-Werror,-Wframe-larger-than] Use dynamic allocation instead. It should also be possible to have single element here instead of the array, but this seems easier. Fixes: 334682ae8151 ("drm/amd/pm: enable workload type change on smu_v13_0_7") Signed-off-by: Arnd Bergmann <arnd@arndb.de> --- .../drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-)
Comments
Applied. Thanks! Alex On Thu, Dec 15, 2022 at 11:37 AM Arnd Bergmann <arnd@kernel.org> wrote: > > From: Arnd Bergmann <arnd@arndb.de> > > The activity_monitor_external[] array is too big to fit on the > kernel stack, resulting in this warning with clang: > > drivers/gpu/drm/amd/amdgpu/../pm/swsmu/smu13/smu_v13_0_7_ppt.c:1438:12: error: stack frame size (1040) exceeds limit (1024) in 'smu_v13_0_7_get_power_profile_mode' [-Werror,-Wframe-larger-than] > > Use dynamic allocation instead. It should also be possible to > have single element here instead of the array, but this seems > easier. > > Fixes: 334682ae8151 ("drm/amd/pm: enable workload type change on smu_v13_0_7") > Signed-off-by: Arnd Bergmann <arnd@arndb.de> > --- > .../drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c | 21 ++++++++++++++----- > 1 file changed, 16 insertions(+), 5 deletions(-) > > diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c > index c270f94a1b86..7eba854e09ec 100644 > --- a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c > +++ b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c > @@ -1439,7 +1439,7 @@ static int smu_v13_0_7_get_power_limit(struct smu_context *smu, > > static int smu_v13_0_7_get_power_profile_mode(struct smu_context *smu, char *buf) > { > - DpmActivityMonitorCoeffIntExternal_t activity_monitor_external[PP_SMC_POWER_PROFILE_COUNT]; > + DpmActivityMonitorCoeffIntExternal_t *activity_monitor_external; > uint32_t i, j, size = 0; > int16_t workload_type = 0; > int result = 0; > @@ -1447,6 +1447,12 @@ static int smu_v13_0_7_get_power_profile_mode(struct smu_context *smu, char *buf > if (!buf) > return -EINVAL; > > + activity_monitor_external = kcalloc(sizeof(activity_monitor_external), > + PP_SMC_POWER_PROFILE_COUNT, > + GFP_KERNEL); > + if (!activity_monitor_external) > + return -ENOMEM; > + > size += sysfs_emit_at(buf, size, " "); > for (i = 0; i <= PP_SMC_POWER_PROFILE_WINDOW3D; i++) > size += sysfs_emit_at(buf, size, "%-14s%s", amdgpu_pp_profile_name[i], > @@ -1459,15 +1465,17 @@ static int smu_v13_0_7_get_power_profile_mode(struct smu_context *smu, char *buf > workload_type = smu_cmn_to_asic_specific_index(smu, > CMN2ASIC_MAPPING_WORKLOAD, > i); > - if (workload_type < 0) > - return -EINVAL; > + if (workload_type < 0) { > + result = -EINVAL; > + goto out; > + } > > result = smu_cmn_update_table(smu, > SMU_TABLE_ACTIVITY_MONITOR_COEFF, workload_type, > (void *)(&activity_monitor_external[i]), false); > if (result) { > dev_err(smu->adev->dev, "[%s] Failed to get activity monitor!", __func__); > - return result; > + goto out; > } > } > > @@ -1495,7 +1503,10 @@ do { \ > PRINT_DPM_MONITOR(Fclk_BoosterFreq); > #undef PRINT_DPM_MONITOR > > - return size; > + result = size; > +out: > + kfree(activity_monitor_external); > + return result; > } > > static int smu_v13_0_7_set_power_profile_mode(struct smu_context *smu, long *input, uint32_t size) > -- > 2.35.1 >
Le 15/12/2022 à 17:36, Arnd Bergmann a écrit : > From: Arnd Bergmann <arnd-r2nGTMty4D4@public.gmane.org> > > The activity_monitor_external[] array is too big to fit on the > kernel stack, resulting in this warning with clang: > > drivers/gpu/drm/amd/amdgpu/../pm/swsmu/smu13/smu_v13_0_7_ppt.c:1438:12: error: stack frame size (1040) exceeds limit (1024) in 'smu_v13_0_7_get_power_profile_mode' [-Werror,-Wframe-larger-than] > > Use dynamic allocation instead. It should also be possible to > have single element here instead of the array, but this seems > easier. > > Fixes: 334682ae8151 ("drm/amd/pm: enable workload type change on smu_v13_0_7") > Signed-off-by: Arnd Bergmann <arnd-r2nGTMty4D4@public.gmane.org> > --- > .../drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c | 21 ++++++++++++++----- > 1 file changed, 16 insertions(+), 5 deletions(-) > > diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c > index c270f94a1b86..7eba854e09ec 100644 > --- a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c > +++ b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c > @@ -1439,7 +1439,7 @@ static int smu_v13_0_7_get_power_limit(struct smu_context *smu, > > static int smu_v13_0_7_get_power_profile_mode(struct smu_context *smu, char *buf) > { > - DpmActivityMonitorCoeffIntExternal_t activity_monitor_external[PP_SMC_POWER_PROFILE_COUNT]; > + DpmActivityMonitorCoeffIntExternal_t *activity_monitor_external; > uint32_t i, j, size = 0; > int16_t workload_type = 0; > int result = 0; > @@ -1447,6 +1447,12 @@ static int smu_v13_0_7_get_power_profile_mode(struct smu_context *smu, char *buf > if (!buf) > return -EINVAL; > > + activity_monitor_external = kcalloc(sizeof(activity_monitor_external), Hi, Before, 'activity_monitor_external' was not initialized. Maybe kcalloc() is enough? sizeof(*activity_monitor_external)? ~~~~ > + PP_SMC_POWER_PROFILE_COUNT, > + GFP_KERNEL); > + if (!activity_monitor_external) > + return -ENOMEM; > + > size += sysfs_emit_at(buf, size, " "); > for (i = 0; i <= PP_SMC_POWER_PROFILE_WINDOW3D; i++) Unrelated, but wouldn't it be more straightforward with "< PP_SMC_POWER_PROFILE_COUNT"? > size += sysfs_emit_at(buf, size, "%-14s%s", amdgpu_pp_profile_name[i], > @@ -1459,15 +1465,17 @@ static int smu_v13_0_7_get_power_profile_mode(struct smu_context *smu, char *buf > workload_type = smu_cmn_to_asic_specific_index(smu, > CMN2ASIC_MAPPING_WORKLOAD, > i); > - if (workload_type < 0) > - return -EINVAL; > + if (workload_type < 0) { > + result = -EINVAL; > + goto out; > + } > > result = smu_cmn_update_table(smu, > SMU_TABLE_ACTIVITY_MONITOR_COEFF, workload_type, > (void *)(&activity_monitor_external[i]), false); > if (result) { > dev_err(smu->adev->dev, "[%s] Failed to get activity monitor!", __func__); > - return result; > + goto out; > } > } > > @@ -1495,7 +1503,10 @@ do { \ > PRINT_DPM_MONITOR(Fclk_BoosterFreq); > #undef PRINT_DPM_MONITOR > > - return size; > + result = size; > +out: > + kfree(activity_monitor_external); > + return result; > } > > static int smu_v13_0_7_set_power_profile_mode(struct smu_context *smu, long *input, uint32_t size)
Le 15/12/2022 à 20:46, Christophe JAILLET a écrit : > Le 15/12/2022 à 17:36, Arnd Bergmann a écrit : >> From: Arnd Bergmann <arnd-r2nGTMty4D4@public.gmane.org> >> >> The activity_monitor_external[] array is too big to fit on the >> kernel stack, resulting in this warning with clang: >> >> drivers/gpu/drm/amd/amdgpu/../pm/swsmu/smu13/smu_v13_0_7_ppt.c:1438:12: error: stack frame size (1040) exceeds limit (1024) in 'smu_v13_0_7_get_power_profile_mode' [-Werror,-Wframe-larger-than] >> >> Use dynamic allocation instead. It should also be possible to >> have single element here instead of the array, but this seems >> easier. >> >> Fixes: 334682ae8151 ("drm/amd/pm: enable workload type change on >> smu_v13_0_7") >> Signed-off-by: Arnd Bergmann <arnd-r2nGTMty4D4@public.gmane.org> >> --- >> .../drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c | 21 ++++++++++++++----- >> 1 file changed, 16 insertions(+), 5 deletions(-) >> >> diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c >> b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c >> index c270f94a1b86..7eba854e09ec 100644 >> --- a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c >> +++ b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c >> @@ -1439,7 +1439,7 @@ static int smu_v13_0_7_get_power_limit(struct >> smu_context *smu, >> static int smu_v13_0_7_get_power_profile_mode(struct smu_context >> *smu, char *buf) >> { >> - DpmActivityMonitorCoeffIntExternal_t >> activity_monitor_external[PP_SMC_POWER_PROFILE_COUNT]; >> + DpmActivityMonitorCoeffIntExternal_t *activity_monitor_external; >> uint32_t i, j, size = 0; >> int16_t workload_type = 0; >> int result = 0; >> @@ -1447,6 +1447,12 @@ static int >> smu_v13_0_7_get_power_profile_mode(struct smu_context *smu, char *buf >> if (!buf) >> return -EINVAL; >> + activity_monitor_external = >> kcalloc(sizeof(activity_monitor_external), > > Hi, > > Before, 'activity_monitor_external' was not initialized. > Maybe kcalloc() is enough? Read kmalloc_array() > > sizeof(*activity_monitor_external)? > ~~~~ > >> + PP_SMC_POWER_PROFILE_COUNT, >> + GFP_KERNEL); >> + if (!activity_monitor_external) >> + return -ENOMEM; >> + >> size += sysfs_emit_at(buf, size, " "); >> for (i = 0; i <= PP_SMC_POWER_PROFILE_WINDOW3D; i++) > > Unrelated, but wouldn't it be more straightforward with "< > PP_SMC_POWER_PROFILE_COUNT"? > >> size += sysfs_emit_at(buf, size, "%-14s%s", >> amdgpu_pp_profile_name[i], >> @@ -1459,15 +1465,17 @@ static int >> smu_v13_0_7_get_power_profile_mode(struct smu_context *smu, char *buf >> workload_type = smu_cmn_to_asic_specific_index(smu, >> CMN2ASIC_MAPPING_WORKLOAD, >> i); >> - if (workload_type < 0) >> - return -EINVAL; >> + if (workload_type < 0) { >> + result = -EINVAL; >> + goto out; >> + } >> result = smu_cmn_update_table(smu, >> SMU_TABLE_ACTIVITY_MONITOR_COEFF, workload_type, >> (void *)(&activity_monitor_external[i]), false); >> if (result) { >> dev_err(smu->adev->dev, "[%s] Failed to get activity >> monitor!", __func__); >> - return result; >> + goto out; >> } >> } >> @@ -1495,7 +1503,10 @@ do >> { \ >> PRINT_DPM_MONITOR(Fclk_BoosterFreq); >> #undef PRINT_DPM_MONITOR >> - return size; >> + result = size; >> +out: >> + kfree(activity_monitor_external); >> + return result; >> } >> static int smu_v13_0_7_set_power_profile_mode(struct smu_context >> *smu, long *input, uint32_t size) > >
On Thu, Dec 15, 2022 at 2:46 PM Christophe JAILLET <christophe.jaillet@wanadoo.fr> wrote: > > Le 15/12/2022 à 17:36, Arnd Bergmann a écrit : > > From: Arnd Bergmann <arnd-r2nGTMty4D4@public.gmane.org> > > > > The activity_monitor_external[] array is too big to fit on the > > kernel stack, resulting in this warning with clang: > > > > drivers/gpu/drm/amd/amdgpu/../pm/swsmu/smu13/smu_v13_0_7_ppt.c:1438:12: error: stack frame size (1040) exceeds limit (1024) in 'smu_v13_0_7_get_power_profile_mode' [-Werror,-Wframe-larger-than] > > > > Use dynamic allocation instead. It should also be possible to > > have single element here instead of the array, but this seems > > easier. > > > > Fixes: 334682ae8151 ("drm/amd/pm: enable workload type change on smu_v13_0_7") > > Signed-off-by: Arnd Bergmann <arnd-r2nGTMty4D4@public.gmane.org> > > --- > > .../drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c | 21 ++++++++++++++----- > > 1 file changed, 16 insertions(+), 5 deletions(-) > > > > diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c > > index c270f94a1b86..7eba854e09ec 100644 > > --- a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c > > +++ b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c > > @@ -1439,7 +1439,7 @@ static int smu_v13_0_7_get_power_limit(struct smu_context *smu, > > > > static int smu_v13_0_7_get_power_profile_mode(struct smu_context *smu, char *buf) > > { > > - DpmActivityMonitorCoeffIntExternal_t activity_monitor_external[PP_SMC_POWER_PROFILE_COUNT]; > > + DpmActivityMonitorCoeffIntExternal_t *activity_monitor_external; > > uint32_t i, j, size = 0; > > int16_t workload_type = 0; > > int result = 0; > > @@ -1447,6 +1447,12 @@ static int smu_v13_0_7_get_power_profile_mode(struct smu_context *smu, char *buf > > if (!buf) > > return -EINVAL; > > > > + activity_monitor_external = kcalloc(sizeof(activity_monitor_external), > > Hi, > > Before, 'activity_monitor_external' was not initialized. > Maybe kcalloc() is enough? > > sizeof(*activity_monitor_external)? > ~~~~ I've fixed this up when applying. Alex > > > + PP_SMC_POWER_PROFILE_COUNT, > > + GFP_KERNEL); > > + if (!activity_monitor_external) > > + return -ENOMEM; > > + > > size += sysfs_emit_at(buf, size, " "); > > for (i = 0; i <= PP_SMC_POWER_PROFILE_WINDOW3D; i++) > > Unrelated, but wouldn't it be more straightforward with "< > PP_SMC_POWER_PROFILE_COUNT"? > > > size += sysfs_emit_at(buf, size, "%-14s%s", amdgpu_pp_profile_name[i], > > @@ -1459,15 +1465,17 @@ static int smu_v13_0_7_get_power_profile_mode(struct smu_context *smu, char *buf > > workload_type = smu_cmn_to_asic_specific_index(smu, > > CMN2ASIC_MAPPING_WORKLOAD, > > i); > > - if (workload_type < 0) > > - return -EINVAL; > > + if (workload_type < 0) { > > + result = -EINVAL; > > + goto out; > > + } > > > > result = smu_cmn_update_table(smu, > > SMU_TABLE_ACTIVITY_MONITOR_COEFF, workload_type, > > (void *)(&activity_monitor_external[i]), false); > > if (result) { > > dev_err(smu->adev->dev, "[%s] Failed to get activity monitor!", __func__); > > - return result; > > + goto out; > > } > > } > > > > @@ -1495,7 +1503,10 @@ do { \ > > PRINT_DPM_MONITOR(Fclk_BoosterFreq); > > #undef PRINT_DPM_MONITOR > > > > - return size; > > + result = size; > > +out: > > + kfree(activity_monitor_external); > > + return result; > > } > > > > static int smu_v13_0_7_set_power_profile_mode(struct smu_context *smu, long *input, uint32_t size) >
diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c index c270f94a1b86..7eba854e09ec 100644 --- a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c +++ b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c @@ -1439,7 +1439,7 @@ static int smu_v13_0_7_get_power_limit(struct smu_context *smu, static int smu_v13_0_7_get_power_profile_mode(struct smu_context *smu, char *buf) { - DpmActivityMonitorCoeffIntExternal_t activity_monitor_external[PP_SMC_POWER_PROFILE_COUNT]; + DpmActivityMonitorCoeffIntExternal_t *activity_monitor_external; uint32_t i, j, size = 0; int16_t workload_type = 0; int result = 0; @@ -1447,6 +1447,12 @@ static int smu_v13_0_7_get_power_profile_mode(struct smu_context *smu, char *buf if (!buf) return -EINVAL; + activity_monitor_external = kcalloc(sizeof(activity_monitor_external), + PP_SMC_POWER_PROFILE_COUNT, + GFP_KERNEL); + if (!activity_monitor_external) + return -ENOMEM; + size += sysfs_emit_at(buf, size, " "); for (i = 0; i <= PP_SMC_POWER_PROFILE_WINDOW3D; i++) size += sysfs_emit_at(buf, size, "%-14s%s", amdgpu_pp_profile_name[i], @@ -1459,15 +1465,17 @@ static int smu_v13_0_7_get_power_profile_mode(struct smu_context *smu, char *buf workload_type = smu_cmn_to_asic_specific_index(smu, CMN2ASIC_MAPPING_WORKLOAD, i); - if (workload_type < 0) - return -EINVAL; + if (workload_type < 0) { + result = -EINVAL; + goto out; + } result = smu_cmn_update_table(smu, SMU_TABLE_ACTIVITY_MONITOR_COEFF, workload_type, (void *)(&activity_monitor_external[i]), false); if (result) { dev_err(smu->adev->dev, "[%s] Failed to get activity monitor!", __func__); - return result; + goto out; } } @@ -1495,7 +1503,10 @@ do { \ PRINT_DPM_MONITOR(Fclk_BoosterFreq); #undef PRINT_DPM_MONITOR - return size; + result = size; +out: + kfree(activity_monitor_external); + return result; } static int smu_v13_0_7_set_power_profile_mode(struct smu_context *smu, long *input, uint32_t size)