From nobody Fri May 17 07:46:59 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=quarantine dis=none) header.from=crudebyte.com ARC-Seal: i=1; a=rsa-sha256; t=1629209225; cv=none; d=zohomail.com; s=zohoarc; b=J2S6PMkV8OBPvW8jQZ6SIcffD/pDXdrtqZHY5Kl22o5GKrFybBJSpIpu6KxrhnuDePA+c+P3cwsl3EQEJglvIkdlBFzOhxINIMLXTneBcSBXpZWdM/emKmJBEL5OmxfAJ4hcJEAdcg9dOuqgF/yiF9WJ+BhrxY6VMbFib7Ocna4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1629209225; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=OaO3YB+4zeFcNbwwHKkr3fnRXdRx4zTA07GodXV//E8=; b=PEnAT9vYAS4MMFiDt5ktG/S4qlnAd/Kfibp5iBg++9LGaZxWEU7zMqM2BXwC/OF5RSHkHL4wDKvcnfNUNcgJh6xR3FBbnVnkL5bf1lk4jdOxfXgkVp0c20+FMK8FoahmR5+iz1OC4sgL3WRZCDVS/pzFCZZVc4bkltv97WgcMPs= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1629209225587424.44443582800545; Tue, 17 Aug 2021 07:07:05 -0700 (PDT) Received: from localhost ([::1]:37568 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mFzk7-0002h2-QC for importer@patchew.org; Tue, 17 Aug 2021 10:07:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43716) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <7dacbecf25b2c9b4a0ce12d689a8a535f09a31e3@lizzy.crudebyte.com>) id 1mFziy-0000s7-78 for qemu-devel@nongnu.org; Tue, 17 Aug 2021 10:05:52 -0400 Received: from lizzy.crudebyte.com ([91.194.90.13]:38451) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <7dacbecf25b2c9b4a0ce12d689a8a535f09a31e3@lizzy.crudebyte.com>) id 1mFzit-0006aT-CJ for qemu-devel@nongnu.org; Tue, 17 Aug 2021 10:05:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=crudebyte.com; s=lizzy; h=Cc:To:Subject:Date:From:References:In-Reply-To: Message-Id:Content-Type:Content-Transfer-Encoding:MIME-Version:Content-ID: Content-Description; bh=OaO3YB+4zeFcNbwwHKkr3fnRXdRx4zTA07GodXV//E8=; b=WwXEb OzBXBIA+BS5SYEqM1yniX7bz0ut3x3bm+AnMc91tG7lNIW7m+ARq8Oa7yzzbTnFdacPYGJihvCmox wDCgLgx+yDJ+HY8PqfN1X9sUN9CiccQHigg0MCC1K6dZX493FzNHIpquKirSzLJZMGTfr0GCqfa8D BS4XGEb0vblQm0xMzcSPLqClXJ08A6v1H3avQcyTYCl6EHNOJUBcWUS7B65njpoNIeZEpb4zBDqBm jDq5FsT3TKqsrv/Zvmn2JojqBRr+Q8hqW8WILa2PWpRfVTfXa7su3aLnFIRR/jaLNBMgTX8s4gGO+ RQO/xQ8Lp76cRtm94Wd+6uKqPYuRQ==; Message-Id: <7dacbecf25b2c9b4a0ce12d689a8a535f09a31e3.1629208359.git.qemu_oss@crudebyte.com> In-Reply-To: References: From: Christian Schoenebeck Date: Tue, 17 Aug 2021 14:38:24 +0200 Subject: [PATCH 1/2] hw/9pfs: avoid 'path' copy in v9fs_walk() To: qemu-devel@nongnu.org Cc: Greg Kurz 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: none client-ip=91.194.90.13; envelope-from=7dacbecf25b2c9b4a0ce12d689a8a535f09a31e3@lizzy.crudebyte.com; helo=lizzy.crudebyte.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, SPF_HELO_NONE=0.001, SPF_NONE=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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @crudebyte.com) X-ZM-MESSAGEID: 1629209228176100001 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The v9fs_walk() function resolves all client submitted path nodes to the local 'pathes' array. Using a separate string scalar variable 'path' inside the background worker thread loop and copying that local 'path' string scalar variable subsequently to the 'pathes' array (at the end of each loop iteration) is not necessary. Instead simply resolve each path directly to the 'pathes' array and don't use the string scalar variable 'path' inside the fs worker thread loop at all. The only advantage of the 'path' scalar was that in case of an error the respective 'pathes' element would not be filled. Right now this is not an issue as the v9fs_walk() function returns as soon as any error occurs. Suggested-by: Greg Kurz Signed-off-by: Christian Schoenebeck Reviewed-by: Greg Kurz --- hw/9pfs/9p.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c index 2815257f42..4d642ab12a 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -1787,7 +1787,8 @@ static void coroutine_fn v9fs_walk(void *opaque) strcmp("..", wnames[name_idx].data)) { err =3D s->ops->name_to_path(&s->ctx, &dpath, - wnames[name_idx].data, &path); + wnames[name_idx].data, + &pathes[name_idx]); if (err < 0) { err =3D -errno; break; @@ -1796,14 +1797,13 @@ static void coroutine_fn v9fs_walk(void *opaque) err =3D -EINTR; break; } - err =3D s->ops->lstat(&s->ctx, &path, &stbuf); + err =3D s->ops->lstat(&s->ctx, &pathes[name_idx], &stbuf); if (err < 0) { err =3D -errno; break; } stbufs[name_idx] =3D stbuf; - v9fs_path_copy(&dpath, &path); - v9fs_path_copy(&pathes[name_idx], &path); + v9fs_path_copy(&dpath, &pathes[name_idx]); } } }); --=20 2.20.1 From nobody Fri May 17 07:46:59 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=quarantine dis=none) header.from=crudebyte.com ARC-Seal: i=1; a=rsa-sha256; t=1629209254; cv=none; d=zohomail.com; s=zohoarc; b=HJCB/zAlpb0EsG2U4jN9W4f8tV/1ikZBe/BtfDzii/r16E3NRz6ZRaiuNxgnVjWNgTUsWStp+PoYUlup4vCpeNnf0aHENEZvNfIIJdSdTczgwkIaabNFP8oCpkUVSAd7kJ13sFxgQbeBpUucXmsOunpBQykgtKs3vz+pEBn4F/M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1629209254; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=6dyL740HRzi5q7b7aP9+G2NOBKE2CUMD9VrR61TTY1E=; b=KTZtDow23rD3Gwa+GKHdWoOEQpDXWJIRkGh+m/q3s9hszAvyIiSqgjOEgKOn5wYyuLjET1f/MGTUX0Qw2Ve3tKN+QgKW9EYul1MGeyjTUj7j0m/YpmU6jaZkxWLJofXVFC37DZvFGSTVukP8PH8UVSo4wxDxIIg1VV6NOVh2H/g= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1629209254559762.0125156448041; Tue, 17 Aug 2021 07:07:34 -0700 (PDT) Received: from localhost ([::1]:38264 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mFzkb-00038n-5X for importer@patchew.org; Tue, 17 Aug 2021 10:07:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43746) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mFzj0-0000sf-OK for qemu-devel@nongnu.org; Tue, 17 Aug 2021 10:05:54 -0400 Received: from lizzy.crudebyte.com ([91.194.90.13]:57549) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mFziz-0006fP-EM for qemu-devel@nongnu.org; Tue, 17 Aug 2021 10:05:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=crudebyte.com; s=lizzy; h=Cc:To:Subject:Date:From:References:In-Reply-To: Message-Id:Content-Type:Content-Transfer-Encoding:MIME-Version:Content-ID: Content-Description; bh=6dyL740HRzi5q7b7aP9+G2NOBKE2CUMD9VrR61TTY1E=; b=Kglrg R1QeSDwHgKTtuVNqb6V8EoZw3GWlggO17bxYsUDhKsf84qh7116K7FYg2XCgkSYhra/lqueK3l7qu kzxfwgaMHKXHCuBdN0mc7sg2YLdVPmmofrENmqSMq0IUr+Lz33lC5YEQDHx1PobqFfuN8018ghfb2 SbyfqXz/P2o7sAAHmXmhNHcsPIiPvagzSg/9RrjJ8FnbDR1RYIAFC9RE4gl4sE9obs+Lcb+J/8/dA lzf+eJOuewTjQQr4FvJv+p4yIen5Td+WXo0Dcf3A7cs/QM/s6dB37VVjMeqjQ/uoTTYn0eQAJIjJa J1LIxQ3IXhudH7xZYkhkzjeBM7sqA==; Message-Id: In-Reply-To: References: From: Christian Schoenebeck Date: Tue, 17 Aug 2021 15:46:50 +0200 Subject: [PATCH 2/2] hw/9pfs: use g_autofree in v9fs_walk() where possible To: qemu-devel@nongnu.org Cc: Greg Kurz 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: none client-ip=91.194.90.13; envelope-from=b51670d2a39399535a035f6bc77c3cbeed85edae@lizzy.crudebyte.com; helo=lizzy.crudebyte.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, SPF_HELO_NONE=0.001, SPF_NONE=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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @crudebyte.com) X-ZM-MESSAGEID: 1629209255986100001 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Suggested-by: Greg Kurz Signed-off-by: Christian Schoenebeck Reviewed-by: Greg Kurz Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/9pfs/9p.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c index 4d642ab12a..c857b31321 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -1703,11 +1703,12 @@ static bool same_stat_id(const struct stat *a, cons= t struct stat *b) static void coroutine_fn v9fs_walk(void *opaque) { int name_idx; - V9fsQID *qids =3D NULL; + g_autofree V9fsQID *qids =3D NULL; int i, err =3D 0; V9fsPath dpath, path, *pathes =3D NULL; uint16_t nwnames; - struct stat stbuf, fidst, *stbufs =3D NULL; + struct stat stbuf, fidst; + g_autofree struct stat *stbufs =3D NULL; size_t offset =3D 7; int32_t fid, newfid; V9fsString *wnames =3D NULL; @@ -1872,8 +1873,6 @@ out_nofid: v9fs_path_free(&pathes[name_idx]); } g_free(wnames); - g_free(qids); - g_free(stbufs); g_free(pathes); } } --=20 2.20.1