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 3FBDA331202 for ; Fri, 20 Feb 2026 12:05:32 +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=1771589133; cv=none; b=jKqpY6qSw34GUhzTlS8qcdyN3bxT5YXUVZ17Dpx9dW1qZ71BQRj0+xuLaRhn7DPycrVu6cqrXvW/HFpGU4LL3nMzaNpwM7PqnjekHIbfiDvZYMxuAHP5PLgUy6nHdUIleqsyQWDj/Q1nZtZoDnqSd5+nKmoSeqDxI1uN8gZfFP8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771589133; c=relaxed/simple; bh=0Y9bv6X+6xkBTTTd57iYgJ7w+Y0tG0eK7gbKW4uyNPo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lzxRL1KkVkbOmT7M7DFyu5IZhsIW1jLWQ0FbTEUxZFAhK+EQCz/x+VT+8L77CFuoMunvorWzzZj05Gsh/KPHaJccM2FCsBEltfi5fCH2cB/swJYhi3x8cZtFmyTZw6g+NbKh8a8HFuoMCWc+XTHmELKzGFu4ZdBZAbkLqD/tpkg= 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=HOLk1UIU; 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="HOLk1UIU" 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=yxTISjp9SAUpuFXEjSEZ+gNBLl0enjtLXzurhw7ychU=; b=HOLk1UIUpSD+id+B2pD8ikmqLW nWjCaXeOLl6n4MVD7e1DmU1ILO5hvXAQjI2ynXo9ekOuBZohZgftHNY2st0TovauRBFiGYMOUubai jNguYqBCczveJ0tIKUfEgtzj+BHXCjgaiu/KkbY6CuB7aDJ+7+qTw+/6b60mItMtmRTSxhKHQRKPY 7xYrySIDd5sK6hfDNs+YYwx1tk7gV2V29lnRu4vuQzgDen5aKPALeqbJru5GYumeDsVl5573Qtz2A q1d+BO/vt7qljOZNH2rp++IC7oF4kVXyl+mDdQRmBdfSxRwOD/2TLIlonTpCIiTx2dtxbhxNs00Ao QueESeJg==; 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 1vtPGE-002uyp-6e; Fri, 20 Feb 2026 13:05:30 +0100 From: Tvrtko Ursulin To: criu@lists.linux.dev Cc: David Francis , Tvrtko Ursulin Subject: [RFC 07/26] plugins/amdgpu: Close the directory when image probing fails Date: Fri, 20 Feb 2026 12:04:55 +0000 Message-ID: <20260220120514.4540-8-tvrtko.ursulin@igalia.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260220120514.4540-1-tvrtko.ursulin@igalia.com> References: <20260220120514.4540-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 --- plugins/amdgpu/amdgpu_plugin.c | 76 ++++++++++++++++++++-------------- 1 file changed, 46 insertions(+), 30 deletions(-) diff --git a/plugins/amdgpu/amdgpu_plugin.c b/plugins/amdgpu/amdgpu_plugin.c index b13ec66e3336..dcc8940e735b 100644 --- a/plugins/amdgpu/amdgpu_plugin.c +++ b/plugins/amdgpu/amdgpu_plugin.c @@ -1119,15 +1119,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); + 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; @@ -1137,45 +1169,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); - 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); - 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