From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 682014A83 for ; Sun, 27 Feb 2022 15:39:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1645976394; 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; bh=JUKXRy9HtvoNJh5zgWKk9291k0gpOXjxfgvv4FNocC0=; b=QDIFWwyzFEamCrdA1eWIFXTlRhdBlJFJPtJBUeKG0Ts5V2nuXykT3wzE2aA2RhhRKXDUDH w7C2Uy63r31zqRhkn9L1bxSRc7VbcCIOPHhgEQlImfl/enhYBBK8NwL2APzrkeJcpnKC6k XC9z5vVvRk0qS7ogwARswUIXJVGwWEE= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-36-ti6bXXVzOhquNatgyvhQZQ-1; Sun, 27 Feb 2022 10:39:52 -0500 X-MC-Unique: ti6bXXVzOhquNatgyvhQZQ-1 Received: by mail-qk1-f197.google.com with SMTP id l82-20020a37a255000000b0060dd39f5d87so9486297qke.4 for ; Sun, 27 Feb 2022 07:39:52 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=JUKXRy9HtvoNJh5zgWKk9291k0gpOXjxfgvv4FNocC0=; b=ozmdjQopQaUMgM0I/BizUHfnJudplD8uUZ7r4pWcOIhegGKcBwSl4hepQlYvhLA9vm JP4kWkOaPvBRjJiu6deXjrPh3SdeT4XSRHjhDiBSTTsrgBUbDCwvE4Ykhilcr7HN+AJZ +GYNK50nrcrVVCiMCAbH0Oui6yu3Zk7v7tPHrfFTMAPgCEtg4r8yuv937kjuUkamDkcR 1NY70hmEtf9KJ1jYkdnPknqPEkEblgnV+EmrXHwyL9ZIFirP3v5naVZQ7u5aT7+1bqbJ T57gO4iwUKIgjtZnE0azruTboaB/CslIbS9fP+6pGoJijX07Lk/fWygS818IWDdO5N0w F45Q== X-Gm-Message-State: AOAM5315Qm7dfZjidyRvvEXMJm7yOqZNmiYbnwGfvjZVeuHTrmQERHvX 03GI/ixjrOhOsayLVxoxH8kXDftBSJpQ5rIpfgWhiX073mvNpBFrIiCnmGaSW2wKoFrhOrg/MKL VeitQM/0x6OBDSA== X-Received: by 2002:ad4:5883:0:b0:432:b007:962b with SMTP id dz3-20020ad45883000000b00432b007962bmr10545692qvb.55.1645976392541; Sun, 27 Feb 2022 07:39:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJypeMdQov6ivEZ1hmtZAlsJVizNYH0ogniT3ujzWNSu97z8PC8qPn1bhLsvRrQy0v8d6KuyjQ== X-Received: by 2002:ad4:5883:0:b0:432:b007:962b with SMTP id dz3-20020ad45883000000b00432b007962bmr10545670qvb.55.1645976392292; Sun, 27 Feb 2022 07:39:52 -0800 (PST) Received: from localhost.localdomain.com (024-205-208-113.res.spectrum.com. [24.205.208.113]) by smtp.gmail.com with ESMTPSA id c6-20020ac87d86000000b002ddd9f33ed1sm5036371qtd.44.2022.02.27.07.39.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Feb 2022 07:39:51 -0800 (PST) From: trix@redhat.com To: alexander.deucher@amd.com, christian.koenig@amd.com, Xinhui.Pan@amd.com, airlied@linux.ie, daniel@ffwll.ch, nathan@kernel.org, ndesaulniers@google.com, lijo.lazar@amd.com, nirmoy.das@amd.com, kevin1.wang@amd.com, tom.stdenis@amd.com, evan.quan@amd.com, Amaranath.Somalapuram@amd.com Cc: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, Tom Rix Subject: [PATCH v2] drm/amdgpu: Fix realloc of ptr Date: Sun, 27 Feb 2022 07:33:42 -0800 Message-Id: <20220227153342.79546-1-trix@redhat.com> X-Mailer: git-send-email 2.26.3 Precedence: bulk X-Mailing-List: llvm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=trix@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" From: Tom Rix Clang static analysis reports this error amdgpu_debugfs.c:1690:9: warning: 1st function call argument is an uninitialized value tmp = krealloc_array(tmp, i + 1, ^~~~~~~~~~~~~~~~~~~~~~~~~~~ realloc uses tmp, so tmp can not be garbage. And the return needs to be checked. Fixes: 5ce5a584cb82 ("drm/amdgpu: add debugfs for reset registers list") Signed-off-by: Tom Rix --- v2: use 'new' to hold/check the ralloc return fix commit log mistake on ralloc freeing to using input ptr drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c index 9eb9b440bd438..2f4f8c5618d81 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c @@ -1676,7 +1676,7 @@ static ssize_t amdgpu_reset_dump_register_list_write(struct file *f, { struct amdgpu_device *adev = (struct amdgpu_device *)file_inode(f)->i_private; char reg_offset[11]; - uint32_t *tmp; + uint32_t *new, *tmp = NULL; int ret, i = 0, len = 0; do { @@ -1687,7 +1687,12 @@ static ssize_t amdgpu_reset_dump_register_list_write(struct file *f, goto error_free; } - tmp = krealloc_array(tmp, i + 1, sizeof(uint32_t), GFP_KERNEL); + new = krealloc_array(tmp, i + 1, sizeof(uint32_t), GFP_KERNEL); + if (!new) { + ret = -ENOMEM; + goto error_free; + } + tmp = new; if (sscanf(reg_offset, "%X %n", &tmp[i], &ret) != 1) { ret = -EINVAL; goto error_free; -- 2.26.3