From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=115.124.30.99 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793872177; b=MnJsfEgk+P56rxhDX9HznkN3XLhZ0XdD8z2JyXOu3h26Za5C9dBJevc89524Gz4C3PO5 a8AyiA6WXodNgiTkMFHHRhA3XASAY+JbE3xPpUkL/C38rjM58kjKySr3PuNVKD+GOB04K 7AhQSNLQthXMCwc3mHCZxfdOo7M8A8iZBJsr/ilxPZ8TKHlwewVrWtPww7AokFCYH25aP flrhTkyuVynBDoCzD+IC69xosU26172iNAdSuUvX3tlRs7delEtRgJfSdI8y0rZBd8Zno dyYxl4a2hk8RWAhe1kh17zhj9bAyc5i7Mgb3kfyT+v81Nlk0HncOH0VGdccIsmGEukQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793872177; h=DMARC-Filter:DKIM-Signature:X-Alimail-AntiSpam:Received:From:To:Cc: Subject:Date:Message-Id:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=EdvOzSA0ips8bwQUfNOy8LK7YnXn3SMJmmzqT2NcLQI=; b=BaQVFEU/gcDQEsOAKVQZJv8dIgxYSXnVuL81U8ONizrU01qu/YapPlrd9CdNKI4gW7ZL 9BPDZPIpY3Gl1tGieYdRmS83aR5QwdPYOqg/LvdV2XtiUCoGKKb3R6pWBfWsLqc6FFOAb YsGe5NCsx5AY4z6hXY3WPLrMGK+NYOVc5YozdEICnud7AccffHNW+oyMnQQjMCNmqDqlC lyLa9DGI3oNWU/ba6ki3OcS8+QOywOvqo2PKS9qQjbN+GOVXKeENv2Nl06634Ms9nsauO 8OY3cbylUvhgCOTnu8vQoiBr1EIIoBqy61opubY4NCGqOuhAnENKi5T25Em3cQtcV7Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass header.d=linux.alibaba.com header.i=@linux.alibaba.com header.a=rsa-sha256 header.s=default header.b=viOB8r2y; arc=none smtp.remote-ip=115.124.30.99 Received: from out30-99.freemail.mail.aliyun.com (out30-99.freemail.mail.aliyun.com [115.124.30.99]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 20328606D830 for ; Thu, 5 Nov 2026 09:49:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 20328606D830 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.a=rsa-sha256 header.s=default header.b=viOB8r2y DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1793872172; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=EdvOzSA0ips8bwQUfNOy8LK7YnXn3SMJmmzqT2NcLQI=; b=viOB8r2ybo+FCe7sS9mu/zSJq44mDjZiXDY8diRBEhaX46BkmFB9vIp6aa4l6ZCEv4zIWn2jzRvv6Ntc1KTPUVhrx8ieqkPiJvZQGie8AQRUPkCzufHMsq7iUmXi6VyMa6XrA4UtNagC3mMbaZbHa02FZHoQHDOTgMujszg4Ylw= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R141e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam011083073210;MF=joseph.qi@linux.alibaba.com;NM=1;PH=DS;RN=7;SR=0;TI=SMTPD_---0XE8K7.c_1793872171; Received: from localhost(mailfrom:joseph.qi@linux.alibaba.com fp:SMTPD_---0XE8K7.c_1793872171 cluster:ay36) by smtp.aliyun-inc.com; Thu, 05 Nov 2026 17:49:32 +0800 From: Joseph Qi To: Andrew Morton , Heming Zhao Cc: Mark Fasheh , Joel Becker , ocfs2-devel@lists.linux.dev, linux-kernel@vger.kernel.org, Joseph Qi Subject: [PATCH 05/30] ocfs2: abstract the dinode suballoc slot checks Date: Thu, 5 Nov 2026 17:49:01 +0800 Message-Id: <20261105094926.3203416-6-joseph.qi@linux.alibaba.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20261105094926.3203416-1-joseph.qi@linux.alibaba.com> References: <20261105094926.3203416-1-joseph.qi@linux.alibaba.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The suballoc slot validation is a nested if/else-if whose two arms carry different error messages. Split it into two predicates so each message stays at its own call site without having to re-test the slot value to work out which arm fired. The arms were already mutually exclusive, so two sequential tests are equivalent to the if/else-if. Keep the OCFS2_INVALID_SLOT exclusion in the range predicate. OCFS2_INVALID_SLOT is 65535, which is greater than max_slots - 1, so without it every system inode mkfs.ocfs2 creates from the global allocator would be rejected. ocfs2_validate_group_descriptor() in suballoc.c open-codes a similar range test that deliberately permits OCFS2_INVALID_SLOT for all inodes; it is left alone because this predicate is stricter. No functional change intended. Signed-off-by: Joseph Qi --- fs/ocfs2/inode.c | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/fs/ocfs2/inode.c b/fs/ocfs2/inode.c index 8eefda8fe4a6..412c8149d306 100644 --- a/fs/ocfs2/inode.c +++ b/fs/ocfs2/inode.c @@ -88,6 +88,19 @@ static bool ocfs2_dinode_has_wrong_fs_generation(struct super_block *sb, return le32_to_cpu(di->i_fs_generation) != OCFS2_SB(sb)->fs_generation; } +static bool ocfs2_dinode_has_invalid_suballoc_slot(struct ocfs2_dinode *di) +{ + return le16_to_cpu(di->i_suballoc_slot) == (u16)OCFS2_INVALID_SLOT && + !(le32_to_cpu(di->i_flags) & OCFS2_SYSTEM_FL); +} + +static bool ocfs2_dinode_has_out_of_range_suballoc_slot(struct super_block *sb, + struct ocfs2_dinode *di) +{ + return le16_to_cpu(di->i_suballoc_slot) != (u16)OCFS2_INVALID_SLOT && + (u32)le16_to_cpu(di->i_suballoc_slot) > OCFS2_SB(sb)->max_slots - 1; +} + static bool ocfs2_valid_inode_mode(umode_t mode) { return fs_umode_to_ftype(mode) != FT_UNKNOWN; @@ -1553,15 +1566,15 @@ int ocfs2_validate_inode_block(struct super_block *sb, * deleting it would pass the slot to get_local_system_inode() via * ocfs2_remove_inode() and trigger BUG_ON(slot == OCFS2_INVALID_SLOT). */ - if (le16_to_cpu(di->i_suballoc_slot) == (u16)OCFS2_INVALID_SLOT) { - if (!(le32_to_cpu(di->i_flags) & OCFS2_SYSTEM_FL)) { - rc = ocfs2_error(sb, - "Invalid dinode %llu: suballoc slot %u for non-system inode\n", - (unsigned long long)bh->b_blocknr, - le16_to_cpu(di->i_suballoc_slot)); - goto bail; - } - } else if ((u32)le16_to_cpu(di->i_suballoc_slot) > OCFS2_SB(sb)->max_slots - 1) { + if (ocfs2_dinode_has_invalid_suballoc_slot(di)) { + rc = ocfs2_error(sb, + "Invalid dinode %llu: suballoc slot %u for non-system inode\n", + (unsigned long long)bh->b_blocknr, + le16_to_cpu(di->i_suballoc_slot)); + goto bail; + } + + if (ocfs2_dinode_has_out_of_range_suballoc_slot(sb, di)) { rc = ocfs2_error(sb, "Invalid dinode %llu: suballoc slot %u\n", (unsigned long long)bh->b_blocknr, le16_to_cpu(di->i_suballoc_slot)); -- 2.39.3