From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ED04CC4332F for ; Mon, 30 Oct 2023 15:52:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233625AbjJ3Pwh (ORCPT ); Mon, 30 Oct 2023 11:52:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60702 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233619AbjJ3Pwe (ORCPT ); Mon, 30 Oct 2023 11:52:34 -0400 Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4E80C5 for ; Mon, 30 Oct 2023 08:52:30 -0700 (PDT) Received: by mail-ed1-x536.google.com with SMTP id 4fb4d7f45d1cf-538e8eca9c1so7464389a12.3 for ; Mon, 30 Oct 2023 08:52:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698681149; x=1699285949; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=qcBEi1lBI38DN/iPYBUEKFD33e1P8VGGwEZLkT86i0o=; b=OnwFDxQn/S7Fb/dcQZG8ZAoM2RjKGNeGszz31t93ziMlKf7+UpvgTE43IMFiwwE7nS o7rM3LpFn4aboSrd98R6sssEkpXUnqEr7NcuLdsz/p+40XofJSrpLgN58eTablLyLKQC 9LJVgJOl1IPeo3alcuKVN/mTlr8is8xwS+mIF+bc3HObnznyVgEDDyI3MY5+Y10yQfaz iybeQcbfilGQ7NJcMCns1zSZv4ZzTi5GI8a4T29enAqldkIThsUtIOSQ/XEO/WF+n+Jb 9hd5VgwRIWMJGnj8JaWCjkBXeLK6GmUFnQz4xmcKAwADuwu5hqFAKBdMXnYLc98JdhV0 GPew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698681149; x=1699285949; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=qcBEi1lBI38DN/iPYBUEKFD33e1P8VGGwEZLkT86i0o=; b=nT7ePtniW7HbNfeaWa4ed4JK+ZwFu+PPIUYBvofdfWOtd/IfMRh8Ymys5RtB3tJrv7 /9MBL/k1M2veJMpkhHzdOqUlutOc4EdRT3VT2rQ31lsvfaLKPzV5Pfi7m5cHzGdy8gYy v5ZRJ9B8AVRF0nh/X6Buwc7bx42emJ66I+IDmY6r/js1Fj+VVKjAE++/mspQRTkRr271 SM7PriG8FD6OCsPX7ob8OO5456RtRl6iApsJJsdXkuH8owZOdxrPeayvpAuNlj8S6rbQ YsbL+CqBNDfi8yoWn/7OfqH1k2+cqKvVCfRlWORQX3c4/rbpz3TPEIFLo3fnek0eBatc 8OXA== X-Gm-Message-State: AOJu0Yzm/LpObfMZJkLhNueCzb4OA0aUwt6aJoTk2yeuA9jouSlGNs0u 8Zvaqw9xkHEOshk1CYo27sk= X-Google-Smtp-Source: AGHT+IGlois2Urfp4DO3dHoJNYIFRP6cbF1tyrafdH0gLp9u4cmMpfl/mWbX2MVvH6o1Af4Rzoxv1A== X-Received: by 2002:a17:906:80da:b0:9d3:ccd1:a922 with SMTP id a26-20020a17090680da00b009d3ccd1a922mr2329078ejx.58.1698681149064; Mon, 30 Oct 2023 08:52:29 -0700 (PDT) Received: from [192.168.178.25] ([134.19.60.47]) by smtp.gmail.com with ESMTPSA id lo10-20020a170906fa0a00b00993a37aebc5sm6100891ejb.50.2023.10.30.08.52.27 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 30 Oct 2023 08:52:28 -0700 (PDT) Message-ID: <403a0750-361e-4218-8c83-a085966349e4@gmail.com> Date: Mon, 30 Oct 2023 16:52:25 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] drm/amdgpu: Fixes uninitialized variable usage in amdgpu_dm_setup_replay Content-Language: en-US To: Yuran Pereira , Hamza Mahfooz Cc: "Li, Sun peng (Leo)" , "Lakha, Bhawanpreet" , "Pan, Xinhui" , "Siqueira, Rodrigo" , "linux-kernel@vger.kernel.org" , "amd-gfx@lists.freedesktop.org" , "dri-devel@lists.freedesktop.org" , "Deucher, Alexander" , "airlied@gmail.com" , "Koenig, Christian" , "linux-kernel-mentees@lists.linuxfoundation.org" References: <39ab34ec-209d-4176-b271-1a02e2976497@amd.com> From: =?UTF-8?Q?Christian_K=C3=B6nig?= In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Am 28.10.23 um 02:48 schrieb Yuran Pereira: > Hello, > On Fri, Oct 27, 2023 at 11:57:45AM -0400, Hamza Mahfooz wrote: >> On 10/27/23 11:55, Lakha, Bhawanpreet wrote: >>> [AMD Official Use Only - General] >>> >>> >>> >>> There was a consensus to use memset instead of {0}. I remember making >>> changes related to that previously. >> Hm, seems like it's used rather consistently in the DM and in DC >> though. >> > Have you decided which one should be used? > > Should I submit a v2 patch using {0} instead of memset? The problem is that {0} doesn't initialize padding fields in structures. So what can happen are problems like leaking bytes to userspace or getting unstable hash keys etc... So I think memset() is usually preferred and that not only counts for Linux. Regards, Christian. > > > Yuran Pereira >>> Bhawan >>> >>> ------------------------------------------------------------------------ >>> *From:* Mahfooz, Hamza >>> *Sent:* October 27, 2023 11:53 AM >>> *To:* Yuran Pereira ; airlied@gmail.com >>> >>> *Cc:* Li, Sun peng (Leo) ; Lakha, Bhawanpreet >>> ; Pan, Xinhui ; Siqueira, >>> Rodrigo ; linux-kernel@vger.kernel.org >>> ; amd-gfx@lists.freedesktop.org >>> ; dri-devel@lists.freedesktop.org >>> ; Deucher, Alexander >>> ; Koenig, Christian >>> ; >>> linux-kernel-mentees@lists.linuxfoundation.org >>> >>> *Subject:* Re: [PATCH] drm/amdgpu: Fixes uninitialized variable usage in >>> amdgpu_dm_setup_replay >>> On 10/26/23 17:25, Yuran Pereira wrote: >>>> Since `pr_config` is not initialized after its declaration, the >>>> following operations with `replay_enable_option` may be performed >>>> when `replay_enable_option` is holding junk values which could >>>> possibly lead to undefined behaviour >>>> >>>> ``` >>>>       ... >>>>       pr_config.replay_enable_option |= pr_enable_option_static_screen; >>>>       ... >>>> >>>>       if (!pr_config.replay_timing_sync_supported) >>>>           pr_config.replay_enable_option &= ~pr_enable_option_general_ui; >>>>       ... >>>> ``` >>>> >>>> This patch initializes `pr_config` after its declaration to ensure that >>>> it doesn't contain junk data, and prevent any undefined behaviour >>>> >>>> Addresses-Coverity-ID: 1544428 ("Uninitialized scalar variable") >>>> Fixes: dede1fea4460 ("drm/amd/display: Add Freesync Panel DM code") >>>> Signed-off-by: Yuran Pereira >>>> --- >>>>    drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_replay.c | 3 +++ >>>>    1 file changed, 3 insertions(+) >>>> >>>> diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_replay.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_replay.c >>>> index 32d3086c4cb7..40526507f50b 100644 >>>> --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_replay.c >>>> +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_replay.c >>>> @@ -23,6 +23,7 @@ >>>>     * >>>>     */ >>>> +#include >>>>    #include "amdgpu_dm_replay.h" >>>>    #include "dc.h" >>>>    #include "dm_helpers.h" >>>> @@ -74,6 +75,8 @@ bool amdgpu_dm_setup_replay(struct dc_link *link, struct amdgpu_dm_connector *ac >>>>         struct replay_config pr_config; >>> I would prefer setting pr_config = {0}; >>> >>>>         union replay_debug_flags *debug_flags = NULL; >>>> +     memset(&pr_config, 0, sizeof(pr_config)); >>>> + >>>>         // For eDP, if Replay is supported, return true to skip checks >>>>         if (link->replay_settings.config.replay_supported) >>>>                 return true; >>> -- >>> Hamza >>> >> -- >> Hamza >>