Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3304380rwb; Mon, 15 Aug 2022 23:44:01 -0700 (PDT) X-Google-Smtp-Source: AA6agR5pqZvm7Mw14phRIf3WnmO+zKzexDG0Lo+eY5fP4OL9n9iJLuCDxcZwb1ZNWd1r8IIFN5Eg X-Received: by 2002:a17:907:2ce8:b0:731:3ef5:cbaa with SMTP id hz8-20020a1709072ce800b007313ef5cbaamr12727226ejc.328.1660632241495; Mon, 15 Aug 2022 23:44:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660632241; cv=none; d=google.com; s=arc-20160816; b=RA7R2mfyLjNM0mRn9N8vE7VpeaCO01eimHZmPGi5oV2WG39bYxrRZAqwzUTaG/zpCE s7ThHtf1IIDSPOVO8dCxT48+GzPlWRk3VdknxdiyQFW6V3UvTiFBykPKqlSdHs+Sy0xr raXafMzzKwDIaXQ+441Q8wYbwRGveuuXw5jVI8WFkqg2PlAeUdbAQ9cCVuOoauUQN/wt 8K7aj/qZ0ZepaAraVnuVlm6xK77h6iAEauhLyFG0PBP+MIZ5SWDNgxiPgT0A+vXyAZtf rJoyMkf25BzIsaaieW61ZBvqN8G6t18c7X7hbC8E8oKx38giUaGoBVkatLlm82ShfFGf 3N9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=k8axr/Aep0d+9tnwrwx2dH9IRoVDFQvDb+3T8DBTfYY=; b=MmC0TbaYWFt28jAJc9IPtSlCpIdK7iSyk3a23Mjwcu13Hu/1fpriC/B2zxK4oTNdvz xkH5k2VJTWI1zZ6TPxh1hZBdP9hOfqqQommjsl8eu1RkO9KidpDlH36le45xrcq893Cr SHxLo9bqjiB9D6jeJcAMYwplkPOB08a5r3YLuv6DTiFPYSo529TAZMS5kDbhBPt4K2cw ixYARFJ3P/k7L7BnglA+Ze+KanTU5aVBwRvfovuXNOfTjoehsFU5CjWaRpTx1zItDbf5 ay9Btgv77Kl1CNXEmPrGnHRXv34MyJugoTIXWb1C/0xMe7xH8imRnBmXPg77tZZyqsvm 0M+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=SYrbCR1C; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ho39-20020a1709070ea700b0073100e36dd2si11912332ejc.939.2022.08.15.23.43.34; Mon, 15 Aug 2022 23:44:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=SYrbCR1C; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230100AbiHPGmy (ORCPT + 99 others); Tue, 16 Aug 2022 02:42:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230155AbiHPGmk (ORCPT ); Tue, 16 Aug 2022 02:42:40 -0400 Received: from mail-m974.mail.163.com (mail-m974.mail.163.com [123.126.97.4]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A5541100E; Mon, 15 Aug 2022 18:31:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=k8axr /Aep0d+9tnwrwx2dH9IRoVDFQvDb+3T8DBTfYY=; b=SYrbCR1ChEwP7KDSYp3bn 0nlavgADJkGGdcCxQsNf5V+iGBa9qjRmlRqrPZ6hR6Hzo+YnCA5drFe/7L0jqlYL xwd0DHBCWU+w/Vi1/QIEToRRJCsYp0caqKZT9mKOYSKu9ZTTQyFVbSekABoXxfwB hT0yLk8C1SO011B15V0MAg= Received: from localhost.localdomain (unknown [116.128.244.169]) by smtp4 (Coremail) with SMTP id HNxpCgCXJsDL7_pipFLJVQ--.14169S2; Tue, 16 Aug 2022 09:15:56 +0800 (CST) From: Jiangshan Yi <13667453960@163.com> To: tytso@mit.edu, adilger.kernel@dilger.ca Cc: lczerner@redhat.com, linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, Jiangshan Yi Subject: [PATCH v3] fs/ext4: replace ternary operator with min()/max() and min_t() Date: Tue, 16 Aug 2022 09:15:53 +0800 Message-Id: <20220816011553.2912926-1-13667453960@163.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: HNxpCgCXJsDL7_pipFLJVQ--.14169S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxGFWxCw4xury5CF45JFy3CFg_yoW5WFWfpF n3AF18GFWru348uayIgr4UZ3W5W3WkG3y7XryY9r1UWFZIqFyxtrn8Kr1jvF1FgrWkZ34j qFW0kr1UJwnIkFDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07UuuWJUUUUU= X-Originating-IP: [116.128.244.169] X-CM-SenderInfo: bprtllyxuvjmiwq6il2tof0z/1tbivgpe+1ZceYnPBQACsj X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,FROM_LOCAL_DIGITS,FROM_LOCAL_HEX,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From: Jiangshan Yi Fix the following coccicheck warning: fs/ext4/inline.c:183: WARNING opportunity for min(). fs/ext4/extents.c:2631: WARNING opportunity for max(). fs/ext4/extents.c:2632: WARNING opportunity for min(). fs/ext4/extents.c:5559: WARNING opportunity for max(). fs/ext4/super.c:6908: WARNING opportunity for min(). min()/max() and min_t() macro is defined in include/linux/minmax.h. It avoids multiple evaluations of the arguments when non-constant and performs strict type-checking. Suggested-by: Lukas Czerner Signed-off-by: Jiangshan Yi Reviewed-by: Lukas Czerner --- fs/ext4/extents.c | 8 +++----- fs/ext4/inline.c | 3 +-- fs/ext4/super.c | 3 +-- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index c148bb97b527..37321aecd878 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -2628,9 +2628,8 @@ ext4_ext_rm_leaf(handle_t *handle, struct inode *inode, unwritten, ex_ee_len); path[depth].p_ext = ex; - a = ex_ee_block > start ? ex_ee_block : start; - b = ex_ee_block+ex_ee_len - 1 < end ? - ex_ee_block+ex_ee_len - 1 : end; + a = max(ex_ee_block, start); + b = min(ex_ee_block + ex_ee_len - 1, end); ext_debug(inode, " border %u:%u\n", a, b); @@ -5557,8 +5556,7 @@ static int ext4_insert_range(struct file *file, loff_t offset, loff_t len) * ee_start_lblk to shift extents */ ret = ext4_ext_shift_extents(inode, handle, - ee_start_lblk > offset_lblk ? ee_start_lblk : offset_lblk, - len_lblk, SHIFT_RIGHT); + max(ee_start_lblk, offset_lblk), len_lblk, SHIFT_RIGHT); up_write(&EXT4_I(inode)->i_data_sem); if (IS_SYNC(inode)) diff --git a/fs/ext4/inline.c b/fs/ext4/inline.c index a4fbe825694b..2b42ececa46d 100644 --- a/fs/ext4/inline.c +++ b/fs/ext4/inline.c @@ -180,8 +180,7 @@ static int ext4_read_inline_data(struct inode *inode, void *buffer, BUG_ON(len > EXT4_I(inode)->i_inline_size); - cp_len = len < EXT4_MIN_INLINE_DATA_SIZE ? - len : EXT4_MIN_INLINE_DATA_SIZE; + cp_len = min_t(unsigned int, len, EXT4_MIN_INLINE_DATA_SIZE); raw_inode = ext4_raw_inode(iloc); memcpy(buffer, (void *)(raw_inode->i_block), cp_len); diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 9a66abcca1a8..5615bf7ab15d 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -6905,8 +6905,7 @@ static ssize_t ext4_quota_read(struct super_block *sb, int type, char *data, len = i_size-off; toread = len; while (toread > 0) { - tocopy = sb->s_blocksize - offset < toread ? - sb->s_blocksize - offset : toread; + tocopy = min(sb->s_blocksize - offset, toread); bh = ext4_bread(NULL, inode, blk, 0); if (IS_ERR(bh)) return PTR_ERR(bh); -- 2.25.1