Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp21517lqz; Fri, 29 Mar 2024 07:24:30 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU8m/t2TWg0d+xWr7uM8sS/YKzxE1KDpSnwE1q68OBOYmNHfw9JUY22s6vaPtPPOZgPJCU6ySFGmK1ah8Nhrsz5GxDP35lSjb4hRXVaAg== X-Google-Smtp-Source: AGHT+IEjx/cKG12X1mss4xUBZyD1vfXU7tNd/OEt4h526qWMpIlbLK5xk7/+c/XLhcsbrlYeInDh X-Received: by 2002:a05:6a20:1589:b0:1a3:15e8:7e93 with SMTP id h9-20020a056a20158900b001a315e87e93mr2385098pzj.56.1711722270078; Fri, 29 Mar 2024 07:24:30 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711722270; cv=pass; d=google.com; s=arc-20160816; b=xKMLyD2vNgUilCFvry8vmkoZHGFIcMGOnOfRzs37jZlXO9DUgR9W+ZAR23wK8Xqo5G 3wj5ygqidBRyu6GgtLESIcNgkT+NlmaIEAsyyPsLACG9H7cwCF7y53UAmx8Vik0NvZzu 1uP/ai5wgj1VemN40XEqM8E1nemnXH4ginyqQ24Bg6T9sNgXqakvGs7OwDjbvYNOcqMl q/tKSXdTjaL3RQfAnJwmHrn726/2mKk+kVrzMhp7qCBSZGPaI3zbbBvJj0i6cIf1EJBY n42p//Zh2kWGkenIj4dgc/i11Apy6i2rKZOiTSVV/EwPcl6xI48w1kKVSfNQrYwGtyz0 iFYA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=i4x1dXjCIjV88vefEYGdZZyddMHJvDemcgJT67ERypE=; fh=5XbtNPaJxs4xa9JTzDXY3wSo9tajjxbP3f7AovZxqFE=; b=Drm+HqWqe8yB3Ao2LQh1g3RfRAwJuNsMRK0aIrbW/2uoykJE+71GVXvJJy7b2rWpYf By36oFVoE+qNgGZQI11Y00qen1M+N+95IkmssjnkMxuuWZ0bvX2/EPWAKDzFj7bgYl2r 3WGzmw7zBWBng2za2Ju/RMDwRYs3wCU73CAwdB/5LDst6xte6gEG78pqkxanIuUfyb5U v13eMb96FSomfPB/yiUHUpBkvQv25fDdVwFtSmeS+PGA+IQkBxejkmoFWLmAV+nGRNYp pwPMMwVYZdSJgg2tlb7UtBWLSUajt8vyS927F1eSAi9u2v86yUHwK8yK01KW8RP2lP6S DfRQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=K48CQdos; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-124911-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-124911-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id y8-20020aa78548000000b006e6857da47asi3748765pfn.366.2024.03.29.07.24.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Mar 2024 07:24:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-124911-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=K48CQdos; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-124911-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-124911-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id BF58F285D09 for ; Fri, 29 Mar 2024 14:24:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C05F414BFAD; Fri, 29 Mar 2024 12:46:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="K48CQdos" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 E12A629E1BE; Fri, 29 Mar 2024 12:46:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711716418; cv=none; b=jFs/MBOG4Tik2dKBrPVYBKnrWYEdc9x1BpHvkdJnLgNU8asYalkOYcUrqyWsigfV6ywZaf2GcYqKqpvarytmb5AIx9bmaYeLhc8+YFY0a/HU5IX/hDdxEcyo4ecbbxb3QK83PG8XK6exf+/IeLQjpw4gEd2R9VqjqbpytnMzYyA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711716418; c=relaxed/simple; bh=5wOc+LUMfZCRy3MZnUmqxiohZmyUE+kUku580aPi7cM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=UwvdprkAkQr+5vZGvuQ7BsWqAXfTOaWexx48i9MTdB8TjMk7VTX48OlMf5KUr71e6chJV28dsc0ylabFIeD1wwAE/X464tND49ZPh0cXnSr/4OH+vBr4/KFaOhGBw5GcE2ryUGnFI6rzNOJ5IyAalwuCXFEpzW+iezSUcm8I81Y= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=K48CQdos; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8EBC6C433C7; Fri, 29 Mar 2024 12:46:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711716417; bh=5wOc+LUMfZCRy3MZnUmqxiohZmyUE+kUku580aPi7cM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K48CQdosDo9SRk5QTbGebzTok+HtVCMMqTAnVjjcK391k1vyHJ0Tnuw/cJwvrGrPJ C2YaN4mqrdRD9cIe+T8+ASn7AiHYoj4Un71MgNXPdev/IYXGmeql9FA6DPmBxmBLjo cnCysJu1dCe7qzG+wWe5vJkQ5s8RiehJQr3ohfJTlrLYW6ZCffnWg4XK9X0kpugAO6 fhYAmX09Atqcw/LOWxWVVhZInZmpNgSc33GS1+4RRzE+tORLlII9tMjtys6wT9Kswh 72sDOFI+SBkbpknddIpBdkubuAknNTE3hWcEWX+bTCfiQuZW+CGNKt7V9jVvG4+uhW OyQNXwGbajpjg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Srinivasan Shanmugam , =?UTF-8?q?Christian=20K=C3=B6nig?= , Alex Deucher , Sasha Levin , Xinhui.Pan@amd.com, airlied@gmail.com, daniel@ffwll.ch, mario.limonciello@amd.com, Hawking.Zhang@amd.com, lijo.lazar@amd.com, candice.li@amd.com, le.ma@amd.com, victorchengchi.lu@amd.com, shashank.sharma@amd.com, andrealmeid@igalia.com, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Subject: [PATCH AUTOSEL 6.1 27/52] drm/amd/amdgpu: Fix potential ioremap() memory leaks in amdgpu_device_init() Date: Fri, 29 Mar 2024 08:45:21 -0400 Message-ID: <20240329124605.3091273-27-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240329124605.3091273-1-sashal@kernel.org> References: <20240329124605.3091273-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.1.83 Content-Transfer-Encoding: 8bit From: Srinivasan Shanmugam [ Upstream commit eb4f139888f636614dab3bcce97ff61cefc4b3a7 ] This ensures that the memory mapped by ioremap for adev->rmmio, is properly handled in amdgpu_device_init(). If the function exits early due to an error, the memory is unmapped. If the function completes successfully, the memory remains mapped. Reported by smatch: drivers/gpu/drm/amd/amdgpu/amdgpu_device.c:4337 amdgpu_device_init() warn: 'adev->rmmio' from ioremap() not released on lines: 4035,4045,4051,4058,4068,4337 Cc: Christian König Cc: Alex Deucher Signed-off-by: Srinivasan Shanmugam Reviewed-by: Christian König Signed-off-by: Alex Deucher Signed-off-by: Sasha Levin --- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c index 6a4749c0c5a58..ebca5594878dd 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c @@ -3712,8 +3712,10 @@ int amdgpu_device_init(struct amdgpu_device *adev, * early on during init and before calling to RREG32. */ adev->reset_domain = amdgpu_reset_create_reset_domain(SINGLE_DEVICE, "amdgpu-reset-dev"); - if (!adev->reset_domain) - return -ENOMEM; + if (!adev->reset_domain) { + r = -ENOMEM; + goto unmap_memory; + } /* detect hw virtualization here */ amdgpu_detect_virtualization(adev); @@ -3721,18 +3723,18 @@ int amdgpu_device_init(struct amdgpu_device *adev, r = amdgpu_device_get_job_timeout_settings(adev); if (r) { dev_err(adev->dev, "invalid lockup_timeout parameter syntax\n"); - return r; + goto unmap_memory; } /* early init functions */ r = amdgpu_device_ip_early_init(adev); if (r) - return r; + goto unmap_memory; /* Get rid of things like offb */ r = drm_aperture_remove_conflicting_pci_framebuffers(adev->pdev, &amdgpu_kms_driver); if (r) - return r; + goto unmap_memory; /* Enable TMZ based on IP_VERSION */ amdgpu_gmc_tmz_set(adev); @@ -3742,7 +3744,7 @@ int amdgpu_device_init(struct amdgpu_device *adev, if (adev->gmc.xgmi.supported) { r = adev->gfxhub.funcs->get_xgmi_info(adev); if (r) - return r; + goto unmap_memory; } /* enable PCIE atomic ops */ @@ -3998,6 +4000,8 @@ int amdgpu_device_init(struct amdgpu_device *adev, failed: amdgpu_vf_error_trans_all(adev); +unmap_memory: + iounmap(adev->rmmio); return r; } -- 2.43.0