Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 ED8224349 for ; Thu, 17 Feb 2022 15:38:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1645112335; 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=CoTxwG5lqMogkG1tkhH6Op74mbfSGaKHCACVBM5sEqs=; b=i8zWxnN1EQrC4lpbglJ4scP44oGKStEg3l5HQbckAaRYJcLgiaA9Gov7IR/H8xciHBKm6x ceE3fNHDGH909nEm0xTDKQ/obWMVjgo8iENI0vidssqKn2mICn60uXqMs1SOsbG8FWPAiX j6TCMm5WFPosnwayi1KetGGhMRN7yWk= Received: from mail-ot1-f72.google.com (mail-ot1-f72.google.com [209.85.210.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-481-4Gx92fE_Mw-DzEkIyWWmVg-1; Thu, 17 Feb 2022 10:38:54 -0500 X-MC-Unique: 4Gx92fE_Mw-DzEkIyWWmVg-1 Received: by mail-ot1-f72.google.com with SMTP id v17-20020a9d6051000000b005acf76789e9so7305otj.1 for ; Thu, 17 Feb 2022 07:38:54 -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=CoTxwG5lqMogkG1tkhH6Op74mbfSGaKHCACVBM5sEqs=; b=mJw8Wy6upiZEyzb3GrIXdGdDT7Ms2I2f9rYV1TUeTvmbFMhtZildpww5OzBJ5GHXem cQjNOtEoUG/cxfjK2mb90um/MH3jgA69A8FXq1pWTw6ZQ1KSpfzMTvrpUEg9el0hC774 wm76BoM2p/G+j7vhz3QaO8RzWKsKhlr/Bdktfy0QhFGX+v6nHdua9PzZzxir2DiHNIQb yrT3Fx0LCq+9sKV3sTX4sKUaAOfQfTt/KvO8aois8KlMuQt+hxJJlmnMAY2xXUAIq1fB 4rUWAJjzvaHhUxoUpZJdtOtFRkEm9PAfml3wPAik4rcgx6mAh88lgHUszHHLcGS4Y+XL r8Tg== X-Gm-Message-State: AOAM530sr/Cz3ZrbWyI5T1u5JXNX6goVinTOyQzSNHO7wAfNhstMfGIN kL4stYHTGOeSg+ygaDs1AWrT3Eb0i7WdPTRSLddpAdwf2Ca2IUq5CffZmR8Y/G1sTh8h2iYx+Nu 5c81+tT+WWPeohQ== X-Received: by 2002:a05:6830:41:b0:5a0:93fa:161d with SMTP id d1-20020a056830004100b005a093fa161dmr1020924otp.88.1645112333718; Thu, 17 Feb 2022 07:38:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJzNPtTeWpYlbfs2THVEoksmj7PsLvm2GLCm7n8pIk1AhH37AWo21W37FGBs4lG0Kd2SS1+XmQ== X-Received: by 2002:a05:6830:41:b0:5a0:93fa:161d with SMTP id d1-20020a056830004100b005a093fa161dmr1020900otp.88.1645112333470; Thu, 17 Feb 2022 07:38:53 -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 q28sm2691306ots.76.2022.02.17.07.38.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Feb 2022 07:38:53 -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, Hawking.Zhang@amd.com, john.clements@amd.com, tao.zhou1@amd.com, YiPeng.Chai@amd.com, luben.tuikov@amd.com, Stanley.Yang@amd.com, Dennis.Li@amd.com, mukul.joshi@amd.com, nirmoy.das@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] drm/amdgpu: fix amdgpu_ras_block_late_init error handler Date: Thu, 17 Feb 2022 07:38:42 -0800 Message-Id: <20220217153842.3252424-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 build fails with amdgpu_ras.c:2416:7: error: variable 'ras_obj' is used uninitialized whenever 'if' condition is true if (adev->in_suspend || amdgpu_in_reset(adev)) { ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ amdgpu_ras.c:2453:6: note: uninitialized use occurs here if (ras_obj->ras_cb) ^~~~~~~ There is a logic error in the error handler's labels. ex/ The sysfs: is the last goto label in the normal code but is the middle of error handler. Rework the error handler. cleanup: is the first error, so it's handler should be last. interrupt: is the second error, it's handler is next. interrupt: handles the failure of amdgpu_ras_interrupt_add_hander() by calling amdgpu_ras_interrupt_remove_handler(). This is wrong, remove() assumes the interrupt has been setup, not torn down by add(). Change the goto label to cleanup. sysfs is the last error, it's handler should be first. sysfs: handles the failure of amdgpu_ras_sysfs_create() by calling amdgpu_ras_sysfs_remove(). But when the create() fails there is nothing added so there is nothing to remove. This error handler is not needed. Remove the error handler and change goto label to interrupt. Fixes: b293e891b057 ("drm/amdgpu: add helper function to do common ras_late_init/fini (v3)") Signed-off-by: Tom Rix --- drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c index b5cd21cb6e58..c5c8a666110f 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c @@ -2432,12 +2432,12 @@ int amdgpu_ras_block_late_init(struct amdgpu_device *adev, if (ras_obj->ras_cb) { r = amdgpu_ras_interrupt_add_handler(adev, ras_block); if (r) - goto interrupt; + goto cleanup; } r = amdgpu_ras_sysfs_create(adev, ras_block); if (r) - goto sysfs; + goto interrupt; /* Those are the cached values at init. */ @@ -2447,12 +2447,11 @@ int amdgpu_ras_block_late_init(struct amdgpu_device *adev, } return 0; -cleanup: - amdgpu_ras_sysfs_remove(adev, ras_block); -sysfs: + +interrupt: if (ras_obj->ras_cb) amdgpu_ras_interrupt_remove_handler(adev, ras_block); -interrupt: +cleanup: amdgpu_ras_feature_enable(adev, ras_block, 0); return r; } -- 2.26.3