From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.85.151]) (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 8B76F38FF for ; Sat, 26 Feb 2022 22:22:03 +0000 (UTC) Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id uk-mta-218-qo9exv-6NkuKleZpLM9g_w-1; Sat, 26 Feb 2022 22:22:00 +0000 X-MC-Unique: qo9exv-6NkuKleZpLM9g_w-1 Received: from AcuMS.Aculab.com (fd9f:af1c:a25b:0:994c:f5c2:35d6:9b65) by AcuMS.aculab.com (fd9f:af1c:a25b:0:994c:f5c2:35d6:9b65) with Microsoft SMTP Server (TLS) id 15.0.1497.28; Sat, 26 Feb 2022 22:21:58 +0000 Received: from AcuMS.Aculab.com ([fe80::994c:f5c2:35d6:9b65]) by AcuMS.aculab.com ([fe80::994c:f5c2:35d6:9b65%12]) with mapi id 15.00.1497.028; Sat, 26 Feb 2022 22:21:58 +0000 From: David Laight To: "'trix@redhat.com'" , "alexander.deucher@amd.com" , "christian.koenig@amd.com" , "Xinhui.Pan@amd.com" , "airlied@linux.ie" , "daniel@ffwll.ch" , "nathan@kernel.org" , "ndesaulniers@google.com" , "nirmoy.das@amd.com" , "lijo.lazar@amd.com" , "tom.stdenis@amd.com" , "evan.quan@amd.com" , "kevin1.wang@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" Subject: RE: [PATCH] drm/amdgpu: Fix realloc of ptr Thread-Topic: [PATCH] drm/amdgpu: Fix realloc of ptr Thread-Index: AQHYKynKuecV+YVBsEaifDyg6Kuo9qymZ9yQ Date: Sat, 26 Feb 2022 22:21:58 +0000 Message-ID: References: <20220226155851.4176109-1-trix@redhat.com> In-Reply-To: <20220226155851.4176109-1-trix@redhat.com> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] 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=C51A453 smtp.mailfrom=david.laight@aculab.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable From: trix@redhat.com > Sent: 26 February 2022 15:59 >=20 > From: Tom Rix >=20 > Clang static analysis reports this error > amdgpu_debugfs.c:1690:9: warning: 1st function call > argument is an uninitialized value > tmp =3D krealloc_array(tmp, i + 1, > ^~~~~~~~~~~~~~~~~~~~~~~~~~~ >=20 > realloc will free tmp, so tmp can not be garbage. > And the return needs to be checked. Are you sure? A quick check seems to show that krealloc() behaves the same way as libc realloc() and the pointer isn't freed on failure. =09David > Fixes: 5ce5a584cb82 ("drm/amdgpu: add debugfs for reset registers list") > Signed-off-by: Tom Rix > --- > drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c | 6 +++++- > 1 file changed, 5 insertions(+), 1 deletion(-) >=20 > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c b/drivers/gpu/dr= m/amd/amdgpu/amdgpu_debugfs.c > index 9eb9b440bd438..159b97c0b4ebc 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_writ= e(struct file *f, > { > =09struct amdgpu_device *adev =3D (struct amdgpu_device *)file_inode(f)-= >i_private; > =09char reg_offset[11]; > -=09uint32_t *tmp; > +=09uint32_t *tmp =3D NULL; > =09int ret, i =3D 0, len =3D 0; >=20 > =09do { > @@ -1688,6 +1688,10 @@ static ssize_t amdgpu_reset_dump_register_list_wri= te(struct file *f, > =09=09} >=20 > =09=09tmp =3D krealloc_array(tmp, i + 1, sizeof(uint32_t), GFP_KERNEL); > +=09=09if (!tmp) { > +=09=09=09ret =3D -ENOMEM; > +=09=09=09goto error_free; > +=09=09} > =09=09if (sscanf(reg_offset, "%X %n", &tmp[i], &ret) !=3D 1) { > =09=09=09ret =3D -EINVAL; > =09=09=09goto error_free; > -- > 2.26.3 - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1= PT, UK Registration No: 1397386 (Wales)