From nobody Wed Nov 19 15:17:58 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1616160703; cv=none; d=zohomail.com; s=zohoarc; b=YQxihp4iEEcLgdlc6Wf5fYif+v4/MFbH3IYkxnClt3Z1BQ0I/z2uvTgdZn3sqObWbuMgSunEo3OmEqnB/7LFr2O4fMk9z34//+wcC4qe1j0s7ddV1LIHT3/XCOgtIVRHQZ7sM/7drh+0ulV589uNxgFsaOwm0A8CjZeCtbzTaEU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616160703; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=eiWZx+mACoCrFVRPV7yfaFTS0OqnVjieeU+w0fMK/vM=; b=X4h+0f+FD2W54qhaAVdrJS+q1KyLfD3mFLaMOcUX9c9pFEt5D1CBaRTqn/EN6W+1YDsT6xrwvDPMLaM4SccixJyoCkZwUt1DbtECD3mDbjZB7ZVy9EybxHgrj4yr4hRF9kjI/Xk+xRW36cEmsbh1Ah0vtWdNF14rXn6EOHYQCH0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1616160703109583.006644983374; Fri, 19 Mar 2021 06:31:43 -0700 (PDT) Received: from localhost ([::1]:41810 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lNFE5-0006lA-9a for importer@patchew.org; Fri, 19 Mar 2021 09:31:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:32980) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lNF9C-0001HU-Uz for qemu-devel@nongnu.org; Fri, 19 Mar 2021 09:26:38 -0400 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]:42594) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lNF99-0004Ck-MU for qemu-devel@nongnu.org; Fri, 19 Mar 2021 09:26:38 -0400 Received: by mail-wr1-x42f.google.com with SMTP id x13so9113053wrs.9 for ; Fri, 19 Mar 2021 06:26:34 -0700 (PDT) Received: from localhost.localdomain ([102.47.92.134]) by smtp.googlemail.com with ESMTPSA id v13sm8889584wrt.45.2021.03.19.06.26.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Mar 2021 06:26:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=eiWZx+mACoCrFVRPV7yfaFTS0OqnVjieeU+w0fMK/vM=; b=R2B8n6+PVJ33LQk3cWXqWrBdDPLZ0Py5YEC58bBd5rbxEjDrx3N/U4ejPPOAYB53Hm 13r9r5qS9eAxuDZrpz6RjTNhXgWKLmEJ+qW/kp0cru0G4RKrzT2JW9QlZJHJEzjQ0cQd FkVMxzqQLePjYzzbTqqR4xpyaHPZOKODu4dPu6Afahh7MXv8sudVBBg3I5c/j+aY8TB5 hVhfIfSsBOLbRf+1/Vh3bxiBE4980hb/ywaXaqZUMjZ1sL6zgVQln+zI+2Oi1pA+Z10T 2pFiigMgAPw7jz5WcV92od26iVQid/Xx98KXXe4d+SJJXUZYUjP2qRq6gNzp1mhrKb1S 7K1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=eiWZx+mACoCrFVRPV7yfaFTS0OqnVjieeU+w0fMK/vM=; b=T8jWeJrceRgC28eBenCwEwtir2JRbiUQkll6nzO2xrHrTHf/JU2Zz1xUFC7T8DJhwj V2kxFp9oLIZ3pSrVMmg4SeN1VcmL7hbrX6NAtKGlFjNfY6D/HSynNE0tsetFRpyNoUAc BctLjaBPCy/lkefdx2v7Oh8wLjfUG8ie8UYwgJ0lrp0ReQCABi+T4vLy5H+QFlK6PA0T gbqkqKfogU5jjnxRaYk1O7Iflo9d7ilBCHnk4s9FzRGx3ExXHgbAIpR8aFPRrP2kztjk DGlobPQ+IplupsRdlnNrmBZjUzXvgjE7/dG8woW2bqSn0qtW3rqrwg5lf6V3mJm3SEe+ xzgA== X-Gm-Message-State: AOAM530jxxuFzonjqHvF8Fddc2iZbU5IX4I4WTdWUAiLkESCUvzpnnth TQGsEVzX1zAfhwE722b5g4DZnRYEyUw= X-Google-Smtp-Source: ABdhPJwg+2c68Wc56HxZ5vNFPS4yCseuk7pNaBWZ4n2jj9zjSl8XT/xHHxPA272eTXxquR5n+A72vQ== X-Received: by 2002:adf:ea0e:: with SMTP id q14mr4602850wrm.389.1616160393236; Fri, 19 Mar 2021 06:26:33 -0700 (PDT) From: Mahmoud Mandour To: qemu-devel@nongnu.org Subject: [PATCH 6/8] virtiofsd: Changed allocations of fv_VuDev & its internals to GLib functions Date: Fri, 19 Mar 2021 15:25:25 +0200 Message-Id: <20210319132527.3118-7-ma.mandourr@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210319132527.3118-1-ma.mandourr@gmail.com> References: <20210319132527.3118-1-ma.mandourr@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::42f; envelope-from=ma.mandourr@gmail.com; helo=mail-wr1-x42f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mahmoud Mandour Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) Content-Type: text/plain; charset="utf-8" Changed the allocations of fv_VuDev structs, VuDev structs, and fv_QueueInfo strcuts from using calloc()/realloc() & free() to using the equivalent functions from GLib. In instances, removed the pair of allocation and assertion for non-NULL checking with a GLib function that aborts on error. Removed NULL-checking for fv_VuDev struct allocation and used a GLib function that crashes on error; namely, g_new0(). This is because allocating one struct should not be a problem on an healthy system. Also following the pattern of aborting-on-null behaviour that is taken with allocating VuDev structs and fv_QueueInfo structs. Signed-off-by: Mahmoud Mandour Reviewed-by: Stefan Hajnoczi --- tools/virtiofsd/fuse_virtio.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/tools/virtiofsd/fuse_virtio.c b/tools/virtiofsd/fuse_virtio.c index 07e5d91a9f..5828b9a76f 100644 --- a/tools/virtiofsd/fuse_virtio.c +++ b/tools/virtiofsd/fuse_virtio.c @@ -729,7 +729,7 @@ static void fv_queue_cleanup_thread(struct fv_VuDev *vu= d, int qidx) pthread_mutex_destroy(&ourqi->vq_lock); close(ourqi->kill_fd); ourqi->kick_fd =3D -1; - free(vud->qi[qidx]); + g_free(vud->qi[qidx]); vud->qi[qidx] =3D NULL; } =20 @@ -760,15 +760,13 @@ static void fv_queue_set_started(VuDev *dev, int qidx= , bool started) if (started) { /* Fire up a thread to watch this queue */ if (qidx >=3D vud->nqueues) { - vud->qi =3D realloc(vud->qi, (qidx + 1) * sizeof(vud->qi[0])); - assert(vud->qi); + vud->qi =3D g_realloc_n(vud->qi, qidx + 1, sizeof(vud->qi[0])); memset(vud->qi + vud->nqueues, 0, sizeof(vud->qi[0]) * (1 + (qidx - vud->nqueues))); vud->nqueues =3D qidx + 1; } if (!vud->qi[qidx]) { - vud->qi[qidx] =3D calloc(sizeof(struct fv_QueueInfo), 1); - assert(vud->qi[qidx]); + vud->qi[qidx] =3D g_new0(struct fv_QueueInfo, 1); vud->qi[qidx]->virtio_dev =3D vud; vud->qi[qidx]->qidx =3D qidx; } else { @@ -1034,12 +1032,7 @@ int virtio_session_mount(struct fuse_session *se) __func__); =20 /* TODO: Some cleanup/deallocation! */ - se->virtio_dev =3D calloc(sizeof(struct fv_VuDev), 1); - if (!se->virtio_dev) { - fuse_log(FUSE_LOG_ERR, "%s: virtio_dev calloc failed\n", __func__); - close(data_sock); - return -1; - } + se->virtio_dev =3D g_new0(struct fv_VuDev, 1); =20 se->vu_socketfd =3D data_sock; se->virtio_dev->se =3D se; @@ -1061,8 +1054,8 @@ void virtio_session_close(struct fuse_session *se) return; } =20 - free(se->virtio_dev->qi); + g_free(se->virtio_dev->qi); pthread_rwlock_destroy(&se->virtio_dev->vu_dispatch_rwlock); - free(se->virtio_dev); + g_free(se->virtio_dev); se->virtio_dev =3D NULL; } --=20 2.25.1