From patchwork Tue Jul 27 21:17:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goldwyn Rodrigues X-Patchwork-Id: 12404209 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4C0BCC4320E for ; Tue, 27 Jul 2021 21:19:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3313360F6E for ; Tue, 27 Jul 2021 21:19:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234939AbhG0VT1 (ORCPT ); Tue, 27 Jul 2021 17:19:27 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:48680 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234329AbhG0VRw (ORCPT ); Tue, 27 Jul 2021 17:17:52 -0400 Received: from imap1.suse-dmz.suse.de (imap1.suse-dmz.suse.de [192.168.254.73]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 704062225F; Tue, 27 Jul 2021 21:17:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1627420669; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+E0xUIJZHsW17IpTJAF8whOwg78kaxbefCWM2mIXd9c=; b=c2YLT9h/vmJDwQTgY5i2/fPysSa6+PKGEU+7ju+PuCFOR5PLUeh/Ev4RszgcPraYCzNdjj QrwsnYxQAaPJ8wjOPW/SnxJP9U6iais9ZCik8p7UXZhqKclDJKuF3yIuMmUlmwrhSK8wOd OQ6DcfU0ZTUMPDDtEDS7Pr2/Jjz2iOI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1627420669; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+E0xUIJZHsW17IpTJAF8whOwg78kaxbefCWM2mIXd9c=; b=j+564oqTDY6a1CUmRRvKs/F1JSKByht6VUbvR2gY2V4O6acRnIrQ7edVZ+VGNt1ZLNDmbf LxcdtGLu8fnMyoDQ== Received: from imap1.suse-dmz.suse.de (imap1.suse-dmz.suse.de [192.168.254.73]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap1.suse-dmz.suse.de (Postfix) with ESMTPS id 05BBB133DE; Tue, 27 Jul 2021 21:17:48 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap1.suse-dmz.suse.de with ESMTPSA id q9luKPx3AGFydQAAGKfGzw (envelope-from ); Tue, 27 Jul 2021 21:17:48 +0000 From: Goldwyn Rodrigues To: linux-btrfs@vger.kernel.org Cc: Goldwyn Rodrigues Subject: [PATCH 1/7] btrfs: Allocate walk_control on stack Date: Tue, 27 Jul 2021 16:17:25 -0500 Message-Id: <381dc8c84c07b4eecc8b5de6686d79ad5c60ae58.1627418762.git.rgoldwyn@suse.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Goldwyn Rodrigues Instead of using kmalloc() to allocate walk_control, allocate walk_control on stack. No need to memset() a struct to zero if it is initialized to zero. sizeof(walk_control) = 200 Signed-off-by: Goldwyn Rodrigues --- fs/btrfs/extent-tree.c | 89 +++++++++++++++++------------------------- 1 file changed, 36 insertions(+), 53 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index fc3da7585fb7..a66cb2e5146f 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -5484,7 +5484,7 @@ int btrfs_drop_snapshot(struct btrfs_root *root, int update_ref, int for_reloc) struct btrfs_trans_handle *trans; struct btrfs_root *tree_root = fs_info->tree_root; struct btrfs_root_item *root_item = &root->root_item; - struct walk_control *wc; + struct walk_control wc = {0}; struct btrfs_key key; int err = 0; int ret; @@ -5499,13 +5499,6 @@ int btrfs_drop_snapshot(struct btrfs_root *root, int update_ref, int for_reloc) goto out; } - wc = kzalloc(sizeof(*wc), GFP_NOFS); - if (!wc) { - btrfs_free_path(path); - err = -ENOMEM; - goto out; - } - /* * Use join to avoid potential EINTR from transaction start. See * wait_reserve_ticket and the whole reservation callchain. @@ -5537,12 +5530,10 @@ int btrfs_drop_snapshot(struct btrfs_root *root, int update_ref, int for_reloc) path->nodes[level] = btrfs_lock_root_node(root); path->slots[level] = 0; path->locks[level] = BTRFS_WRITE_LOCK; - memset(&wc->update_progress, 0, - sizeof(wc->update_progress)); } else { btrfs_disk_key_to_cpu(&key, &root_item->drop_progress); - memcpy(&wc->update_progress, &key, - sizeof(wc->update_progress)); + memcpy(&wc.update_progress, &key, + sizeof(wc.update_progress)); level = btrfs_root_drop_level(root_item); BUG_ON(level == 0); @@ -5568,62 +5559,62 @@ int btrfs_drop_snapshot(struct btrfs_root *root, int update_ref, int for_reloc) ret = btrfs_lookup_extent_info(trans, fs_info, path->nodes[level]->start, - level, 1, &wc->refs[level], - &wc->flags[level]); + level, 1, &wc.refs[level], + &wc.flags[level]); if (ret < 0) { err = ret; goto out_end_trans; } - BUG_ON(wc->refs[level] == 0); + BUG_ON(wc.refs[level] == 0); if (level == btrfs_root_drop_level(root_item)) break; btrfs_tree_unlock(path->nodes[level]); path->locks[level] = 0; - WARN_ON(wc->refs[level] != 1); + WARN_ON(wc.refs[level] != 1); level--; } } - wc->restarted = test_bit(BTRFS_ROOT_DEAD_TREE, &root->state); - wc->level = level; - wc->shared_level = -1; - wc->stage = DROP_REFERENCE; - wc->update_ref = update_ref; - wc->keep_locks = 0; - wc->reada_count = BTRFS_NODEPTRS_PER_BLOCK(fs_info); + wc.restarted = test_bit(BTRFS_ROOT_DEAD_TREE, &root->state); + wc.level = level; + wc.shared_level = -1; + wc.stage = DROP_REFERENCE; + wc.update_ref = update_ref; + wc.keep_locks = 0; + wc.reada_count = BTRFS_NODEPTRS_PER_BLOCK(fs_info); while (1) { - ret = walk_down_tree(trans, root, path, wc); + ret = walk_down_tree(trans, root, path, &wc); if (ret < 0) { err = ret; break; } - ret = walk_up_tree(trans, root, path, wc, BTRFS_MAX_LEVEL); + ret = walk_up_tree(trans, root, path, &wc, BTRFS_MAX_LEVEL); if (ret < 0) { err = ret; break; } if (ret > 0) { - BUG_ON(wc->stage != DROP_REFERENCE); + BUG_ON(wc.stage != DROP_REFERENCE); break; } - if (wc->stage == DROP_REFERENCE) { - wc->drop_level = wc->level; - btrfs_node_key_to_cpu(path->nodes[wc->drop_level], - &wc->drop_progress, - path->slots[wc->drop_level]); + if (wc.stage == DROP_REFERENCE) { + wc.drop_level = wc.level; + btrfs_node_key_to_cpu(path->nodes[wc.drop_level], + &wc.drop_progress, + path->slots[wc.drop_level]); } btrfs_cpu_key_to_disk(&root_item->drop_progress, - &wc->drop_progress); - btrfs_set_root_drop_level(root_item, wc->drop_level); + &wc.drop_progress); + btrfs_set_root_drop_level(root_item, wc.drop_level); - BUG_ON(wc->level == 0); + BUG_ON(wc.level == 0); if (btrfs_should_end_transaction(trans) || (!for_reloc && btrfs_need_cleaner_sleep(fs_info))) { ret = btrfs_update_root(trans, tree_root, @@ -5703,7 +5694,6 @@ int btrfs_drop_snapshot(struct btrfs_root *root, int update_ref, int for_reloc) out_end_trans: btrfs_end_transaction_throttle(trans); out_free: - kfree(wc); btrfs_free_path(path); out: /* @@ -5731,7 +5721,7 @@ int btrfs_drop_subtree(struct btrfs_trans_handle *trans, { struct btrfs_fs_info *fs_info = root->fs_info; struct btrfs_path *path; - struct walk_control *wc; + struct walk_control wc = {0}; int level; int parent_level; int ret = 0; @@ -5743,12 +5733,6 @@ int btrfs_drop_subtree(struct btrfs_trans_handle *trans, if (!path) return -ENOMEM; - wc = kzalloc(sizeof(*wc), GFP_NOFS); - if (!wc) { - btrfs_free_path(path); - return -ENOMEM; - } - btrfs_assert_tree_locked(parent); parent_level = btrfs_header_level(parent); atomic_inc(&parent->refs); @@ -5761,30 +5745,29 @@ int btrfs_drop_subtree(struct btrfs_trans_handle *trans, path->slots[level] = 0; path->locks[level] = BTRFS_WRITE_LOCK; - wc->refs[parent_level] = 1; - wc->flags[parent_level] = BTRFS_BLOCK_FLAG_FULL_BACKREF; - wc->level = level; - wc->shared_level = -1; - wc->stage = DROP_REFERENCE; - wc->update_ref = 0; - wc->keep_locks = 1; - wc->reada_count = BTRFS_NODEPTRS_PER_BLOCK(fs_info); + wc.refs[parent_level] = 1; + wc.flags[parent_level] = BTRFS_BLOCK_FLAG_FULL_BACKREF; + wc.level = level; + wc.shared_level = -1; + wc.stage = DROP_REFERENCE; + wc.update_ref = 0; + wc.keep_locks = 1; + wc.reada_count = BTRFS_NODEPTRS_PER_BLOCK(fs_info); while (1) { - wret = walk_down_tree(trans, root, path, wc); + wret = walk_down_tree(trans, root, path, &wc); if (wret < 0) { ret = wret; break; } - wret = walk_up_tree(trans, root, path, wc, parent_level); + wret = walk_up_tree(trans, root, path, &wc, parent_level); if (wret < 0) ret = wret; if (wret != 0) break; } - kfree(wc); btrfs_free_path(path); return ret; } From patchwork Tue Jul 27 21:17:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goldwyn Rodrigues X-Patchwork-Id: 12404211 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, UNWANTED_LANGUAGE_BODY,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1938BC432BE for ; Tue, 27 Jul 2021 21:19:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 019C960BD3 for ; Tue, 27 Jul 2021 21:19:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234989AbhG0VT2 (ORCPT ); Tue, 27 Jul 2021 17:19:28 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:48686 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234427AbhG0VRx (ORCPT ); Tue, 27 Jul 2021 17:17:53 -0400 Received: from imap1.suse-dmz.suse.de (imap1.suse-dmz.suse.de [192.168.254.73]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 8220E22274; Tue, 27 Jul 2021 21:17:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1627420672; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zp9QHZTHlySlM4NbUf634gCV7sA9Fjtxj5yGsb/PmnE=; b=q9q4SjoYFedaTBkEcwGfrR50c5xTIuBbquyFfkw1UG3oyiWxSt7pM81oKYQFgthw7/j2jN pmPzbHCRnIXfguTWJJEEQ7oEoGZJ4r0ep2JsB4SFc92M7BeKphkrzTsrmzSPAUmhExRtOP IUGtl763x2u/UPrT1Anh2G7VkJcW0tA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1627420672; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zp9QHZTHlySlM4NbUf634gCV7sA9Fjtxj5yGsb/PmnE=; b=JS4cB70fkdyC5e4TE/OcqUK9MFa4DNeP0CUX3pY60Xu7aLdRRPHrhp9JpxSWwKp0+j1vk4 YK5C6wxugcw6/BDg== Received: from imap1.suse-dmz.suse.de (imap1.suse-dmz.suse.de [192.168.254.73]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap1.suse-dmz.suse.de (Postfix) with ESMTPS id E3EE7133DE; Tue, 27 Jul 2021 21:17:51 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap1.suse-dmz.suse.de with ESMTPSA id GmphLf93AGF3dQAAGKfGzw (envelope-from ); Tue, 27 Jul 2021 21:17:51 +0000 From: Goldwyn Rodrigues To: linux-btrfs@vger.kernel.org Cc: Goldwyn Rodrigues Subject: [PATCH 2/7] btrfs: Allocate file_ra_state on stack Date: Tue, 27 Jul 2021 16:17:26 -0500 Message-Id: <2bb91af815d028ed3231910fcc5d8c6779ebf79c.1627418762.git.rgoldwyn@suse.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Goldwyn Rodrigues Instead of allocating file_ra_state using kmalloc, allocate on stack. sizeof(struct readahead) = 32 bytes Signed-off-by: Goldwyn Rodrigues --- fs/btrfs/free-space-cache.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c index 2131ae5b9ed7..8eeb65278ac0 100644 --- a/fs/btrfs/free-space-cache.c +++ b/fs/btrfs/free-space-cache.c @@ -344,19 +344,13 @@ int btrfs_truncate_free_space_cache(struct btrfs_trans_handle *trans, static void readahead_cache(struct inode *inode) { - struct file_ra_state *ra; + struct file_ra_state ra; unsigned long last_index; - ra = kzalloc(sizeof(*ra), GFP_NOFS); - if (!ra) - return; - - file_ra_state_init(ra, inode->i_mapping); + file_ra_state_init(&ra, inode->i_mapping); last_index = (i_size_read(inode) - 1) >> PAGE_SHIFT; - page_cache_sync_readahead(inode->i_mapping, ra, NULL, 0, last_index); - - kfree(ra); + page_cache_sync_readahead(inode->i_mapping, &ra, NULL, 0, last_index); } static int io_ctl_init(struct btrfs_io_ctl *io_ctl, struct inode *inode, From patchwork Tue Jul 27 21:17:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goldwyn Rodrigues X-Patchwork-Id: 12404219 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1F152C432BE for ; Tue, 27 Jul 2021 21:19:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 08EC060F6E for ; Tue, 27 Jul 2021 21:19:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234662AbhG0VTk (ORCPT ); Tue, 27 Jul 2021 17:19:40 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:45968 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234511AbhG0VR5 (ORCPT ); Tue, 27 Jul 2021 17:17:57 -0400 Received: from imap1.suse-dmz.suse.de (imap1.suse-dmz.suse.de [192.168.254.73]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 0A6A42017C; Tue, 27 Jul 2021 21:17:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1627420676; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=frYSfLVEsDV2Yukyj70wAHokIYWt5tbtqzv6kNoUs+c=; b=TK7/Kn8quor4ZRDZGOS9JC4owDVeL6sDiRjt2Ty1RTjBXNY8R5V8JOS0SC+HlKjUE4wo3g bXJXCA27VvT1RLGc4W5XAN4o9i8s4Drz/HnXjj9hoRF2YJQ+zTulu6iXoDw6Z+SH3lJoxG W6QRvTPwNSr86+xr/XzZC5TTZeQAAFk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1627420676; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=frYSfLVEsDV2Yukyj70wAHokIYWt5tbtqzv6kNoUs+c=; b=P3Q73o4/OVF0iCuda9AIUdBeQAn+P121GnuZ3xfBOTNruNfV7Z6wUxnSrFvmCDCm2nCMc8 t/w/6nhVe2HAprBw== Received: from imap1.suse-dmz.suse.de (imap1.suse-dmz.suse.de [192.168.254.73]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap1.suse-dmz.suse.de (Postfix) with ESMTPS id 8FF88133DE; Tue, 27 Jul 2021 21:17:55 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap1.suse-dmz.suse.de with ESMTPSA id Dt9GDwN4AGF7dQAAGKfGzw (envelope-from ); Tue, 27 Jul 2021 21:17:55 +0000 From: Goldwyn Rodrigues To: linux-btrfs@vger.kernel.org Cc: Goldwyn Rodrigues Subject: [PATCH 3/7] btrfs: Allocate btrfs_ioctl_get_subvol_info_args on stack Date: Tue, 27 Jul 2021 16:17:27 -0500 Message-Id: <2200f9340973d627ee304ac4470f5921061266f9.1627418762.git.rgoldwyn@suse.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Goldwyn Rodrigues Instead of using kmalloc() to allocate btrfs_ioctl_get_subvol_info_args, allocate btrfs_ioctl_get_subvol_info_args on stack. sizeof(btrfs_ioctl_get_subvol_info_args) = 504 Signed-off-by: Goldwyn Rodrigues Reviewed-by: Anand Jain --- fs/btrfs/ioctl.c | 55 +++++++++++++++++++++--------------------------- 1 file changed, 24 insertions(+), 31 deletions(-) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 0ba98e08a029..90b134b5a653 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -2681,7 +2681,7 @@ static int btrfs_ioctl_ino_lookup_user(struct file *file, void __user *argp) /* Get the subvolume information in BTRFS_ROOT_ITEM and BTRFS_ROOT_BACKREF */ static int btrfs_ioctl_get_subvol_info(struct file *file, void __user *argp) { - struct btrfs_ioctl_get_subvol_info_args *subvol_info; + struct btrfs_ioctl_get_subvol_info_args subvol_info = {0}; struct btrfs_fs_info *fs_info; struct btrfs_root *root; struct btrfs_path *path; @@ -2699,12 +2699,6 @@ static int btrfs_ioctl_get_subvol_info(struct file *file, void __user *argp) if (!path) return -ENOMEM; - subvol_info = kzalloc(sizeof(*subvol_info), GFP_KERNEL); - if (!subvol_info) { - btrfs_free_path(path); - return -ENOMEM; - } - inode = file_inode(file); fs_info = BTRFS_I(inode)->root->fs_info; @@ -2717,32 +2711,32 @@ static int btrfs_ioctl_get_subvol_info(struct file *file, void __user *argp) } root_item = &root->root_item; - subvol_info->treeid = key.objectid; + subvol_info.treeid = key.objectid; - subvol_info->generation = btrfs_root_generation(root_item); - subvol_info->flags = btrfs_root_flags(root_item); + subvol_info.generation = btrfs_root_generation(root_item); + subvol_info.flags = btrfs_root_flags(root_item); - memcpy(subvol_info->uuid, root_item->uuid, BTRFS_UUID_SIZE); - memcpy(subvol_info->parent_uuid, root_item->parent_uuid, + memcpy(subvol_info.uuid, root_item->uuid, BTRFS_UUID_SIZE); + memcpy(subvol_info.parent_uuid, root_item->parent_uuid, BTRFS_UUID_SIZE); - memcpy(subvol_info->received_uuid, root_item->received_uuid, + memcpy(subvol_info.received_uuid, root_item->received_uuid, BTRFS_UUID_SIZE); - subvol_info->ctransid = btrfs_root_ctransid(root_item); - subvol_info->ctime.sec = btrfs_stack_timespec_sec(&root_item->ctime); - subvol_info->ctime.nsec = btrfs_stack_timespec_nsec(&root_item->ctime); + subvol_info.ctransid = btrfs_root_ctransid(root_item); + subvol_info.ctime.sec = btrfs_stack_timespec_sec(&root_item->ctime); + subvol_info.ctime.nsec = btrfs_stack_timespec_nsec(&root_item->ctime); - subvol_info->otransid = btrfs_root_otransid(root_item); - subvol_info->otime.sec = btrfs_stack_timespec_sec(&root_item->otime); - subvol_info->otime.nsec = btrfs_stack_timespec_nsec(&root_item->otime); + subvol_info.otransid = btrfs_root_otransid(root_item); + subvol_info.otime.sec = btrfs_stack_timespec_sec(&root_item->otime); + subvol_info.otime.nsec = btrfs_stack_timespec_nsec(&root_item->otime); - subvol_info->stransid = btrfs_root_stransid(root_item); - subvol_info->stime.sec = btrfs_stack_timespec_sec(&root_item->stime); - subvol_info->stime.nsec = btrfs_stack_timespec_nsec(&root_item->stime); + subvol_info.stransid = btrfs_root_stransid(root_item); + subvol_info.stime.sec = btrfs_stack_timespec_sec(&root_item->stime); + subvol_info.stime.nsec = btrfs_stack_timespec_nsec(&root_item->stime); - subvol_info->rtransid = btrfs_root_rtransid(root_item); - subvol_info->rtime.sec = btrfs_stack_timespec_sec(&root_item->rtime); - subvol_info->rtime.nsec = btrfs_stack_timespec_nsec(&root_item->rtime); + subvol_info.rtransid = btrfs_root_rtransid(root_item); + subvol_info.rtime.sec = btrfs_stack_timespec_sec(&root_item->rtime); + subvol_info.rtime.nsec = btrfs_stack_timespec_nsec(&root_item->rtime); if (key.objectid != BTRFS_FS_TREE_OBJECTID) { /* Search root tree for ROOT_BACKREF of this subvolume */ @@ -2765,18 +2759,18 @@ static int btrfs_ioctl_get_subvol_info(struct file *file, void __user *argp) leaf = path->nodes[0]; slot = path->slots[0]; btrfs_item_key_to_cpu(leaf, &key, slot); - if (key.objectid == subvol_info->treeid && + if (key.objectid == subvol_info.treeid && key.type == BTRFS_ROOT_BACKREF_KEY) { - subvol_info->parent_id = key.offset; + subvol_info.parent_id = key.offset; rref = btrfs_item_ptr(leaf, slot, struct btrfs_root_ref); - subvol_info->dirid = btrfs_root_ref_dirid(leaf, rref); + subvol_info.dirid = btrfs_root_ref_dirid(leaf, rref); item_off = btrfs_item_ptr_offset(leaf, slot) + sizeof(struct btrfs_root_ref); item_len = btrfs_item_size_nr(leaf, slot) - sizeof(struct btrfs_root_ref); - read_extent_buffer(leaf, subvol_info->name, + read_extent_buffer(leaf, subvol_info.name, item_off, item_len); } else { ret = -ENOENT; @@ -2784,14 +2778,13 @@ static int btrfs_ioctl_get_subvol_info(struct file *file, void __user *argp) } } - if (copy_to_user(argp, subvol_info, sizeof(*subvol_info))) + if (copy_to_user(argp, &subvol_info, sizeof(subvol_info))) ret = -EFAULT; out: btrfs_put_root(root); out_free: btrfs_free_path(path); - kfree(subvol_info); return ret; } From patchwork Tue Jul 27 21:17:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goldwyn Rodrigues X-Patchwork-Id: 12404217 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1EB29C432BE for ; Tue, 27 Jul 2021 21:19:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0C85A60F90 for ; Tue, 27 Jul 2021 21:19:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234298AbhG0VTi (ORCPT ); Tue, 27 Jul 2021 17:19:38 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:45978 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232460AbhG0VSA (ORCPT ); Tue, 27 Jul 2021 17:18:00 -0400 Received: from imap1.suse-dmz.suse.de (imap1.suse-dmz.suse.de [192.168.254.73]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id DD3882017E; Tue, 27 Jul 2021 21:17:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1627420678; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rEyIH/bOS8Bn4awUHidr6TSJf8z50TURL1HGFB7wI8k=; b=XHQs5X3Q32kOVSgi22PHq4NvhB3oU4IQEezyaKjf4Yy24nNhlP2hVjrGXs1sYOHhrqLv3o 7b9L0OgW0uQeriD5FMov6uCrYkaMjxkkdFTVq1l2pUV4Wb9cJA7EykewsbWda/B2rsrPPZ ODp4DhmDGtkyDun0USqJQ0B56MuQhrE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1627420678; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rEyIH/bOS8Bn4awUHidr6TSJf8z50TURL1HGFB7wI8k=; b=XZrILikg2renP7pQUQrtP9XbDwdEs7c0Bu2qS/mlzac+53X/MTp22uKy/iBKdnZhfyUZtC fwOHOqDvATyb0LDQ== Received: from imap1.suse-dmz.suse.de (imap1.suse-dmz.suse.de [192.168.254.73]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap1.suse-dmz.suse.de (Postfix) with ESMTPS id 6FAAF133DE; Tue, 27 Jul 2021 21:17:58 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap1.suse-dmz.suse.de with ESMTPSA id pCOkBwZ4AGGBdQAAGKfGzw (envelope-from ); Tue, 27 Jul 2021 21:17:58 +0000 From: Goldwyn Rodrigues To: linux-btrfs@vger.kernel.org Cc: Goldwyn Rodrigues Subject: [PATCH 4/7] btrfs: Allocate btrfs_ioctl_balance_args on stack Date: Tue, 27 Jul 2021 16:17:28 -0500 Message-Id: <320216bed8e0c28e9235571db1962cbb1e18366a.1627418762.git.rgoldwyn@suse.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Goldwyn Rodrigues Instead of using kmalloc() to allocate btrfs_ioctl_balance_args, allocate btrfs_ioctl_balance_args on stack. sizeof(btrfs_ioctl_balance_args) = 1024 Signed-off-by: Goldwyn Rodrigues Reported-by: kernel test robot --- fs/btrfs/ioctl.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 90b134b5a653..9c3acc539052 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -4141,7 +4141,7 @@ static long btrfs_ioctl_balance_ctl(struct btrfs_fs_info *fs_info, int cmd) static long btrfs_ioctl_balance_progress(struct btrfs_fs_info *fs_info, void __user *arg) { - struct btrfs_ioctl_balance_args *bargs; + struct btrfs_ioctl_balance_args bargs = {0}; int ret = 0; if (!capable(CAP_SYS_ADMIN)) @@ -4153,18 +4153,11 @@ static long btrfs_ioctl_balance_progress(struct btrfs_fs_info *fs_info, goto out; } - bargs = kzalloc(sizeof(*bargs), GFP_KERNEL); - if (!bargs) { - ret = -ENOMEM; - goto out; - } - - btrfs_update_ioctl_balance_args(fs_info, bargs); + btrfs_update_ioctl_balance_args(fs_info, &bargs); - if (copy_to_user(arg, bargs, sizeof(*bargs))) + if (copy_to_user(arg, &bargs, sizeof(bargs))) ret = -EFAULT; - kfree(bargs); out: mutex_unlock(&fs_info->balance_mutex); return ret; From patchwork Tue Jul 27 21:17:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goldwyn Rodrigues X-Patchwork-Id: 12404215 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3E930C432BE for ; Tue, 27 Jul 2021 21:19:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 293DA60FF1 for ; Tue, 27 Jul 2021 21:19:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232142AbhG0VTh (ORCPT ); Tue, 27 Jul 2021 17:19:37 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:45986 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235050AbhG0VSD (ORCPT ); Tue, 27 Jul 2021 17:18:03 -0400 Received: from imap1.suse-dmz.suse.de (imap1.suse-dmz.suse.de [192.168.254.73]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 0BBD82017F; Tue, 27 Jul 2021 21:18:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1627420682; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6EM0oWVPxmOcyDguIStTCYKUhiSMxP/xNZbOx6mKJYg=; b=BC8+Rgr54jp0o8JDzSsaZ2+DdH1siopwwNFkVQi9EPLcs9UJS9ctWySsbm1H1XvbzZRfL2 kV7chgPGMkOT3YK7cIdLiDQptu63b1uEHerBFt7kPsifRr87vpJS5Xz04hErJkMdJLE3Lm dJM9TqB2+8H+/iIKe9Un7wP2FBdW1u4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1627420682; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6EM0oWVPxmOcyDguIStTCYKUhiSMxP/xNZbOx6mKJYg=; b=GjapjOeP7YDU1tWip16HSRPNPxs3o39PJNt4BReEukclkUBi/yhr6FXdz2lzZ1khhsYtcZ mS6WDi5TNMF1GcBQ== Received: from imap1.suse-dmz.suse.de (imap1.suse-dmz.suse.de [192.168.254.73]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap1.suse-dmz.suse.de (Postfix) with ESMTPS id 9CA97133DE; Tue, 27 Jul 2021 21:18:01 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap1.suse-dmz.suse.de with ESMTPSA id zub8HAl4AGGJdQAAGKfGzw (envelope-from ); Tue, 27 Jul 2021 21:18:01 +0000 From: Goldwyn Rodrigues To: linux-btrfs@vger.kernel.org Cc: Goldwyn Rodrigues Subject: [PATCH 5/7] btrfs: Allocate btrfs_ioctl_quota_rescan_args on stack Date: Tue, 27 Jul 2021 16:17:29 -0500 Message-Id: <4bfd049f4d8956c6b257e2cf2a69373c90a0f35e.1627418762.git.rgoldwyn@suse.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Goldwyn Rodrigues Instead of using kmalloc() to allocate btrfs_ioctl_quota_rescan_args, allocate btrfs_ioctl_quota_rescan_args on stack. sizeof(btrfs_ioctl_quota_rescan_args) = 64 Signed-off-by: Goldwyn Rodrigues Reviewed-by: Anand Jain --- fs/btrfs/ioctl.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 9c3acc539052..291c16d8576b 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -4390,25 +4390,20 @@ static long btrfs_ioctl_quota_rescan(struct file *file, void __user *arg) static long btrfs_ioctl_quota_rescan_status(struct btrfs_fs_info *fs_info, void __user *arg) { - struct btrfs_ioctl_quota_rescan_args *qsa; + struct btrfs_ioctl_quota_rescan_args qsa = {0}; int ret = 0; if (!capable(CAP_SYS_ADMIN)) return -EPERM; - qsa = kzalloc(sizeof(*qsa), GFP_KERNEL); - if (!qsa) - return -ENOMEM; - if (fs_info->qgroup_flags & BTRFS_QGROUP_STATUS_FLAG_RESCAN) { - qsa->flags = 1; - qsa->progress = fs_info->qgroup_rescan_progress.objectid; + qsa.flags = 1; + qsa.progress = fs_info->qgroup_rescan_progress.objectid; } - if (copy_to_user(arg, qsa, sizeof(*qsa))) + if (copy_to_user(arg, &qsa, sizeof(qsa))) ret = -EFAULT; - kfree(qsa); return ret; } From patchwork Tue Jul 27 21:17:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goldwyn Rodrigues X-Patchwork-Id: 12404213 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 663DFC4338F for ; Tue, 27 Jul 2021 21:19:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 51D2D60F90 for ; Tue, 27 Jul 2021 21:19:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235091AbhG0VTg (ORCPT ); Tue, 27 Jul 2021 17:19:36 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:45994 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235052AbhG0VSG (ORCPT ); Tue, 27 Jul 2021 17:18:06 -0400 Received: from imap1.suse-dmz.suse.de (imap1.suse-dmz.suse.de [192.168.254.73]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id D460220180; Tue, 27 Jul 2021 21:18:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1627420684; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5epPq6eJwcbufhqZJnqCSU1yA+81tlBeGHqrpDVK3xw=; b=kygNGorH6hORbc/C0iKLOM1PGKdjn5EoAGG0N/0GHO9pFj9nSwJCAAIIdD9teuUnWp1jmZ CLg15UM8TUuWfTrZy/LFDWlrtIEdEQlywZUQGurvsnTYvnm0hTeIpn1yggg3Dp/3ceDDjm 4alFmz4jivnPO+32MwUFfI6y1mIPmhI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1627420684; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5epPq6eJwcbufhqZJnqCSU1yA+81tlBeGHqrpDVK3xw=; b=noat/vXRTOh6+3y+IjTTYCVuPo/pW35xs+7yrxCmx4PXgwIEXRpF8Tj8RsVs/1EStqC0C1 yw6dI4TJk8q8QBAA== Received: from imap1.suse-dmz.suse.de (imap1.suse-dmz.suse.de [192.168.254.73]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap1.suse-dmz.suse.de (Postfix) with ESMTPS id 4E55F133DE; Tue, 27 Jul 2021 21:18:04 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap1.suse-dmz.suse.de with ESMTPSA id 2eTQCQx4AGGQdQAAGKfGzw (envelope-from ); Tue, 27 Jul 2021 21:18:04 +0000 From: Goldwyn Rodrigues To: linux-btrfs@vger.kernel.org Cc: Goldwyn Rodrigues Subject: [PATCH 6/7] btrfs: Allocate btrfs_ioctl_defrag_range_args on stack Date: Tue, 27 Jul 2021 16:17:30 -0500 Message-Id: <4b5d49128b43de57f5abfa9c922eb6cef3be9cba.1627418762.git.rgoldwyn@suse.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Goldwyn Rodrigues Instead of using kmalloc() to allocate btrfs_ioctl_defrag_range_args, allocate btrfs_ioctl_defrag_range_args on stack. sizeof(btrfs_ioctl_defrag_range_args) = 48 Signed-off-by: Goldwyn Rodrigues Reviewed-by: Anand Jain --- fs/btrfs/ioctl.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 291c16d8576b..bc38a1af45c7 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -3096,7 +3096,7 @@ static int btrfs_ioctl_defrag(struct file *file, void __user *argp) { struct inode *inode = file_inode(file); struct btrfs_root *root = BTRFS_I(inode)->root; - struct btrfs_ioctl_defrag_range_args *range; + struct btrfs_ioctl_defrag_range_args range = {0}; int ret; ret = mnt_want_write_file(file); @@ -3128,33 +3128,25 @@ static int btrfs_ioctl_defrag(struct file *file, void __user *argp) goto out; } - range = kzalloc(sizeof(*range), GFP_KERNEL); - if (!range) { - ret = -ENOMEM; - goto out; - } - if (argp) { - if (copy_from_user(range, argp, - sizeof(*range))) { + if (copy_from_user(&range, argp, + sizeof(range))) { ret = -EFAULT; - kfree(range); goto out; } /* compression requires us to start the IO */ - if ((range->flags & BTRFS_DEFRAG_RANGE_COMPRESS)) { - range->flags |= BTRFS_DEFRAG_RANGE_START_IO; - range->extent_thresh = (u32)-1; + if ((range.flags & BTRFS_DEFRAG_RANGE_COMPRESS)) { + range.flags |= BTRFS_DEFRAG_RANGE_START_IO; + range.extent_thresh = (u32)-1; } } else { /* the rest are all set to zero by kzalloc */ - range->len = (u64)-1; + range.len = (u64)-1; } ret = btrfs_defrag_file(file_inode(file), file, - range, BTRFS_OLDEST_GENERATION, 0); + &range, BTRFS_OLDEST_GENERATION, 0); if (ret > 0) ret = 0; - kfree(range); break; default: ret = -EINVAL; From patchwork Tue Jul 27 21:17:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goldwyn Rodrigues X-Patchwork-Id: 12404221 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, UNWANTED_LANGUAGE_BODY,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7DC8BC4338F for ; Tue, 27 Jul 2021 21:20:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5691060FD7 for ; Tue, 27 Jul 2021 21:20:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234640AbhG0VUH (ORCPT ); Tue, 27 Jul 2021 17:20:07 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:46004 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231339AbhG0VTZ (ORCPT ); Tue, 27 Jul 2021 17:19:25 -0400 Received: from imap1.suse-dmz.suse.de (imap1.suse-dmz.suse.de [192.168.254.73]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id F40B920181; Tue, 27 Jul 2021 21:18:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1627420687; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GuVIO3h4A3uvlueiXNtD+gOKe8DJdOF+LTpC6lPdeN0=; b=EuKCJQ5x1aIryfImdCZCKXzQJC0ZwE/5lo4eOuyv4ITyP5/7WWVCmnZPxGksfvaljlrL3U it1sdsmqMYHRsEMDmrAFKqZ0esYXDKXascr1WM7FowqTcJeEbx7VnhXS7ANbsNBVEFs3Jr c37zWMpUUmHW0bRBsyRoCAtn4NbRtlw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1627420687; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GuVIO3h4A3uvlueiXNtD+gOKe8DJdOF+LTpC6lPdeN0=; b=plHhhSL3RHlgtPnDW4SiJjwR6x3MZzBGUwCOKA55C8KaJf9YPzlHZtSiqu8vgr2h8w1C9w it0DORLeufmpOgCg== Received: from imap1.suse-dmz.suse.de (imap1.suse-dmz.suse.de [192.168.254.73]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap1.suse-dmz.suse.de (Postfix) with ESMTPS id 7064D133DE; Tue, 27 Jul 2021 21:18:07 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap1.suse-dmz.suse.de with ESMTPSA id sdu9Dg94AGGTdQAAGKfGzw (envelope-from ); Tue, 27 Jul 2021 21:18:07 +0000 From: Goldwyn Rodrigues To: linux-btrfs@vger.kernel.org Cc: Goldwyn Rodrigues Subject: [PATCH 7/7] btrfs: Alloc backref_ctx on stack Date: Tue, 27 Jul 2021 16:17:31 -0500 Message-Id: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Goldwyn Rodrigues Instead of using kmalloc() to allocate backref_ctx, allocate backref_ctx on stack. sizeof(backref_ctx) = 48 Signed-off-by: Goldwyn Rodrigues --- fs/btrfs/send.c | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c index 6ac37ae6c811..e0553fa27f85 100644 --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c @@ -1307,7 +1307,7 @@ static int find_extent_clone(struct send_ctx *sctx, u64 flags = 0; struct btrfs_file_extent_item *fi; struct extent_buffer *eb = path->nodes[0]; - struct backref_ctx *backref_ctx = NULL; + struct backref_ctx backref_ctx = {0}; struct clone_root *cur_clone_root; struct btrfs_key found_key; struct btrfs_path *tmp_path; @@ -1322,12 +1322,6 @@ static int find_extent_clone(struct send_ctx *sctx, /* We only use this path under the commit sem */ tmp_path->need_commit_sem = 0; - backref_ctx = kmalloc(sizeof(*backref_ctx), GFP_KERNEL); - if (!backref_ctx) { - ret = -ENOMEM; - goto out; - } - if (data_offset >= ino_size) { /* * There may be extents that lie behind the file's size. @@ -1392,12 +1386,12 @@ static int find_extent_clone(struct send_ctx *sctx, cur_clone_root->found_refs = 0; } - backref_ctx->sctx = sctx; - backref_ctx->found = 0; - backref_ctx->cur_objectid = ino; - backref_ctx->cur_offset = data_offset; - backref_ctx->found_itself = 0; - backref_ctx->extent_len = num_bytes; + backref_ctx.sctx = sctx; + backref_ctx.found = 0; + backref_ctx.cur_objectid = ino; + backref_ctx.cur_offset = data_offset; + backref_ctx.found_itself = 0; + backref_ctx.extent_len = num_bytes; /* * The last extent of a file may be too large due to page alignment. @@ -1405,7 +1399,7 @@ static int find_extent_clone(struct send_ctx *sctx, * __iterate_backrefs work. */ if (data_offset + num_bytes >= ino_size) - backref_ctx->extent_len = ino_size - data_offset; + backref_ctx.extent_len = ino_size - data_offset; /* * Now collect all backrefs. @@ -1416,12 +1410,12 @@ static int find_extent_clone(struct send_ctx *sctx, extent_item_pos = 0; ret = iterate_extent_inodes(fs_info, found_key.objectid, extent_item_pos, 1, __iterate_backrefs, - backref_ctx, false); + &backref_ctx, false); if (ret < 0) goto out; - if (!backref_ctx->found_itself) { + if (!backref_ctx.found_itself) { /* found a bug in backref code? */ ret = -EIO; btrfs_err(fs_info, @@ -1434,7 +1428,7 @@ static int find_extent_clone(struct send_ctx *sctx, "find_extent_clone: data_offset=%llu, ino=%llu, num_bytes=%llu, logical=%llu", data_offset, ino, num_bytes, logical); - if (!backref_ctx->found) + if (!backref_ctx.found) btrfs_debug(fs_info, "no clones found"); cur_clone_root = NULL; @@ -1458,7 +1452,6 @@ static int find_extent_clone(struct send_ctx *sctx, out: btrfs_free_path(tmp_path); - kfree(backref_ctx); return ret; }