From patchwork Fri Mar 19 13:25:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mahmoud Abumandour X-Patchwork-Id: 1455866 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=VFjFHRse; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4F24Zz1tZjz9sWF for ; Sat, 20 Mar 2021 00:32:59 +1100 (AEDT) Received: from localhost ([::1]:44716 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lNFFI-0007tu-LW for incoming@patchwork.ozlabs.org; Fri, 19 Mar 2021 09:32:56 -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) 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) 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) 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 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 Reviewed-by: Stefan Hajnoczi --- 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_lowlevel.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 fuse_req *next) static void destroy_req(fuse_req_t req) { pthread_mutex_destroy(&req->lock); - free(req); + g_free(req); } void fuse_free_req(fuse_req_t req) @@ -130,7 +130,7 @@ static struct fuse_req *fuse_ll_alloc_req(struct fuse_session *se) { struct fuse_req *req; - req = (struct fuse_req *)calloc(1, sizeof(struct fuse_req)); + req = g_try_new0(struct fuse_req, 1); if (req == 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_session *se, if (curr->u.i.unique == req->unique) { req->interrupted = 1; list_del_req(curr); - free(curr); + g_free(curr); return NULL; } } From patchwork Fri Mar 19 13:25:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mahmoud Abumandour X-Patchwork-Id: 1455870 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=E7PpszS5; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4F24dR1NfLz9s1l for ; Sat, 20 Mar 2021 00:35:06 +1100 (AEDT) Received: from localhost ([::1]:53366 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lNFHM-0002zh-TA for incoming@patchwork.ozlabs.org; Fri, 19 Mar 2021 09:35:04 -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) 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) 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) 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 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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_lowlevel.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; - padded_iov = malloc((count + 1) * sizeof(struct iovec)); + padded_iov = g_try_new(struct iovec, count + 1); if (padded_iov == 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++; res = send_reply_iov(req, 0, padded_iov, count); - free(padded_iov); 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; - fiov = malloc(sizeof(fiov[0]) * count); + fiov = g_try_new(fuse_ioctl_iovec, count); if (!fiov) { return NULL; } @@ -578,7 +577,7 @@ static struct fuse_ioctl_iovec *fuse_ioctl_iovec_copy(const struct iovec *iov, fiov[i].len = iov[i].iov_len; } - return fiov; + return g_steal_pointer(&fiov); } 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, res = send_reply_iov(req, 0, iov, count); out: - free(in_fiov); - free(out_fiov); - return res; enomem: @@ -663,11 +659,11 @@ int fuse_reply_ioctl(fuse_req_t req, int result, const void *buf, size_t size) int fuse_reply_ioctl_iov(fuse_req_t req, int result, const struct iovec *iov, int count) { - struct iovec *padded_iov; + g_autofree struct iovec *padded_iov; struct fuse_ioctl_out arg; int res; - padded_iov = malloc((count + 2) * sizeof(struct iovec)); + padded_iov = g_try_new(struct iovec, count + 2); if (padded_iov == NULL) { return fuse_reply_err(req, ENOMEM); } @@ -680,7 +676,6 @@ int fuse_reply_ioctl_iov(fuse_req_t req, int result, const struct iovec *iov, memcpy(&padded_iov[2], iov, count * sizeof(struct iovec)); res = send_reply_iov(req, 0, padded_iov, count + 2); - free(padded_iov); 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, struct 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 = calloc(sizeof(struct iovec), in_num); - assert(in_sg_cpy); + g_autofree struct iovec *in_sg_cpy = 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 = in_sg_cpy; @@ -386,7 +385,6 @@ int virtio_send_data_iov(struct fuse_session *se, struct fuse_chan *ch, ret = errno; fuse_log(FUSE_LOG_DEBUG, "%s: preadv failed (%m) len=%zd\n", __func__, len); - free(in_sg_cpy); goto err; } fuse_log(FUSE_LOG_DEBUG, "%s: preadv ret=%d len=%zd\n", __func__, @@ -410,13 +408,11 @@ int virtio_send_data_iov(struct fuse_session *se, struct fuse_chan *ch, if (ret != len) { fuse_log(FUSE_LOG_DEBUG, "%s: ret!=len\n", __func__); ret = EIO; - free(in_sg_cpy); goto err; } in_sg_left -= ret; len -= ret; } while (in_sg_left); - free(in_sg_cpy); /* Need to fix out->len on EOF */ if (len) { From patchwork Fri Mar 19 13:25:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mahmoud Abumandour X-Patchwork-Id: 1455871 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=QaOvPmtg; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4F24g84tHGz9sVS for ; Sat, 20 Mar 2021 00:36:35 +1100 (AEDT) Received: from localhost ([::1]:58754 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lNFIn-0005GH-OZ for incoming@patchwork.ozlabs.org; Fri, 19 Mar 2021 09:36:33 -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) 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) 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) 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 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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_lowlevel.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 nodeid, void fuse_pollhandle_destroy(struct fuse_pollhandle *ph) { - free(ph); + g_free(ph); } 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 nodeid, struct fuse_pollhandle *ph = NULL; if (arg->flags & FUSE_POLL_SCHEDULE_NOTIFY) { - ph = malloc(sizeof(struct fuse_pollhandle)); - if (ph == NULL) { - fuse_reply_err(req, ENOMEM); - return; - } + ph = g_new(struct fuse_pollhandle, 1); ph->kh = arg->kh; ph->se = req->se; } From patchwork Fri Mar 19 13:25:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mahmoud Abumandour X-Patchwork-Id: 1455872 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=JA8INJ/E; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4F24hC2GcWz9s1l for ; Sat, 20 Mar 2021 00:37:31 +1100 (AEDT) Received: from localhost ([::1]:33276 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lNFJh-0006MU-A0 for incoming@patchwork.ozlabs.org; Fri, 19 Mar 2021 09:37:29 -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) 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) 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) 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 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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_lowlevel.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 = NULL; - free(se); + g_free(se); } @@ -2490,11 +2490,7 @@ struct fuse_session *fuse_session_new(struct fuse_args *args, return NULL; } - se = (struct fuse_session *)calloc(1, sizeof(struct fuse_session)); - if (se == NULL) { - fuse_log(FUSE_LOG_ERR, "fuse: failed to allocate fuse object\n"); - goto out1; - } + se = g_new0(struct fuse_session, 1); se->fd = -1; se->vu_listen_fd = -1; se->thread_pool_size = THREAD_POOL_SIZE; @@ -2550,7 +2546,7 @@ struct fuse_session *fuse_session_new(struct fuse_args *args, out4: fuse_opt_free_args(args); out2: - free(se); + g_free(se); out1: return NULL; } From patchwork Fri Mar 19 13:25:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mahmoud Abumandour X-Patchwork-Id: 1455874 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=KhChTaWE; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4F24kc3G8Yz9s1l for ; Sat, 20 Mar 2021 00:39:36 +1100 (AEDT) Received: from localhost ([::1]:40086 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lNFLi-0000jQ-Ga for incoming@patchwork.ozlabs.org; Fri, 19 Mar 2021 09:39:34 -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) 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) 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) 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 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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) static void lo_map_destroy(struct lo_map *map) { - free(map->elems); + g_free(map->elems); } 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_nelems) return 1; } - new_elems = realloc(map->elems, sizeof(map->elems[0]) * new_nelems); + new_elems = g_try_realloc_n(map->elems, new_nelems, sizeof(map->elems[0])); if (!new_elems) { return 0; } From patchwork Fri Mar 19 13:25:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mahmoud Abumandour X-Patchwork-Id: 1455864 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=R2B8n6+P; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4F24XR4p02z9sWb for ; Sat, 20 Mar 2021 00:30:47 +1100 (AEDT) Received: from localhost ([::1]:37618 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lNFDB-0004wO-9s for incoming@patchwork.ozlabs.org; Fri, 19 Mar 2021 09:30:45 -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) 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) 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) 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 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 *vud, int qidx) pthread_mutex_destroy(&ourqi->vq_lock); close(ourqi->kill_fd); ourqi->kick_fd = -1; - free(vud->qi[qidx]); + g_free(vud->qi[qidx]); vud->qi[qidx] = NULL; } @@ -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 >= vud->nqueues) { - vud->qi = realloc(vud->qi, (qidx + 1) * sizeof(vud->qi[0])); - assert(vud->qi); + vud->qi = 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 = qidx + 1; } if (!vud->qi[qidx]) { - vud->qi[qidx] = calloc(sizeof(struct fv_QueueInfo), 1); - assert(vud->qi[qidx]); + vud->qi[qidx] = g_new0(struct fv_QueueInfo, 1); vud->qi[qidx]->virtio_dev = vud; vud->qi[qidx]->qidx = qidx; } else { @@ -1034,12 +1032,7 @@ int virtio_session_mount(struct fuse_session *se) __func__); /* TODO: Some cleanup/deallocation! */ - se->virtio_dev = 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 = g_new0(struct fv_VuDev, 1); se->vu_socketfd = data_sock; se->virtio_dev->se = se; @@ -1061,8 +1054,8 @@ void virtio_session_close(struct fuse_session *se) return; } - 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 = NULL; } From patchwork Fri Mar 19 13:25:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mahmoud Abumandour X-Patchwork-Id: 1455868 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=vfRGdKzO; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4F24bZ1kvNz9sWb for ; Sat, 20 Mar 2021 00:33:29 +1100 (AEDT) Received: from localhost ([::1]:46512 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lNFFn-0000D7-Qc for incoming@patchwork.ozlabs.org; Fri, 19 Mar 2021 09:33:27 -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) 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) 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) 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 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 = lo_data(req); struct lo_dirp *d = NULL; struct lo_inode *dinode; - char *buf = NULL; + g_autofree char *buf = NULL; char *p; size_t rem = size; int err = EBADF; @@ -1669,7 +1669,7 @@ static void lo_do_readdir(fuse_req_t req, fuse_ino_t ino, size_t size, } err = ENOMEM; - buf = calloc(1, size); + buf = g_try_malloc0(size); if (!buf) { goto error; } @@ -1755,7 +1755,6 @@ error: } else { fuse_reply_buf(req, buf, size - rem); } - free(buf); } 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 ino, const char *in_name, size_t size) { struct lo_data *lo = lo_data(req); - char *value = NULL; + g_autofree char *value = 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 ino, const char *in_name, ino, name, size); if (size) { - value = malloc(size); + value = g_try_malloc(size); if (!value) { goto out_err; } @@ -2806,8 +2805,6 @@ static void lo_getxattr(fuse_req_t req, fuse_ino_t ino, const char *in_name, fuse_reply_xattr(req, ret); } out_free: - free(value); - if (fd >= 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 = lo_data(req); - char *value = NULL; + g_autofree char *value = 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 ino, size_t size) size); if (size) { - value = malloc(size); + value = g_try_malloc(size); if (!value) { goto out_err; } @@ -2933,8 +2930,6 @@ static void lo_listxattr(fuse_req_t req, fuse_ino_t ino, size_t size) fuse_reply_xattr(req, ret); } out_free: - free(value); - if (fd >= 0) { close(fd); } From patchwork Fri Mar 19 13:25:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mahmoud Abumandour X-Patchwork-Id: 1455873 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=jQO5AkXB; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4F24kW2XrYz9s1l for ; Sat, 20 Mar 2021 00:39:31 +1100 (AEDT) Received: from localhost ([::1]:39586 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lNFLd-0000WN-CU for incoming@patchwork.ozlabs.org; Fri, 19 Mar 2021 09:39:29 -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) 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) 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) 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 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 user_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 = malloc(se->bufsize); - assert(fbuf.mem); + fbuf.mem = g_malloc(se->bufsize); fuse_mutex_init(&req->ch.lock); req->ch.fd = -1; @@ -524,7 +523,7 @@ static void fv_queue_worker(gpointer data, gpointer user_data) fbuf.size = out_sg[0].iov_len + out_sg[1].iov_len; /* Allocate the bufv, with space for the rest of the iov */ - pbufv = malloc(sizeof(struct fuse_bufvec) + + pbufv = 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 user_data) out: if (allocated_bufv) { - free(pbufv); + g_free(pbufv); } /* If the request has no reply, still recycle the virtqueue element */ @@ -588,7 +587,7 @@ out: } pthread_mutex_destroy(&req->ch.lock); - free(fbuf.mem); + g_free(fbuf.mem); free(req); }