From nobody Mon Apr 29 09:47:31 2024 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=1616160830; cv=none; d=zohomail.com; s=zohoarc; b=CjD55ganOvo7mEhum4PN35DxfmT/JODIbfK6c1J2Yf1je/AykDRUfpAm/Syl4Hs1PBS06SolHdyV0NOD3gCQFFWwfEzkn3BQiL0n9YFirQ8Vy4GoK8sP2FHX9bDNUFojhn1Ho3Fs56gensbo1InzoXnLNKaSe41zT1ehwAMgnc0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616160830; 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=zPz2JDY4qZl9EO9V+0iDtCjid2U+jmokq/nSA43V4JA=; b=ng5hvQkI17SJTut7NMa0ZQ4drgc2rb42QJ7CD07tCwcWjiUT9MwtVd4G7gbEwXEmseMaNuVEfFOVHNwn2p5i1JMGCQ46rHE8Yl5OZo86p3g1thVXLHjuqmsqdFQ9JM8bFV4KK8aKf/yPqqtG2/GlpzGOS9/fVZJN/EcwxcjhQAg= 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 1616160830784582.8000497106738; Fri, 19 Mar 2021 06:33:50 -0700 (PDT) Received: from localhost ([::1]:48766 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lNFG9-00019O-Km for importer@patchew.org; Fri, 19 Mar 2021 09:33:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:32816) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lNF8x-0000yw-9k for qemu-devel@nongnu.org; Fri, 19 Mar 2021 09:26:23 -0400 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]:34593) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lNF8n-0003wV-Ay for qemu-devel@nongnu.org; Fri, 19 Mar 2021 09:26:23 -0400 Received: by mail-wm1-x333.google.com with SMTP id n11-20020a05600c4f8bb029010e5cf86347so8385379wmq.1 for ; Fri, 19 Mar 2021 06:26:12 -0700 (PDT) Received: from localhost.localdomain ([102.47.92.134]) by smtp.googlemail.com with ESMTPSA id v13sm8889584wrt.45.2021.03.19.06.26.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Mar 2021 06:26:11 -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=zPz2JDY4qZl9EO9V+0iDtCjid2U+jmokq/nSA43V4JA=; b=VFjFHRsevYNfm2YPKvnRzOa7XrI+03W/j8Q8FfE8+zG2n41LCw71lau0dkEs1rcgcL 3UPwcDqneGqCV5ZoH6n37S3hS/CXhHN/7XlEvEzRDCNVBq2UnMiNmwtr4jGLO0TCkEwh 0j3bqDcS6Y+YEgFxVujMYIONjTVyiJhMyHUKbJ25D7tjBTe+1HX2mAOyuAlfcDzxHaf5 fwQexeri5SnIxOSA7J0kHMz6FU8BnZRX42TbJoEOjv5bN0SjwpkRZy+E8IZWOIVC4UYU NIwpnGQi79XR8S50RarNgpgIU40dcowUMO2wK1xS/EyMF/TFGeK5ekBlK+Ru35gigFML lbAQ== 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=zPz2JDY4qZl9EO9V+0iDtCjid2U+jmokq/nSA43V4JA=; b=tiK1RL0K9fuecAsAVYiQRz2yh+KxgWNhM4CIN2bI6iSfRRP4SQDvai8sF3yaTMaoko sg6qAa3d1nt2fMT5VA4/d0PM7rM0dEptZ9mTxAV9TQLJXVvRrLKeXqJTmPMox/Hc58Yg pVZWrSaxgYx6OTYhBgOOMTsuIEwOHeMu4RDYF6jvxvkVSSOwtz41H+bqO8DhKJbjdEFF NlgT1AhcjjBuxQ2bSYE/l4I9AccnhtRVsit6Pk6XQ6++whI6LeheKWAPlJe+SORYNzyU kLvtqAOcx+CNJTfkAGkJUiKYi2wM+lcdpPDr2TejS9O87TBCIEGjbE6PFhR5jSr0hWp+ vyIw== X-Gm-Message-State: AOAM533viyuYfSelptzqbz86y6C0Ufq6F3/ygQzJQmxT49+0lMTUhGq+ y0Du/X9IE3rnKj6gfKETJiCdRqtLRjs= X-Google-Smtp-Source: ABdhPJy8T+PVD7Tu0SMcSPI79lQzZY1uHEzVY397hkzJoQuSJFvxWg7CwaDn0LAgVIeU0iGP6Jpr5Q== X-Received: by 2002:a1c:c244:: with SMTP id s65mr3770884wmf.96.1616160371326; Fri, 19 Mar 2021 06:26:11 -0700 (PDT) From: Mahmoud Mandour To: qemu-devel@nongnu.org Subject: [PATCH 1/8] virtiofsd: Changed allocations of fuse_req to GLib functions Date: Fri, 19 Mar 2021 15:25:20 +0200 Message-Id: <20210319132527.3118-2-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::333; envelope-from=ma.mandourr@gmail.com; helo=mail-wm1-x333.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" Replaced the allocation and deallocation of fuse_req structs using calloc()/free() call pairs to a GLib's g_try_new0() and g_free(). Signed-off-by: Mahmoud Mandour --- tools/virtiofsd/fuse_lowlevel.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/virtiofsd/fuse_lowlevel.c b/tools/virtiofsd/fuse_lowleve= l.c index 1aa26c6333..ba20c73778 100644 --- a/tools/virtiofsd/fuse_lowlevel.c +++ b/tools/virtiofsd/fuse_lowlevel.c @@ -106,7 +106,7 @@ static void list_add_req(struct fuse_req *req, struct f= use_req *next) static void destroy_req(fuse_req_t req) { pthread_mutex_destroy(&req->lock); - free(req); + g_free(req); } =20 void fuse_free_req(fuse_req_t req) @@ -130,7 +130,7 @@ static struct fuse_req *fuse_ll_alloc_req(struct fuse_s= ession *se) { struct fuse_req *req; =20 - req =3D (struct fuse_req *)calloc(1, sizeof(struct fuse_req)); + req =3D g_try_new0(struct fuse_req, 1); if (req =3D=3D NULL) { fuse_log(FUSE_LOG_ERR, "fuse: failed to allocate request\n"); } else { @@ -1684,7 +1684,7 @@ static struct fuse_req *check_interrupt(struct fuse_s= ession *se, if (curr->u.i.unique =3D=3D req->unique) { req->interrupted =3D 1; list_del_req(curr); - free(curr); + g_free(curr); return NULL; } } --=20 2.25.1 From nobody Mon Apr 29 09:47:31 2024 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=1616160972; cv=none; d=zohomail.com; s=zohoarc; b=dkuryPFNw9rXpw/4jYkqHWVtUgJB6L6WuxeZoB/YItWEcLP5vnXzsCSxmH8aAufLOP87NYAvZ06YQfqhNzBOQGyfM9tMclLjX+GEPSYtCH293MrJMHhLwo7cpYG+dDrBobp0z5SzhiBAcix9yNwnaqYlzpI97auNJzYX4jve8Ss= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616160972; 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=cSkDb2cN4/m5oNeRgBE6KjrYKYozQlVRVVXme8ca8DY=; b=J1TlpkvFQx4nlPM5W5CPhqtCJG+m2I2OjTXm8xiq2Rs+BRpCgY6JaIqwxHUVJoAUDqiiJFiHIMfxsKCOTvSVlQ04FTaZE/slt5ATMBv1rjZh9bHLtGGN2jdE5bKba6hrYYRAMsV6g13JbtnAg5ZgUQBU962RHqBF6uFASmHT7UE= 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 1616160972822508.9806224413652; Fri, 19 Mar 2021 06:36:12 -0700 (PDT) Received: from localhost ([::1]:57366 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lNFIR-0004cU-Qm for importer@patchew.org; Fri, 19 Mar 2021 09:36:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:32934) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lNF9B-0001EN-Ck for qemu-devel@nongnu.org; Fri, 19 Mar 2021 09:26:37 -0400 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]:39583) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lNF96-0004B3-L4 for qemu-devel@nongnu.org; Fri, 19 Mar 2021 09:26:37 -0400 Received: by mail-wm1-x334.google.com with SMTP id d8-20020a1c1d080000b029010f15546281so4999908wmd.4 for ; Fri, 19 Mar 2021 06:26:30 -0700 (PDT) Received: from localhost.localdomain ([102.47.92.134]) by smtp.googlemail.com with ESMTPSA id v13sm8889584wrt.45.2021.03.19.06.26.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Mar 2021 06:26:29 -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=cSkDb2cN4/m5oNeRgBE6KjrYKYozQlVRVVXme8ca8DY=; b=E7PpszS5JGLnvUfZ+vF05l10YIoTfJ8YSsGBf0CUIWqqUZF+dqGIME6A5G5BfbASN8 YF2y1q57eWnBENDJGBmtKgdawI9kTMRYaXcWZi/zNupxUlyt9P7c/zDXjiT/b9QWKpBI S4pcvjBiUDc2NbXCINRl60WcijX/V0TAYIbht3a3c5sBuRPoZJCJ8KWptT5wG/K+VbLx LeAuvnzgSQZlNbPfSg1PhIhccbPxXFSCRx4uaH2raxcTSMP0FIpIi1VyyWKJ/aArAcv1 D3mnYxZD12YYSsmVkqVfCdVaYULHzp7xeWbz5c48JbvcbOoqUyna5MNTuyG+8gf3QoqQ 0mrQ== 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=cSkDb2cN4/m5oNeRgBE6KjrYKYozQlVRVVXme8ca8DY=; b=ho9bWusFw6NIEOyulv5H+745LTLHws/AV9dbO5wTbbNJ3Whvh2HIIf77deSoJnX4xj oeZCBzVSQDYGseP7cc9qtnmNz/iqWQWAcuF4e8I4OjWGcVN0BIRX4n+BAVBOkjl7Iss9 gak5ukybiKwD4gEQDmG66x1bbAv1ZS4PFocZoTcDKF+h5Jroqg3W1wv1tW7CpNT9Wlwg AJr62bX64BAqIy9b2bi/HMvrenf2477CWKEIL3N7F/hOdfdeJXIUHwievbaLtiTPS6NO FXse3fXoBT+ZzRfcXkuoEmzfH4bwQxMF4qIgiRWTzlPYRkhjcMnEC1EkLPOh893HM5fA +N1Q== X-Gm-Message-State: AOAM533vx+1XNA/umlqMdAg8uk4aWVd+QMyrbXFfSQvsuGa0SMcSX/hF JOyqqYYoQEXbdLAH6lVhU/Z6sRwelrg= X-Google-Smtp-Source: ABdhPJxPsSQwij9dOPOeoiaTZwhM30XbWpNqev/P/csaF8T0yMY6y6ziJWDt2SGIf8Pi1DP3HmJiSg== X-Received: by 2002:a1c:9d51:: with SMTP id g78mr3904083wme.5.1616160389310; Fri, 19 Mar 2021 06:26:29 -0700 (PDT) From: Mahmoud Mandour To: qemu-devel@nongnu.org Subject: [PATCH 2/8] virtiofds: Changed allocations of iovec to GLib's functions Date: Fri, 19 Mar 2021 15:25:21 +0200 Message-Id: <20210319132527.3118-3-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::334; envelope-from=ma.mandourr@gmail.com; helo=mail-wm1-x334.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" Replaced the calls to malloc()/calloc() and their respective calls to free() of iovec structs with GLib's allocation and deallocation functions. Also, in one instance, used g_new0() instead of a calloc() call plus a null-checking assertion. iovec structs were created locally and freed as the function ends. Hence, I used g_autofree and removed the respective calls to free(). In one instance, a struct fuse_ioctl_iovec pointer is returned from a function, namely, fuse_ioctl_iovec_copy. There, I used g_steal_pointer() in conjunction with g_autofree, this gives the ownership of the pointer to the calling function and still auto-frees the memory when the calling function finishes (maintaining the symantics of previous code). Signed-off-by: Mahmoud Mandour Reviewed-by: Stefan Hajnoczi --- tools/virtiofsd/fuse_lowlevel.c | 19 +++++++------------ tools/virtiofsd/fuse_virtio.c | 6 +----- 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/tools/virtiofsd/fuse_lowlevel.c b/tools/virtiofsd/fuse_lowleve= l.c index ba20c73778..66607100f2 100644 --- a/tools/virtiofsd/fuse_lowlevel.c +++ b/tools/virtiofsd/fuse_lowlevel.c @@ -217,9 +217,9 @@ static int send_reply(fuse_req_t req, int error, const = void *arg, int fuse_reply_iov(fuse_req_t req, const struct iovec *iov, int count) { int res; - struct iovec *padded_iov; + g_autofree struct iovec *padded_iov; =20 - padded_iov =3D malloc((count + 1) * sizeof(struct iovec)); + padded_iov =3D g_try_new(struct iovec, count + 1); if (padded_iov =3D=3D NULL) { return fuse_reply_err(req, ENOMEM); } @@ -228,7 +228,6 @@ int fuse_reply_iov(fuse_req_t req, const struct iovec *= iov, int count) count++; =20 res =3D send_reply_iov(req, 0, padded_iov, count); - free(padded_iov); =20 return res; } @@ -565,10 +564,10 @@ int fuse_reply_bmap(fuse_req_t req, uint64_t idx) static struct fuse_ioctl_iovec *fuse_ioctl_iovec_copy(const struct iovec *= iov, size_t count) { - struct fuse_ioctl_iovec *fiov; + g_autofree struct fuse_ioctl_iovec *fiov; size_t i; =20 - fiov =3D malloc(sizeof(fiov[0]) * count); + fiov =3D g_try_new(fuse_ioctl_iovec, count); if (!fiov) { return NULL; } @@ -578,7 +577,7 @@ static struct fuse_ioctl_iovec *fuse_ioctl_iovec_copy(c= onst struct iovec *iov, fiov[i].len =3D iov[i].iov_len; } =20 - return fiov; + return g_steal_pointer(&fiov); } =20 int fuse_reply_ioctl_retry(fuse_req_t req, const struct iovec *in_iov, @@ -629,9 +628,6 @@ int fuse_reply_ioctl_retry(fuse_req_t req, const struct= iovec *in_iov, =20 res =3D send_reply_iov(req, 0, iov, count); out: - free(in_fiov); - free(out_fiov); - return res; =20 enomem: @@ -663,11 +659,11 @@ int fuse_reply_ioctl(fuse_req_t req, int result, cons= t void *buf, size_t size) int fuse_reply_ioctl_iov(fuse_req_t req, int result, const struct iovec *i= ov, int count) { - struct iovec *padded_iov; + g_autofree struct iovec *padded_iov; struct fuse_ioctl_out arg; int res; =20 - padded_iov =3D malloc((count + 2) * sizeof(struct iovec)); + padded_iov =3D g_try_new(struct iovec, count + 2); if (padded_iov =3D=3D NULL) { return fuse_reply_err(req, ENOMEM); } @@ -680,7 +676,6 @@ int fuse_reply_ioctl_iov(fuse_req_t req, int result, co= nst struct iovec *iov, memcpy(&padded_iov[2], iov, count * sizeof(struct iovec)); =20 res =3D send_reply_iov(req, 0, padded_iov, count + 2); - free(padded_iov); =20 return res; } diff --git a/tools/virtiofsd/fuse_virtio.c b/tools/virtiofsd/fuse_virtio.c index 3e13997406..07e5d91a9f 100644 --- a/tools/virtiofsd/fuse_virtio.c +++ b/tools/virtiofsd/fuse_virtio.c @@ -347,8 +347,7 @@ int virtio_send_data_iov(struct fuse_session *se, struc= t fuse_chan *ch, * Build a copy of the the in_sg iov so we can skip bits in it, * including changing the offsets */ - struct iovec *in_sg_cpy =3D calloc(sizeof(struct iovec), in_num); - assert(in_sg_cpy); + g_autofree struct iovec *in_sg_cpy =3D g_new0(struct iovec, in_num); memcpy(in_sg_cpy, in_sg, sizeof(struct iovec) * in_num); /* These get updated as we skip */ struct iovec *in_sg_ptr =3D in_sg_cpy; @@ -386,7 +385,6 @@ int virtio_send_data_iov(struct fuse_session *se, struc= t fuse_chan *ch, ret =3D errno; fuse_log(FUSE_LOG_DEBUG, "%s: preadv failed (%m) len=3D%zd\n", __func__, len); - free(in_sg_cpy); goto err; } fuse_log(FUSE_LOG_DEBUG, "%s: preadv ret=3D%d len=3D%zd\n", __func= __, @@ -410,13 +408,11 @@ int virtio_send_data_iov(struct fuse_session *se, str= uct fuse_chan *ch, if (ret !=3D len) { fuse_log(FUSE_LOG_DEBUG, "%s: ret!=3Dlen\n", __func__); ret =3D EIO; - free(in_sg_cpy); goto err; } in_sg_left -=3D ret; len -=3D ret; } while (in_sg_left); - free(in_sg_cpy); =20 /* Need to fix out->len on EOF */ if (len) { --=20 2.25.1 From nobody Mon Apr 29 09:47:31 2024 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=1616161046; cv=none; d=zohomail.com; s=zohoarc; b=eU7DjKYdL7zkXjpV0MAoKDWoeGlRaOLA/Ws2VapYKI1aHv6KN/UZodqWevDi+vTX4NHWPDHIIxMriX++RmkkZ9aNmo65UdGUsj0PzBRzDt5vpK324j4kVoPBg06uj4SaX382wgCA8Zo0mBJaa0vWybKu8FwYihi+1M2CsUjsAMw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616161046; 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=dughqH1cx9PZP0psDeqXff4h8j75pyRUTE0x8cTekeU=; b=FfkXZgge4kz7CXTCuAXeRnZoVK3giVedNXIMytZ1m8BPQesYKEFtEh2aW+00iUYTeKl+xLR8K3gIuqcm0VRGtWls2qhb0p7N+34DbSkaMKv3AriLDcZAU3b752NPL9FWDr+r7LWz2KkA12ewVa7z33vGBbhgx0/pjLPsqxK+D1I= 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 1616161046796431.18772037856354; Fri, 19 Mar 2021 06:37:26 -0700 (PDT) Received: from localhost ([::1]:33490 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lNFJd-0006Rh-Fi for importer@patchew.org; Fri, 19 Mar 2021 09:37:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:32976) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lNF9C-0001HN-TL for qemu-devel@nongnu.org; Fri, 19 Mar 2021 09:26:38 -0400 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]:45579) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lNF96-0004Bf-LL for qemu-devel@nongnu.org; Fri, 19 Mar 2021 09:26:38 -0400 Received: by mail-wm1-x32c.google.com with SMTP id r10-20020a05600c35cab029010c946c95easo5233573wmq.4 for ; Fri, 19 Mar 2021 06:26:31 -0700 (PDT) Received: from localhost.localdomain ([102.47.92.134]) by smtp.googlemail.com with ESMTPSA id v13sm8889584wrt.45.2021.03.19.06.26.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Mar 2021 06:26:29 -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=dughqH1cx9PZP0psDeqXff4h8j75pyRUTE0x8cTekeU=; b=QaOvPmtgIJAVBkzxC7G5f5APK5fBiY5URqmRLkpyB2Z7sRlgn7DlPoHIF3X2SciaZs l1rICCeNsimSjC2Ve30ECSCijm4gdi8Ul6abCVb09wtcfjnaq1j5fiieMdLSB2eoziGQ HXM2falcM7a8vevshPILGEuF+Yai4+z1XA5ZJIe+NiF8CFO5GaidYdbJLtdO2VaBVT5O 8XAXYX8KfRkIE/BbYjMBXZ4uAby6n33GPsgYsQDhqv14Bg6Kp2Lbkc/Q1BWGzf+TsN5q nXJ1rJOD29cGoYlOhqM9h19G5ObT0vi1J6TeXlNK+9XvXnMjayFMEDak95FooL6ZntzO LGqA== 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=dughqH1cx9PZP0psDeqXff4h8j75pyRUTE0x8cTekeU=; b=fQVsF2WC6SD6AG7j5EA5o2hch7dwJ8lv085TQc/690Y9fl0k3AKbDZ1JJNDraSOCuc TwwmmAXrnaMdEMmc70jYsMNEq1mCAMxd0WJptLayB+W8MK4GnIY5gSZamd20O8c2vTZF PiZJfkbTakvG+PI6op5eNgjlsYzDi2CjxTYEF9Siw13gdI1LPWHIslNLPutWJF/v9uBK TrCafrg5K4I9hm4ZDQhbXCBV1U4NxvW8UoR4MQVAQoqIH1tFxQWKXbhtRqtezNN12c0S DTiH6+zDdZK144s8Zk0UsPU49nLGKa41lRsCJPpemxzPbEjS8EEnGiFZV0HHsLlUGIJg ZbJw== X-Gm-Message-State: AOAM5314n/MPaAcgJhENrhlVUJAffRZSPMTGYJwVpiIbIi51G2BRsl4I feYkTegDq21qm03bA782fVZsD1zXFLs= X-Google-Smtp-Source: ABdhPJyrJ+pHeR+G2D2JQyq4huZZ/vjRg/4z/LN0JvkxAv8+/YT+l7VrWAF+Scs48NFIQNdSKLDjSw== X-Received: by 2002:a05:600c:2109:: with SMTP id u9mr3773540wml.44.1616160390077; Fri, 19 Mar 2021 06:26:30 -0700 (PDT) From: Mahmoud Mandour To: qemu-devel@nongnu.org Subject: [PATCH 3/8] virtiofsd: Changed fuse_pollhandle allocation to GLib's functions Date: Fri, 19 Mar 2021 15:25:22 +0200 Message-Id: <20210319132527.3118-4-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::32c; envelope-from=ma.mandourr@gmail.com; helo=mail-wm1-x32c.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 allocation of fuse_pollhandle structs to GLib's g_new(). Removed the null checking as allocating such a small memory segment should always succeed on a healthy system. Otherwise, the system is already in a critical state. Signed-off-by: Mahmoud Mandour --- tools/virtiofsd/fuse_lowlevel.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/tools/virtiofsd/fuse_lowlevel.c b/tools/virtiofsd/fuse_lowleve= l.c index 66607100f2..45527ff703 100644 --- a/tools/virtiofsd/fuse_lowlevel.c +++ b/tools/virtiofsd/fuse_lowlevel.c @@ -1755,7 +1755,7 @@ static void do_ioctl(fuse_req_t req, fuse_ino_t nodei= d, =20 void fuse_pollhandle_destroy(struct fuse_pollhandle *ph) { - free(ph); + g_free(ph); } =20 static void do_poll(fuse_req_t req, fuse_ino_t nodeid, @@ -1778,11 +1778,7 @@ static void do_poll(fuse_req_t req, fuse_ino_t nodei= d, struct fuse_pollhandle *ph =3D NULL; =20 if (arg->flags & FUSE_POLL_SCHEDULE_NOTIFY) { - ph =3D malloc(sizeof(struct fuse_pollhandle)); - if (ph =3D=3D NULL) { - fuse_reply_err(req, ENOMEM); - return; - } + ph =3D g_new(struct fuse_pollhandle, 1); ph->kh =3D arg->kh; ph->se =3D req->se; } --=20 2.25.1 From nobody Mon Apr 29 09:47:31 2024 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=1616161152; cv=none; d=zohomail.com; s=zohoarc; b=d61DwIji4sDtESDDQfRuQRgo+PXS6JsVw6/vPRjREnmiMjBLHDtNOMfSfuFpmiKC4RglQ9vd0SK/jIyaC6yAMLdrFT1VVpaf5wn6G4sg7ai4CEj5CsIKm5qgeK0Y04HlKgJ8sbjr9dePreAlQy7Za3k0s9OEnIirr4FX9KSoOI0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616161152; 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=pYkY/2Z/pLbSHd+jTUePpf2Jwa7tCLrS2ddiXxwQybM=; b=JAcx1uj6tub1m4xVSwswtqsp61eC/LdtbpB6oI0e7LYS8/t9jReU8f9uCvLAT5EjCEV7iwYh9IG5tUrVkiJfpfx0N3Efbs79V5Q+GE6lXjQpOydghCVPW60XMI1FWd8vbwCgPuE4SymWy1dWEt9s5LOnLEDQ0i/q/Jqu+RSPRUU= 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 1616161152901730.2426816877658; Fri, 19 Mar 2021 06:39:12 -0700 (PDT) Received: from localhost ([::1]:36784 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lNFKM-0007nF-5u for importer@patchew.org; Fri, 19 Mar 2021 09:38:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:32940) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lNF9B-0001Eq-JY for qemu-devel@nongnu.org; Fri, 19 Mar 2021 09:26:37 -0400 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]:55866) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lNF96-0004C8-RU for qemu-devel@nongnu.org; Fri, 19 Mar 2021 09:26:37 -0400 Received: by mail-wm1-x32d.google.com with SMTP id 12so5453381wmf.5 for ; Fri, 19 Mar 2021 06:26:32 -0700 (PDT) Received: from localhost.localdomain ([102.47.92.134]) by smtp.googlemail.com with ESMTPSA id v13sm8889584wrt.45.2021.03.19.06.26.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Mar 2021 06:26:30 -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=pYkY/2Z/pLbSHd+jTUePpf2Jwa7tCLrS2ddiXxwQybM=; b=JA8INJ/EjLhiJttUKSQ1qbYZGiQRnPZrQ5Ys2eSo2N0fAx8cNp9VR1hJ6/8NHrQ3wh 2dQTtnUjwGzEHWclphqWsy/5e1G+Nmhmtaq49ia3cIBJkOBna1S+NEojW/Mic5VH5r+C JnhF9rcvMvvtGJfuL0/CZjTKvk7RK8+/Po+4cqc/jSMp6DrfiLYF1f/FGeCnkIwqihWc H5NUycl9zOp29fUrgrZO+4EmpWd8n9Ou86B7DLgB9fYFbozvKncoG0sl8Jc72ll7dTVj JcbWCW+Ni4zVpJw/q/aG2URFhDR4L42ItfNRXSl6QzbCVf7S+9GTs/vZ8XsA7QnJpcJn iypg== 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=pYkY/2Z/pLbSHd+jTUePpf2Jwa7tCLrS2ddiXxwQybM=; b=nnSnfmTc9NATOqbLX3NR8l2XNCG8IqUzJw6I+6dN7MqvoL17uoCNmn6Yy5b9TJCfZ2 Co+RrJPUs4pG03+klk4up+jBIg53Zb22xRg8gdHqVRqC4xeburwqlVgiQv7HXCFnz0dF wkDFaKIh9005M1o2kPe7DKtBO6g/8uvL7240YnAKbY+c6PpmWu6gnmaL1TTaAgcOPDAO S8bgTpqHNVOXqk8FotNsco+OY/mrzeXYU4+WVVsQyKfeKdkpQ93U5KaJqqPqgDCnXVPh qeDukL5eTw0CvR6ajSVRM3bCJqLQsRQeOEEU2CL9edCW3Gazmgk1q2UgZFpSswioctfe 7jLQ== X-Gm-Message-State: AOAM532lz0CwTLPDBvo186lKK8KkvcGxy/rSlj/7f1mhJFl+VpKOkDcV aEp11wfipZ5n652DgqvGaZjX98KLiac= X-Google-Smtp-Source: ABdhPJw+GZe4pSB1/ybcG0At/uiwB+A5TeddMMAJEvx7k6KblvGEOm/vkVT3X7WFmT7hEg6DCT4WXA== X-Received: by 2002:a1c:f20e:: with SMTP id s14mr3805771wmc.100.1616160390904; Fri, 19 Mar 2021 06:26:30 -0700 (PDT) From: Mahmoud Mandour To: qemu-devel@nongnu.org Subject: [PATCH 4/8] virtiofsd: Changed allocations of fuse_session to GLib's functions Date: Fri, 19 Mar 2021 15:25:23 +0200 Message-Id: <20210319132527.3118-5-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::32d; envelope-from=ma.mandourr@gmail.com; helo=mail-wm1-x32d.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" Replaced the allocation and deallocation of fuse_session structs from calloc() and free() calls to g_new0() and g_free(). Removed the NULL-check and used g_new0() mainly because fuse_session creation is critical and an exit will occur anyway if fuse_session allocation failed. Signed-off-by: Mahmoud Mandour --- tools/virtiofsd/fuse_lowlevel.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/tools/virtiofsd/fuse_lowlevel.c b/tools/virtiofsd/fuse_lowleve= l.c index 45527ff703..b0e9ef29a7 100644 --- a/tools/virtiofsd/fuse_lowlevel.c +++ b/tools/virtiofsd/fuse_lowlevel.c @@ -2467,7 +2467,7 @@ void fuse_session_destroy(struct fuse_session *se) free(se->vu_socket_path); se->vu_socket_path =3D NULL; =20 - free(se); + g_free(se); } =20 =20 @@ -2490,11 +2490,7 @@ struct fuse_session *fuse_session_new(struct fuse_ar= gs *args, return NULL; } =20 - se =3D (struct fuse_session *)calloc(1, sizeof(struct fuse_session)); - if (se =3D=3D NULL) { - fuse_log(FUSE_LOG_ERR, "fuse: failed to allocate fuse object\n"); - goto out1; - } + se =3D g_new0(struct fuse_session, 1); se->fd =3D -1; se->vu_listen_fd =3D -1; se->thread_pool_size =3D THREAD_POOL_SIZE; @@ -2550,7 +2546,7 @@ struct fuse_session *fuse_session_new(struct fuse_arg= s *args, out4: fuse_opt_free_args(args); out2: - free(se); + g_free(se); out1: return NULL; } --=20 2.25.1 From nobody Mon Apr 29 09:47:31 2024 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=1616161226; cv=none; d=zohomail.com; s=zohoarc; b=irXW5HsOKkyG3zkzy16wa8j2Ib/0spjBfH0WFBM0c9r/jn9I+j91SO9m0UCYFvz0n9aYWaqQcypnCxRKPBi/fpal5rPZuavqhWQ8BGSbkGEHK22mPaFr4kPaWCXIdFmRzPt4w/ybB9FxqCI6KcCtqIcjaVWYVHVd8sntyIJI7Iw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616161226; 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=oDM8GCnYBpDqZVvOsLq7sgTXnB4+UFlSG0fMOroprbE=; b=PXNzQ7LKaDBCgjnD+FjQ+QNr0Bn/ss4aFzSti53VbVLeEqy1CJWoFXBM7yxsLsq6+sXt8ci7GnmSK6iB+X5nJ79BuozC8GA+PoEqCvNXJAPp2UsDCtZE9rNBfR+9yDXf/AE4vLcQ1xvqCBwnTpjVphru4pbveu6BgGtCVsuGJ2o= 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 1616161226108604.6359456537402; Fri, 19 Mar 2021 06:40:26 -0700 (PDT) Received: from localhost ([::1]:43036 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lNFMX-0001ue-C4 for importer@patchew.org; Fri, 19 Mar 2021 09:40:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33012) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lNF9E-0001Lz-Ux for qemu-devel@nongnu.org; Fri, 19 Mar 2021 09:26:41 -0400 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]:46976) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lNF99-0004CG-N2 for qemu-devel@nongnu.org; Fri, 19 Mar 2021 09:26:40 -0400 Received: by mail-wr1-x434.google.com with SMTP id v4so9100316wrp.13 for ; Fri, 19 Mar 2021 06:26:33 -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:31 -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=oDM8GCnYBpDqZVvOsLq7sgTXnB4+UFlSG0fMOroprbE=; b=KhChTaWES5Aks6JjxFdGaDmCkybR/v5wVz1KjKPS9J2CPaPVaEpnLDEQ5dteBrDJ08 /8oGskveyWCrv5TQ3L3oYT0hnixtx8h78+v5RPJjd9c2lg2nmG3CvRF1R6rPgUBPf5Gq 0jn0/zTJGow1tQQ6ytmH9lZdI1SRkIZVT35t72A4QO7s7k1ZpQ6K1imF65Ngovn7/ZzO TPASqegKfqpJCkzvmGlb5J4vO/xL52ZxpfdF2JSulUIeahR7jwdj8EcwkX3Z5QUHdGqb LkbPrvqmaW0+yF2F2pSSwVypu6EIag3eXzj85sJBNFZminlHjOct629Xz9isAC5QCNJE sOPw== 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=oDM8GCnYBpDqZVvOsLq7sgTXnB4+UFlSG0fMOroprbE=; b=oM9rEzA66yK5CPGAkScwaplXxGjFkyjo3xLOVWSEy5XAMZWLUKeQFqzz1CZspEFPK0 KXXcoSn9sUx2S6zDP4lAX2OTOUBpfTjcp1h0WtkqC7UWknFB1X3tSDd4kuJ90KR1epGW 9RMjk7O4ht0s8JsQNbuMvyDkF93eN09AWc6xnxRQM03RBdZAq+a7NboHJdSZ+w14896K KIjjW/ovX/1oLRKsdfDIEGsDJcJOHiXBJmzdSWTm85Fup4Hp6IOxfLu81nqZN3Drc1bk Fw2ammNIVCLQYw5LGGNYscTN+sx5tnRqkSgS1c8RBCeK3nwWTVARzA+T3LALEYbwLstJ m4FA== X-Gm-Message-State: AOAM533yQ9Xbir5QSA2FrceD4/0xniWkhqerL/y+/+1QrMfC3neYhkoO XZe8hQjnkNmSSgCrf8SUKYwODzwmMw4= X-Google-Smtp-Source: ABdhPJwAY2zEVdFZmkzso2Hi1nQIUfAf1FgzDQVh1inZ1vU3zPXGYfVyfevKTTsCs5GRLdKlu/6dEA== X-Received: by 2002:adf:c64a:: with SMTP id u10mr4595915wrg.412.1616160391728; Fri, 19 Mar 2021 06:26:31 -0700 (PDT) From: Mahmoud Mandour To: qemu-devel@nongnu.org Subject: [PATCH 5/8] virtiofsd: Changed allocation of lo_map_elems to GLib's functions Date: Fri, 19 Mar 2021 15:25:24 +0200 Message-Id: <20210319132527.3118-6-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::434; envelope-from=ma.mandourr@gmail.com; helo=mail-wr1-x434.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" Replaced (re)allocation of lo_map_elem structs from realloc() to GLib's g_try_realloc_n() and replaced the respective free() call with a g_free(). Signed-off-by: Mahmoud Mandour Reviewed-by: Stefan Hajnoczi --- tools/virtiofsd/passthrough_ll.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough= _ll.c index b144320e48..d049013428 100644 --- a/tools/virtiofsd/passthrough_ll.c +++ b/tools/virtiofsd/passthrough_ll.c @@ -406,7 +406,7 @@ static void lo_map_init(struct lo_map *map) =20 static void lo_map_destroy(struct lo_map *map) { - free(map->elems); + g_free(map->elems); } =20 static int lo_map_grow(struct lo_map *map, size_t new_nelems) @@ -418,7 +418,7 @@ static int lo_map_grow(struct lo_map *map, size_t new_n= elems) return 1; } =20 - new_elems =3D realloc(map->elems, sizeof(map->elems[0]) * new_nelems); + new_elems =3D g_try_realloc_n(map->elems, new_nelems, sizeof(map->elem= s[0])); if (!new_elems) { return 0; } --=20 2.25.1 From nobody Mon Apr 29 09:47:31 2024 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 From nobody Mon Apr 29 09:47:31 2024 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=1616160850; cv=none; d=zohomail.com; s=zohoarc; b=G3lEl4NfIpyKEHzzfY0aBftppMTjYQKnDDx/byAFsdZvnu7UUZhiL6dD+OXpi/jh7theWxBVQwxcZYxdxC7ZBzOf+lGGiRBmZb518EqT/jnJC68g+FKkGDG77NU2jB2v1TnMw7bjvMPL9HGcNYL1oS22m4hEu0z8LqY+2sN6gK8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616160850; 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=tRiDkt/PZdT5UYxHG4CdXIwPFvqt4OqFWKCOPiH+A5w=; b=R1Kr9hkWTBez2xKuMxjgXEmcNv61OIbCXykQ3l6hyZBscwNxeJifPIGJifIkgyGXqeibx4ee8AziCXhE4/OvxF9Ff1cRE2zKDKqxfZM9KRCJpfUw+iUfLsouT+GWfsdszA86niXG9tZBN/muNJqwXZ4ivyuw4wZstcgxeZoavzI= 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 1616160850783691.0953424584765; Fri, 19 Mar 2021 06:34:10 -0700 (PDT) Received: from localhost ([::1]:50602 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lNFGT-0001sq-OR for importer@patchew.org; Fri, 19 Mar 2021 09:34:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33000) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lNF9D-0001Jb-Qc for qemu-devel@nongnu.org; Fri, 19 Mar 2021 09:26:39 -0400 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]:51084) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lNF9A-0004D7-Hd for qemu-devel@nongnu.org; Fri, 19 Mar 2021 09:26:39 -0400 Received: by mail-wm1-x335.google.com with SMTP id g25so5491677wmh.0 for ; Fri, 19 Mar 2021 06:26:36 -0700 (PDT) Received: from localhost.localdomain ([102.47.92.134]) by smtp.googlemail.com with ESMTPSA id v13sm8889584wrt.45.2021.03.19.06.26.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Mar 2021 06:26:33 -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=tRiDkt/PZdT5UYxHG4CdXIwPFvqt4OqFWKCOPiH+A5w=; b=vfRGdKzO6KmrMTkQh9J4s6ZMiSoUgtAYRrUF/evsr6PvXoUrl3WZKD6jo0rp4slJ/n Zfv7Cus0ljJMyrgnarQrztcz1QZahozZT71+A2mn1bkDvgOBxcammZlaAQWBeRXgTf8d 1saUkoJLegRkWXTD/NgYrgwGgJjZ9LsOTCxS1OWObCvhqntRoJakAPdtnPT8M00R26JH n98pVFoPwlcMZVz5jiYTc14G7oCwYsK6DCZli+Yd+ZgKyiBo2I9teqKmtcjawFxIT+jI r4T+wQisWCvfeIoQ6M/WqYk8t1EXIdlX5a0tSNTM91FFSMHa3XpXpY5vaa3q1zoAfZxd Qczg== 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=tRiDkt/PZdT5UYxHG4CdXIwPFvqt4OqFWKCOPiH+A5w=; b=gR+bcxOnkP1n5u2FdzTaGpRKJg7R09dMiqlvnWx7xCnHThF8KkcSY9HvkfwLMAkkT2 jXbF9YSF4JxC4RrvAGwg0qGCsyeHpOwS9BJ7dqhrBePmFZiouPWvZ8h/r9ctQ6iu6e6T GP2ixbflHqorBpRnq3zXepnJZ6NAV526KOnu3L/s6X4P0xJEPgfkWzwzeqlVcXzGH85P 68gyUdsOT3lZoQbyyZciXnMRywXuH+IsDplN/vRK/2wQXENoixrPpnwgZ9ZNnuRU9Tnf 6gE4LROSfEGrJRtYYZGU81RNdIw4if3s0/4no2G11FtVF7/GOwWur9bIQz7Es092gfOG WRQg== X-Gm-Message-State: AOAM5303NOUe2lT9BPIVxzsNQFhtpzRlQiRRJe/pFbH/HqkziuVJXs9a 7fl4eVWVHhm6tguu78DG9jTz+0qn6qk= X-Google-Smtp-Source: ABdhPJxGJbH18sqefbIBK4SKUQqBmLO1I/R5KbSAAsZXNTE5JQ/C6Yef23dwRgLKPZR7kQ2x5T9pkg== X-Received: by 2002:a1c:43c5:: with SMTP id q188mr3696767wma.94.1616160395013; Fri, 19 Mar 2021 06:26:35 -0700 (PDT) From: Mahmoud Mandour To: qemu-devel@nongnu.org Subject: [PATCH 7/8] virtiofsd/passthrough_ll.c: Changed local allocations to GLib functions Date: Fri, 19 Mar 2021 15:25:26 +0200 Message-Id: <20210319132527.3118-8-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::335; envelope-from=ma.mandourr@gmail.com; helo=mail-wm1-x335.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 some local variables to GLib's allocation functions, such as g_try_malloc0(), and annotated those variables as g_autofree. Subsequently, I was able to remove the calls to free(). Signed-off-by: Mahmoud Mandour Reviewed-by: Stefan Hajnoczi --- tools/virtiofsd/passthrough_ll.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough= _ll.c index d049013428..4263b383f0 100644 --- a/tools/virtiofsd/passthrough_ll.c +++ b/tools/virtiofsd/passthrough_ll.c @@ -1653,7 +1653,7 @@ static void lo_do_readdir(fuse_req_t req, fuse_ino_t = ino, size_t size, struct lo_data *lo =3D lo_data(req); struct lo_dirp *d =3D NULL; struct lo_inode *dinode; - char *buf =3D NULL; + g_autofree char *buf =3D NULL; char *p; size_t rem =3D size; int err =3D EBADF; @@ -1669,7 +1669,7 @@ static void lo_do_readdir(fuse_req_t req, fuse_ino_t = ino, size_t size, } =20 err =3D ENOMEM; - buf =3D calloc(1, size); + buf =3D g_try_malloc0(size); if (!buf) { goto error; } @@ -1755,7 +1755,6 @@ error: } else { fuse_reply_buf(req, buf, size - rem); } - free(buf); } =20 static void lo_readdir(fuse_req_t req, fuse_ino_t ino, size_t size, @@ -2726,7 +2725,7 @@ static void lo_getxattr(fuse_req_t req, fuse_ino_t in= o, const char *in_name, size_t size) { struct lo_data *lo =3D lo_data(req); - char *value =3D NULL; + g_autofree char *value =3D NULL; char procname[64]; const char *name; char *mapped_name; @@ -2767,7 +2766,7 @@ static void lo_getxattr(fuse_req_t req, fuse_ino_t in= o, const char *in_name, ino, name, size); =20 if (size) { - value =3D malloc(size); + value =3D g_try_malloc(size); if (!value) { goto out_err; } @@ -2806,8 +2805,6 @@ static void lo_getxattr(fuse_req_t req, fuse_ino_t in= o, const char *in_name, fuse_reply_xattr(req, ret); } out_free: - free(value); - if (fd >=3D 0) { close(fd); } @@ -2826,7 +2823,7 @@ out: static void lo_listxattr(fuse_req_t req, fuse_ino_t ino, size_t size) { struct lo_data *lo =3D lo_data(req); - char *value =3D NULL; + g_autofree char *value =3D NULL; char procname[64]; struct lo_inode *inode; ssize_t ret; @@ -2848,7 +2845,7 @@ static void lo_listxattr(fuse_req_t req, fuse_ino_t i= no, size_t size) size); =20 if (size) { - value =3D malloc(size); + value =3D g_try_malloc(size); if (!value) { goto out_err; } @@ -2933,8 +2930,6 @@ static void lo_listxattr(fuse_req_t req, fuse_ino_t i= no, size_t size) fuse_reply_xattr(req, ret); } out_free: - free(value); - if (fd >=3D 0) { close(fd); } --=20 2.25.1 From nobody Mon Apr 29 09:47:31 2024 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=1616161221; cv=none; d=zohomail.com; s=zohoarc; b=dBuis6X+5oBKJGcL+Ti7AakqpYNwFYUeqR53YqAItL7jToAhJ/qBjtUUaUVyNkjQqruH7KsrGJKmDNYdk4ub75QRyPxb4aAYZ5EGAOKSSCFn/nPReCp3TEdORdZ6MNufFibnZxkgvLh7FUQeVd1XnG4SNGXLouKtsTwhjp2VZnQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616161221; 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=Z2u3q3r6w6+qN78egFiLHd6jOUJq1Ybg2sCdGyDUnAM=; b=lbz0RzY6btyA3BavRr3SynBsNoqdbPqcLhYoKF0foBeUOJ2aT13gD0PNja4SMUQi2+URFGqXD4HXO2GOt7jvTKH+VhuervUkBVfBiS+VD9pLN3qLEqTMV/8I5zuyoWkIPmrAXZI7WDwAX36c0Hl4AJiOvmxdFsybiJ87Tqj89mg= 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 1616161221008777.8658653275031; Fri, 19 Mar 2021 06:40:21 -0700 (PDT) Received: from localhost ([::1]:42608 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lNFMR-0001k5-Eb for importer@patchew.org; Fri, 19 Mar 2021 09:40:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33004) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lNF9E-0001KV-AR for qemu-devel@nongnu.org; Fri, 19 Mar 2021 09:26:40 -0400 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]:43710) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lNF9B-0004E3-FE for qemu-devel@nongnu.org; Fri, 19 Mar 2021 09:26:40 -0400 Received: by mail-wm1-x32f.google.com with SMTP id u5-20020a7bcb050000b029010e9316b9d5so5239476wmj.2 for ; Fri, 19 Mar 2021 06:26:36 -0700 (PDT) Received: from localhost.localdomain ([102.47.92.134]) by smtp.googlemail.com with ESMTPSA id v13sm8889584wrt.45.2021.03.19.06.26.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Mar 2021 06:26:35 -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=Z2u3q3r6w6+qN78egFiLHd6jOUJq1Ybg2sCdGyDUnAM=; b=jQO5AkXBiHKNB+Am/VXnapVwjYC2AMFUqmbnPoYi7GlrLBKtHCc3dA1Yns9zDBt7XK CBUsn5ZEpM9wbqy6HDH35PZHbvmqxTGKHYLX9j+hINcs+APhhDpJoMGh2d2JHpGKsaKS nLNK5X1mjsNYqrQvubTRKRITaL0YNTHf9BNzBWsqKfo7d7xqfhPhy9mcxQCoxOaLA+YI gRYbjLHvyOhg0fCwrI07HHcBaAwKTRfBBwDqo6s3v2Ey8WqE+61Ia/g3jNzY+nWA+zwd 71EEjOjGJ6gCLj/NhW3RI5RwF3gipDed6kg6GAaKuHKFWLWY+X1xX+JfeseWDQ0Tq2Lt CCLQ== 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=Z2u3q3r6w6+qN78egFiLHd6jOUJq1Ybg2sCdGyDUnAM=; b=bD66HMjigX26HMtvquN4K0Kx77GIB3V6JZSRanp7AhFNf5vJiIVUh3xw3SJr53tjID R34dOAwiBpGc+w6fom1PaRy8PMmnZ2Utll+F6zlUJKG/tlJOp7cSJrt1brwZdIS4sNGG XM+044nvtVKcPP/PUxML4lb5E662xsdcBHTraJBMGjvMFR3uIPhokck7k39ST10PTDkx wJm0gSgvqvrYpJZ8p38q/IJ24J9xntsSG8s8iwLQZhLbsC/S7KiXNSekYHTtpoNEqCjx ing4LM3HMJLh5dWBIkxVr1IxAXg4/9cDMxLqLoERHmt+vQUvlTdq0h/1usqk4Ykr5L5B JR9Q== X-Gm-Message-State: AOAM531pNBfuIGNhp8tM4r5Vrfw7dQmP646azMgcX5WxsDCgho8qoE5x 9YlUtNzeVrMP1A/MIxje97IFwcCkAAE= X-Google-Smtp-Source: ABdhPJxj7rOYhwZjq6QDiEtVp+fXMUMqw1ejkJHJJjgBzFUBHZNqSf3jlPZc4U+Cl395dkl+GZFbtQ== X-Received: by 2002:a1c:b4c6:: with SMTP id d189mr3718417wmf.72.1616160395842; Fri, 19 Mar 2021 06:26:35 -0700 (PDT) From: Mahmoud Mandour To: qemu-devel@nongnu.org Subject: [PATCH 8/8] virtiofsd/fuse_virtio.c: Changed allocations of locals to GLib Date: Fri, 19 Mar 2021 15:25:27 +0200 Message-Id: <20210319132527.3118-9-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::32f; envelope-from=ma.mandourr@gmail.com; helo=mail-wm1-x32f.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" Replaced the allocation of local variables from malloc() to GLib allocation functions. In one instance, dropped the usage to an assert after a malloc() call and used g_malloc() instead. Signed-off-by: Mahmoud Mandour Reviewed-by: Stefan Hajnoczi --- tools/virtiofsd/fuse_virtio.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tools/virtiofsd/fuse_virtio.c b/tools/virtiofsd/fuse_virtio.c index 5828b9a76f..587403b026 100644 --- a/tools/virtiofsd/fuse_virtio.c +++ b/tools/virtiofsd/fuse_virtio.c @@ -472,8 +472,7 @@ static void fv_queue_worker(gpointer data, gpointer use= r_data) * They're spread over multiple descriptors in a scatter/gather set * and we can't trust the guest to keep them still; so copy in/out. */ - fbuf.mem =3D malloc(se->bufsize); - assert(fbuf.mem); + fbuf.mem =3D g_malloc(se->bufsize); =20 fuse_mutex_init(&req->ch.lock); req->ch.fd =3D -1; @@ -524,7 +523,7 @@ static void fv_queue_worker(gpointer data, gpointer use= r_data) fbuf.size =3D out_sg[0].iov_len + out_sg[1].iov_len; =20 /* Allocate the bufv, with space for the rest of the iov */ - pbufv =3D malloc(sizeof(struct fuse_bufvec) + + pbufv =3D g_try_malloc(sizeof(struct fuse_bufvec) + sizeof(struct fuse_buf) * (out_num - 2)); if (!pbufv) { fuse_log(FUSE_LOG_ERR, "%s: pbufv malloc failed\n", @@ -569,7 +568,7 @@ static void fv_queue_worker(gpointer data, gpointer use= r_data) =20 out: if (allocated_bufv) { - free(pbufv); + g_free(pbufv); } =20 /* If the request has no reply, still recycle the virtqueue element */ @@ -588,7 +587,7 @@ out: } =20 pthread_mutex_destroy(&req->ch.lock); - free(fbuf.mem); + g_free(fbuf.mem); free(req); } =20 --=20 2.25.1