From patchwork Tue May 9 20:30:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fabian Frederick X-Patchwork-Id: 760321 X-Patchwork-Delegate: dwmw2@infradead.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wMrbt3klcz9rxl for ; Wed, 10 May 2017 06:30:50 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="BtvYPW58"; dkim-atps=neutral DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=JeqRPQ7jz9D5LmE8xJT0BUDlXOyWglDQcKRDMo1VFQE=; b=Btv YPW58rearYDeuU02IDOgi/RPDtYV7yT9gBCIPD8mzMWJF294In9U2W/QlT8p10d5faNjJ4DoNqgTQ INubFetnKOc2gJQYapfpQz5nL0TaDYRZv4XcsvLjYMax5NGkpNp1CTJ0U9oC7X/h8wPXb3fGvLB5C nRU55QGxhlCXQ5iqwhoRlJfBM49ZNFZvYmd/C6aMMByTqU7FcGpjFPkwMHOHtgrbG/w6AsSPgA2XX HDVrMRpu3RERuZ8alP8Kl24Q6MoSz8vlLbbyqy1n86H3DQQmphPMny32IjNQ4TJkWFwoYJ8iA1azC eoGGTjrM5Q0Rvvj6aAIx6YwIhNYdyRA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1d8BmP-0004Y6-JU; Tue, 09 May 2017 20:30:45 +0000 Received: from mailrelay107.isp.belgacom.be ([195.238.20.134]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1d8BmK-0004Uw-4k for linux-mtd@lists.infradead.org; Tue, 09 May 2017 20:30:42 +0000 X-Belgacom-Dynamic: yes IronPort-PHdr: =?us-ascii?q?9a23=3AXTKImRUJMBibvSXlLLZndGFEbQXV8LGtZVwlr6E/?= =?us-ascii?q?grcLSJyIuqrYZRODt8tkgFKBZ4jH8fUM07OQ6P+wHzFYqb+681k8M7V0Hycfjs?= =?us-ascii?q?sXmwFySOWkMmbcaMDQUiohAc5ZX0Vk9XzoeWJcGcL5ekGA6ibqtW1aSV3DMl9Z?= =?us-ascii?q?L/r0FsbtiMO71+ev4JCbNwlXgSXnSbJ0Ig+/oQjYuo8Rm4Q0eYgrzR6cjHJCeu?= =?us-ascii?q?1QjU1yKF6ehRf35Y/k8pdp/QxLuOMn+tIGW6isLPdwdqBREDlzazN938bsrxSW?= =?us-ascii?q?FQY=3D?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A2D4AQBfJRJZ//gsQlddHAELAQUBGAELA?= =?us-ascii?q?QUBgj9sKIFGjnSRDQFGkCGEX4IPIYYDhG5AGAEBAQEBAQEBAQEBaiiCMyCCcC8?= =?us-ascii?q?jKXEkE4oUEbRjOoQRhxGGX4FegmeINoJKBZ4FkwwNggSPZ0iINYtDHziBCk8eG?= =?us-ascii?q?IRqAU8cgWU+Noh0AQEB?= X-IPAS-Result: =?us-ascii?q?A2D4AQBfJRJZ//gsQlddHAELAQUBGAELAQUBgj9sKIFGjnS?= =?us-ascii?q?RDQFGkCGEX4IPIYYDhG5AGAEBAQEBAQEBAQEBaiiCMyCCcC8jKXEkE4oUEbRjO?= =?us-ascii?q?oQRhxGGX4FegmeINoJKBZ4FkwwNggSPZ0iINYtDHziBCk8eGIRqAU8cgWU+Noh?= =?us-ascii?q?0AQEB?= Received: from 248.44-66-87.adsl-dyn.isp.belgacom.be (HELO localhost.localdomain) ([87.66.44.248]) by relay.skynet.be with ESMTP; 09 May 2017 22:30:12 +0200 From: Fabian Frederick To: David Woodhouse Subject: [PATCH linux-next] jffs2: reduce stack usage in jffs2_build_xattr_subsystem() Date: Tue, 9 May 2017 22:30:03 +0200 Message-Id: <20170509203003.11986-1-fabf@skynet.be> X-Mailer: git-send-email 2.9.3 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170509_133040_518822_50EBCBDF X-CRM114-Status: GOOD ( 10.45 ) X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [195.238.20.134 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [195.238.20.134 listed in wl.mailspike.net] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.0 RCVD_IN_MSPIKE_WL Mailspike good senders X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: fabf@skynet.be, linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Use kcalloc() for allocation/flush of 128 pointers table to reduce stack usage. Function now returns -ENOMEM or 0 on success. stackusage Before: ./fs/jffs2/xattr.c:775 jffs2_build_xattr_subsystem 1208 dynamic,bounded After: ./fs/jffs2/xattr.c:775 jffs2_build_xattr_subsystem 192 dynamic,bounded Also update definition when CONFIG_JFFS2_FS_XATTR is not enabled Tested with an MTD mount point and some user set/getfattr. Signed-off-by: Fabian Frederick Reported-by: Tim Gardner Reported-by: kernel test robot Reported-by: Ron Economos Reported-by: Nathan Chancellor Reviewed-by: Nick Desaulniers --- fs/jffs2/build.c | 5 ++++- fs/jffs2/xattr.c | 14 ++++++++++---- fs/jffs2/xattr.h | 4 ++-- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/fs/jffs2/build.c b/fs/jffs2/build.c index b288c8a..f88e0bf 100644 --- a/fs/jffs2/build.c +++ b/fs/jffs2/build.c @@ -211,7 +211,10 @@ static int jffs2_build_filesystem(struct jffs2_sb_info *c) ic->scan_dents = NULL; cond_resched(); } - jffs2_build_xattr_subsystem(c); + ret = jffs2_build_xattr_subsystem(c); + if (ret) + goto exit; + c->flags &= ~JFFS2_SB_FLAG_BUILDING; dbg_fsbuild("FS build complete\n"); diff --git a/fs/jffs2/xattr.c b/fs/jffs2/xattr.c index da3e185..95c0496 100644 --- a/fs/jffs2/xattr.c +++ b/fs/jffs2/xattr.c @@ -772,10 +772,10 @@ void jffs2_clear_xattr_subsystem(struct jffs2_sb_info *c) } #define XREF_TMPHASH_SIZE (128) -void jffs2_build_xattr_subsystem(struct jffs2_sb_info *c) +int jffs2_build_xattr_subsystem(struct jffs2_sb_info *c) { struct jffs2_xattr_ref *ref, *_ref; - struct jffs2_xattr_ref *xref_tmphash[XREF_TMPHASH_SIZE]; + struct jffs2_xattr_ref **xref_tmphash; struct jffs2_xattr_datum *xd, *_xd; struct jffs2_inode_cache *ic; struct jffs2_raw_node_ref *raw; @@ -784,9 +784,13 @@ void jffs2_build_xattr_subsystem(struct jffs2_sb_info *c) BUG_ON(!(c->flags & JFFS2_SB_FLAG_BUILDING)); + + xref_tmphash = kcalloc(XREF_TMPHASH_SIZE, + sizeof(struct jffs2_xattr_ref *), GFP_KERNEL); + if (!xref_tmphash) + return -ENOMEM; + /* Phase.1 : Merge same xref */ - for (i=0; i < XREF_TMPHASH_SIZE; i++) - xref_tmphash[i] = NULL; for (ref=c->xref_temp; ref; ref=_ref) { struct jffs2_xattr_ref *tmp; @@ -884,6 +888,8 @@ void jffs2_build_xattr_subsystem(struct jffs2_sb_info *c) "%u of xref (%u dead, %u orphan) found.\n", xdatum_count, xdatum_unchecked_count, xdatum_orphan_count, xref_count, xref_dead_count, xref_orphan_count); + kfree(xref_tmphash); + return 0; } struct jffs2_xattr_datum *jffs2_setup_xattr_datum(struct jffs2_sb_info *c, diff --git a/fs/jffs2/xattr.h b/fs/jffs2/xattr.h index 720007b..1b5030a 100644 --- a/fs/jffs2/xattr.h +++ b/fs/jffs2/xattr.h @@ -71,7 +71,7 @@ static inline int is_xattr_ref_dead(struct jffs2_xattr_ref *ref) #ifdef CONFIG_JFFS2_FS_XATTR extern void jffs2_init_xattr_subsystem(struct jffs2_sb_info *c); -extern void jffs2_build_xattr_subsystem(struct jffs2_sb_info *c); +extern int jffs2_build_xattr_subsystem(struct jffs2_sb_info *c); extern void jffs2_clear_xattr_subsystem(struct jffs2_sb_info *c); extern struct jffs2_xattr_datum *jffs2_setup_xattr_datum(struct jffs2_sb_info *c, @@ -103,7 +103,7 @@ extern ssize_t jffs2_listxattr(struct dentry *, char *, size_t); #else #define jffs2_init_xattr_subsystem(c) -#define jffs2_build_xattr_subsystem(c) +#define jffs2_build_xattr_subsystem(c) (0) #define jffs2_clear_xattr_subsystem(c) #define jffs2_xattr_do_crccheck_inode(c, ic)