Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp217lqz; Fri, 29 Mar 2024 06:51:37 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVc8qGrg6uzG+8sCbA32dkTOJLl4cPFWU/cJgbYhNeQ039bCCR7kKjGNWpXLWVivgP2Slyugx8/exFGRc2TYaLglTKoos+pjarkQJPugw== X-Google-Smtp-Source: AGHT+IHIJuU0T/QrYh2XvIFteaDSU3ixgckZG4q5B+7VXUoC3F+FHoQXKciN7qG6ZHzGHrIAFCNG X-Received: by 2002:a05:6358:5614:b0:17f:3a71:3027 with SMTP id b20-20020a056358561400b0017f3a713027mr2575042rwf.19.1711720296806; Fri, 29 Mar 2024 06:51:36 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711720296; cv=pass; d=google.com; s=arc-20160816; b=nIwkG/JTJx+kKig14SSmie16THSiUnTycaq9gFtf37sa/v2uyHFwG0VVzHLyNwd6tU Fw2C/eJhryPEqAlCYmaqUxLARSJRPjLE1E3NgHTJy1uIPVPAJSw8ZgX5Yv+PLrQ4fmnS Uu8CUCv4laBIWk97N9VzvEmP0oBXQq5NsBFaMKyA11mwINdVAeVKrc/hjGzh80fqXTNC Juqo/xOSYQ8IOKe5LL4FaSj/1KDIa8jiNPe9L9ocD++4/A0fgmH3Anj6Jg/QizG7+SZu 3cgBuiRC92fMFMX/T844VJQp670v33MT6OV9LIhLznVxO8oeUN2E5FHGwKcXsaNfOIus ehKA== 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=JU4S0DmP9jgK2xAZEc2fngXg8lcK8QAZa3/bHSwMDng=; fh=5XbtNPaJxs4xa9JTzDXY3wSo9tajjxbP3f7AovZxqFE=; b=gj5hawaPXK91P9uCKwearNdKfygFq8T37qC1A7kc/gw7U/862Q7JSRXzyHy7clzE32 RA/JV+eE+9RNqo/EOQLBwbdY8OHU0ziQ3dfga+4XxYe6pO5Y1JUIf7W9rCnJWi9/SXFF BATURp9lyF7es8pL5U34tHwjfvCgk+MYyBD2+r+xb8tg7f2pVSqlSVsR5O7TLgRn+1Q/ kVuoH96Q+MKK61D72fTNoI5u4PTAEVPcHcumVmUbxO3RmYo5xNAM1S/DdeGbSYuGDFUr Eg4C/uxkPJkK0FIG+ryQ8VNlpUaZ4CUVwJHiNwUNIk5p11b1f8n1eqN70hM+bXXbNdxc hdvw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=EbSNCjXz; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-124772-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-124772-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. [139.178.88.99]) by mx.google.com with ESMTPS id u63-20020a637942000000b005dbf4efa1f8si3669181pgc.852.2024.03.29.06.51.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Mar 2024 06:51:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-124772-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=EbSNCjXz; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-124772-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-124772-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 D95162886B3 for ; Fri, 29 Mar 2024 13:47:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5750C1836F6; Fri, 29 Mar 2024 12:41:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="EbSNCjXz" 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 777431487C3; Fri, 29 Mar 2024 12:41:56 +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=1711716116; cv=none; b=bwrMuEAzBUzYmFwmF81jtFsr9suHTp+yIvmTKWjegEJSXx+FvAutMgzEB7gIWhEduCPdp8gmnWnjBxNJr4oLTE8CNRMZtdO+8Et6ub4TedXenKbHteRxbLJ3KGKV0mmRY9GPJ4gX8YfmRJjk+ewEUgRhcFS1uLaM3Kg4d1ZnHsU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711716116; c=relaxed/simple; bh=hv27gBKDYQLW2061t6d9jJ8tcdDAnzxAdPCX0nu7cU0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=d4H+3f+MVD59yewBOb9dh+eLMPqwLFYU4v9AE3Uk0uDu3uCR6laPRu6ux7Tib4r96tOWIGofRfIiElOTKWXoz3B3vQRlC1fI6MUmqjtYp8B1A4Wpus9L0ogVBgqEDDaLnsRcuFCl2kM6U/0QUPDJtjudQK+Q2aQhqtH689jpa2U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=EbSNCjXz; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2115BC433F1; Fri, 29 Mar 2024 12:41:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711716116; bh=hv27gBKDYQLW2061t6d9jJ8tcdDAnzxAdPCX0nu7cU0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EbSNCjXzbN8r2U3/ds6q6voMyp5LhZMsVxQrZsV6RZF3K16Ik2spfw82JNPF81o2S Lcs6gH7CnmVjaCXnBacsxEq57ZjqWIqD6i4T/R652bEmlXV90Hz0LxzpMO7HOIwJdS /qDo12bAZxzcW5bx6MfPAatxUCqp7UePq4fWqAA0h2Ciz7QuKi9S2hcn/GEi0tQBhG zANha42EgMfjqY0NnBVQVvc/Rl5kIiuOoMotxovgWsjELHL6ZdRmpYeVi38BFVRLey gRR57YORFcxtrt5EdKsrnuKbGx/FIUHmheCl+Qn4zejyfYLWJjfQLahRBxaBhsKjKM wphNsM0591n0w== 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.8 62/98] drm/amd/amdgpu: Fix potential ioremap() memory leaks in amdgpu_device_init() Date: Fri, 29 Mar 2024 08:37:33 -0400 Message-ID: <20240329123919.3087149-62-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240329123919.3087149-1-sashal@kernel.org> References: <20240329123919.3087149-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.8.2 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 5c381216df623..1d681298a4893 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c @@ -4025,8 +4025,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); @@ -4036,20 +4038,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); @@ -4059,7 +4061,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 */ @@ -4328,6 +4330,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