Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp12582lqz; Fri, 29 Mar 2024 07:10:01 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWFxJ42HXkuxSs63h8h8sXdnpXz6+uWZ5lKY0ER4WddmkDvsOTIn5zT44eQHg1Rvh2E9g0+CSXVsZ3oDgRjw19+Z/gq02urnlsQ+6IHDw== X-Google-Smtp-Source: AGHT+IHinfUhegMjQ6dYs3343Wi+7a+exmMzLh0oHaLYbQZUeJUOU5fCqGOjbPfCmOWoBBRm7RZR X-Received: by 2002:ae9:e411:0:b0:78a:33cd:5e6 with SMTP id q17-20020ae9e411000000b0078a33cd05e6mr2620875qkc.41.1711721401177; Fri, 29 Mar 2024 07:10:01 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711721401; cv=pass; d=google.com; s=arc-20160816; b=P2HIj80NLrpsDa5yZjpdznWl326VmI/JwOrBCoxZLYWhIf25JwOEwxahQ8oBpEN3KJ vwerpaktA/APCK4R6w3gg3le7kIBtIu+aVI+FtZrioZ+BDaEmOn+8vEmYZNmGTKNxD6g PhiftgLhvcvLOJ64MsQJR+9CXsaIWexNd/t8CmBbINtgE3N1a2kxKvSRYNtMiLrb3Lv9 47M9B+kVLohoh4tJE78MthUr0ZgbXUJ6GkNCcemCDOy7lJDoG/rMoZYpByzFH66LN7rl 9n18sgr4YFlcS9K0+FvHCOZX7YYFP8UIeUKg6hgt/5+ZSsc0w/UeN39Xoej7hwGjoKhV ahBA== 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=zBWqDxkWnq/NpV9Ceqwhh/FbSexg9AoGfWCBg0wVcIM=; fh=5XbtNPaJxs4xa9JTzDXY3wSo9tajjxbP3f7AovZxqFE=; b=D8zYehZyqdhJo/n+AoBkEOCaE5JTx5QebszzuWaX1eptOwl//rSsp5IYyIhz1hvbio MOsWvoxLvcjO+wJcF4UkI+cgc/BJe+JgsHEIcTGFIny2XMXex7uXoEuuDQnfu57zxmQG FmdfZoZc8dhjVi4fUptgwWbc3JkA7jzq2E912/h+7lG8XklgxDdjRnueSFeAxFVoWzOQ NFsP53zGGkrbopjmJF874U3qs6UqjDjWjel0G5ShMToD55zAmLVWWEU1ER8KLCdXPry7 yH0WiQ9OvdtIyUJE1rnbngyUsgm22ULj0SlpNw9UBDmSMEZdiI8HWZu7rrHOfUFvPEia 4poA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ZbkLe1u6; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-124853-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-124853-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id f9-20020a05620a12e900b00789fac3a516si3679326qkl.460.2024.03.29.07.10.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Mar 2024 07:10:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-124853-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ZbkLe1u6; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-124853-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-124853-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id E2A001C24FE6 for ; Fri, 29 Mar 2024 14:10:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 260771C2306; Fri, 29 Mar 2024 12:44:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ZbkLe1u6" 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 4E70214A4D3; Fri, 29 Mar 2024 12:44:55 +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=1711716295; cv=none; b=c9Hkq+Iaqqb79ulGYXXaoxR0m9iynzDYhDeAOQJmISEUB0t5O1IZvWm4ZYLONllRFmfRL60geR1b26j3fkQfoll3PoZy3YTMeFvyQ6TzZcmp2hEXhmAwachqZfva8YXr8PFcDN2JaYEwrPW0VTeIEQHke55k6uFl5Qmaats3PbM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711716295; c=relaxed/simple; bh=AoqCat9N4163RwRCB55sNuaZ5loXmqTak4HXhAlS090=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=NRAn4Qhpx02IGaSFm9HUqmQnRJSlK35RaxlBNaeM0fWb86Whp8QRxzrsLyl1CIrz2Ii2Pz584emknVO8BeiGGqMDDQ3q1LwCOKCU78Nzue7pjWHHBELHmxRG+6DLp6WhPLOOXqKsq72H2jS2PQUpobKNstJGTqMeySMXEmpB+Vg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZbkLe1u6; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4A403C433C7; Fri, 29 Mar 2024 12:44:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711716295; bh=AoqCat9N4163RwRCB55sNuaZ5loXmqTak4HXhAlS090=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZbkLe1u6yHtAMMvC8WM3JDk1y4NxKCjFybthP5vmEUilXqChKhTI3/2W7KQQAjnr1 Vzx6hYjsb20pl+wt0g1eCC/1Mcmg075dDyImZd5Rab45m36kNukddQv8DrgjLGQjiE cjW6/kJ6VkO7LbpSGDu9lyOW3XdD0QuRS2+n9IJygBVu+UsJ2xjP3zaDhabwQO8rwd 2spIGJncOaNngm/P7SlSmftMkr0rZQPtfPjfjZoLPBcrJqTMe8WjgQi0VE0mb6MLY2 6nh87nBOzcjBIBlAb+cxBCBSFH1J7H2bhg1DkA0beRhKp0Hv9wQhXzg1cUI0AIw2Q3 Jn/BHLjDwbgOw== 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.6 44/75] drm/amd/amdgpu: Fix potential ioremap() memory leaks in amdgpu_device_init() Date: Fri, 29 Mar 2024 08:42:25 -0400 Message-ID: <20240329124330.3089520-44-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240329124330.3089520-1-sashal@kernel.org> References: <20240329124330.3089520-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.6.23 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 79261bec26542..d0be5e485530c 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c @@ -3638,8 +3638,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); @@ -3649,20 +3651,20 @@ 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; amdgpu_device_set_mcbp(adev); /* 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); @@ -3672,7 +3674,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 */ @@ -3929,6 +3931,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