From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (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 7F80C2E7BD3 for ; Fri, 10 Apr 2026 18:55:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775847339; cv=none; b=K5DoWqWUuA1PF3vdLC9QjTiA9jWuQ0mrBwdvK87Lt2SXi749p9E2l+Pma0SfcFefdwVMwLq+czAvZlbzt9fwhTX1DyGMMGRE8PH/MA5EXsGP/uhzh+TnfYQYd/2iEzCif82BU9c8+RosF+AGKMek8MWkIC5rUquuVtOsVJW2elM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775847339; c=relaxed/simple; bh=YSG45MJBEatZCG4sa3oABqo4fb0Ah/oxLXAK4L6WnXg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VQ3w/N5TKIZaWpb2y4rmjtP/2RvhiQHLFr6PelUNsKab+GieLpRhKLhRU1u8DvyQ3WQCJgrAZaMspEjrlGiqJDxyl3X6vArDSB41uQ0ddJi4mryMvY54C1AQG4ULrRtadBFxMq5UrXLP7jIjdjpcBzbFO9mikvZcgPlqpLjBaWc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=MTh3u9Qa; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="MTh3u9Qa" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=vjr6z6DnqGI+tg0xw2YLLXU5GqwQ5CapsaO62hUqwbQ=; b=MTh3u9QaDb1zQ8DKeJWABJt7Nr x7JXnibR/JC8nL2VPr1pNneH1WvhyINkmRCTgshRR7Wte2CkJJ4JDynITDCfLEKugJPwhidxt23SX GVVV0qI2flQNOPbWeQSZDkvzqEGdRIq1dXHEZIJxq672OfAs5kFaliMkErjnLEBHGX8eGqMUpddBF o3+y4mCfDNjyT9ndEI7qSVykzqppRhBNDIY6iYqbqjfgvHwJLXawPA1HdAtotRHVZtsfTKcE36MBl r818/9lPW9j7tQYM1cCwPHuGmuwAqRlhlfP9znj708LZ7/BL6kATWnHsnO0T7Sqqcl40J9Lw9BKXO yrHd5YUg==; Received: from [90.240.106.137] (helo=localhost) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1wBH0y-00EWTu-I8; Fri, 10 Apr 2026 20:55:36 +0200 From: Tvrtko Ursulin To: criu@lists.linux.dev Cc: Tvrtko Ursulin , David Francis Subject: [PATCH v2 07/23] plugins/amdgpu: Close the directory when image probing fails Date: Fri, 10 Apr 2026 19:54:58 +0100 Message-ID: <20260410185514.51153-8-tvrtko.ursulin@igalia.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260410185514.51153-1-tvrtko.ursulin@igalia.com> References: <20260410185514.51153-1-tvrtko.ursulin@igalia.com> Precedence: bulk X-Mailing-List: criu@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Close the directory when probing images during restore init fails. While at it, consolidate the identical code between the DRM and KFD images into a common helper. Signed-off-by: Tvrtko Ursulin Reviewed-By: David Francis --- plugins/amdgpu/amdgpu_plugin.c | 82 +++++++++++++++++++--------------- 1 file changed, 46 insertions(+), 36 deletions(-) diff --git a/plugins/amdgpu/amdgpu_plugin.c b/plugins/amdgpu/amdgpu_plugin.c index c875df060eed..1d95c04d1dbd 100644 --- a/plugins/amdgpu/amdgpu_plugin.c +++ b/plugins/amdgpu/amdgpu_plugin.c @@ -1121,15 +1121,47 @@ int amdgpu_id_for_handle(int handle) return -1; } +static int load_img(char *filename, unsigned char **out_buf, size_t *out_len) +{ + unsigned char *buf; + FILE *img_fp; + size_t len; + int ret; + + img_fp = open_img_file(filename, false, &len, true); + if (!img_fp) { + ret = -ENOENT; + goto out; + } + + buf = xmalloc(len); + if (!buf) { + ret = -ENOMEM; + goto out_close; + } + + ret = read_fp(img_fp, buf, len); + if (ret) { + xfree(buf); + } else { + *out_buf = buf; + *out_len = len; + } + +out_close: + fclose(img_fp); +out: + if (ret < 0) + pr_err("Unable to read from %s", filename); + + return ret; +} + int amdgpu_restore_init(void) { if (!shared_memory) { int protection = PROT_READ | PROT_WRITE; int visibility = MAP_SHARED | MAP_ANONYMOUS; - size_t img_size; - FILE *img_fp = NULL; - int ret; - unsigned char *buf; int num_handles = 0; CriuRenderNode *rd = NULL; CriuKfd *e = NULL; @@ -1139,51 +1171,29 @@ int amdgpu_restore_init(void) d = opendir("."); if (d) { while ((dir = readdir(d)) != NULL) { + unsigned char *buf; + size_t img_size; + int ret; + if (strncmp("amdgpu-kfd-", dir->d_name, strlen("amdgpu-kfd-")) == 0) { - img_fp = open_img_file(dir->d_name, false, &img_size, true); - if (!img_fp) - return -EINVAL; - - buf = xmalloc(img_size); - if (!buf) { - fclose(img_fp); - return -ENOMEM; - } - - ret = read_fp(img_fp, buf, img_size); - if (ret) { - pr_perror("Unable to read from %s", dir->d_name); - fclose(img_fp); - xfree(buf); + ret = load_img(dir->d_name, &buf, &img_size); + if (ret < 0) { + closedir(d); return ret; } - fclose(img_fp); e = criu_kfd__unpack(NULL, img_size, buf); num_handles += e->num_of_bos; criu_kfd__free_unpacked(e, NULL); xfree(buf); } if (strncmp("amdgpu-renderD-", dir->d_name, strlen("amdgpu-renderD-")) == 0) { - img_fp = open_img_file(dir->d_name, false, &img_size, true); - if (!img_fp) - return -EINVAL; - - buf = xmalloc(img_size); - if (!buf) { - fclose(img_fp); - return -ENOMEM; - } - - ret = read_fp(img_fp, buf, img_size); - if (ret) { - pr_perror("Unable to read from %s", dir->d_name); - fclose(img_fp); - xfree(buf); + ret = load_img(dir->d_name, &buf, &img_size); + if (ret < 0) { + closedir(d); return ret; } - fclose(img_fp); rd = criu_render_node__unpack(NULL, img_size, buf); num_handles += rd->num_of_bos; criu_render_node__free_unpacked(rd, NULL); -- 2.52.0