Received: by 2002:ab2:1689:0:b0:1f7:5705:b850 with SMTP id d9csp1859646lqa; Tue, 30 Apr 2024 01:00:38 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXONUpdMcxI/N2r0qkQHXQVO6dwZHA0lXLpEYkieijeHRBtP4kdF8QFtmFnr8agh7OiCZKngQrRSKesnn12+KRnq+9mwr+4uTyc1GkTVg== X-Google-Smtp-Source: AGHT+IEq2bNaMV3Q8ThE0OZv6QTdqBZjpWswqbT+nPLmU5IxotNC9a31Cq9qpQqMdalLkWckONUn X-Received: by 2002:a05:6a21:348b:b0:1ad:a8d:dc6d with SMTP id yo11-20020a056a21348b00b001ad0a8ddc6dmr16543380pzb.8.1714464038095; Tue, 30 Apr 2024 01:00:38 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714464038; cv=pass; d=google.com; s=arc-20160816; b=h8sjGLpyRx2nFksgT1/zrQLeJwbk4SH9bEjdQnJTtjKjhcQ5CIlmgCK8W23e15uANx iNCjmFUTyo293Bvg7JnuScvMoUTV/7l9QT7o27y5TFQ5L2dUtUo38JGNvCu/xn5ml6id N3l4zRihTJkiC1zt2R9Mwh1ZvfS+vOP6/6FmE7s1nbMwkS2vgZhqGWPIrNzqBP7VVOPd F/kWOavKCuCphf4YXNsv515P2zfuG+0V361JSRpzmQ6ID5HPiFw9ifuuhbTtKMtE6ngg x/cEKPNnLnL9NGyYXbEXy1Z6Bz194VO5HZvlGOxlBFuA2wChS/2fWDGGNHOQunuiZxQA axeQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=T9ApYN3kJSKRtnVhiFwLFlEQiT5pNLKKbrHISKk7OtE=; fh=CxAm4tbcsuco+wtuBB+hLQKvYmC93X/kvd/225LUB5Q=; b=Ll+YO9YsB/N/cBagKUdhPNdxp65WYtKkTQecnFKFNrChirtFWeDlmCzM2Bqhr6trRA peLbgjg6RWrOElAeN3zZGHeCHdaHaXrThdrJfWvNxi3fNOa9oe32IgJRqjcTZEah/1f+ gTfbhft3EASv37yGLopFBYhOhCS8hspgkMKCdCpR5f9T7B03r5Cojdnmtom2tljXA0jj FuC4pIOOC66TMvpAXWiIT26+dEy4S3g0vw77b0ZvBiRhBpx7HrHc6rHhdXuruk5Tx26l HTafTngvvNur2uwcHnEffXUBsNVo5Nh75efXgnjBqwIZnISeU51xgQHK5bMw7IkmIL4x 01UA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="Y/SFkQGx"; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-163513-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-163513-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id m11-20020a63580b000000b005e84e71d9b6si21861648pgb.93.2024.04.30.01.00.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 01:00:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-163513-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="Y/SFkQGx"; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-163513-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-163513-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 034B5B21287 for ; Tue, 30 Apr 2024 08:00:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4AB187605D; Tue, 30 Apr 2024 08:00:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Y/SFkQGx" Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 300E23FE51; Tue, 30 Apr 2024 08:00:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714464013; cv=none; b=KSUaVzNOXJIZ+mlPtEyPIwrKywi4vCKvC1i2BN2Pg36BpOhv2z6/rHGxPxh+zQrfZ6k/dFdRu/6nKaQQ0BVmhMDE4A9+JuUJI33c7S1su40+M0IgXOujS/ga/kmCUwb/bBj61hyUBQJZZ0/DsgzjYy+jpZ6te+0gf2Ik2bVjDZs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714464013; c=relaxed/simple; bh=Xr3ka3wR8U78ItCs1qwBo9x2xAzK1TP584262NiYwaA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=CGzcoLzEBUCMZvZezVOJRpoArMU7rQtQTmpev8AMvHulGfsVeF69UMTnkuCKk/z7hW+V6KGDKkxXc3tpdIaxr4Wyn1/L01fSQQ6i1r30rkdEDe1KBHB5/O7Jdna1Aa1CQweFeGdvMnfxLjd8NDpRej+C7D4PhP/rnIY/VaZ6LFA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Y/SFkQGx; arc=none smtp.client-ip=209.85.215.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pg1-f182.google.com with SMTP id 41be03b00d2f7-5f807d941c4so4191974a12.0; Tue, 30 Apr 2024 01:00:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714464011; x=1715068811; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=T9ApYN3kJSKRtnVhiFwLFlEQiT5pNLKKbrHISKk7OtE=; b=Y/SFkQGx2nZNXEflVwmqOs/hcAxN7OcBxzqj4Wr9ZdzmtyW8cJW4m9UBhkFMubihkX nNwv0Vm0tIEXY0nR88NtGjQ0XQKmBa/1TNgHEzhdnaMOJ8j0oCjbWk9JELZBUHylQh1b M6gfloLHiKypYgKdSB6QnBQVbLBoapi0ZU5iefaoMMw9+ko+H72EnsRl+ZIcZcBEdNt8 ROi4LsH+4de6yB2gDp15XpiFRsBLdIzyQl8wUNJ5tamnQO47Y2Q4ZKH/HsaY+rP/Ya22 YZ4Xbcul8mSFQuuK+cVJeLd+C2iEpU3UkXyxmPlGiOVQPtqtlw4HZvQtuNSOiEc4a9v6 teVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714464011; x=1715068811; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=T9ApYN3kJSKRtnVhiFwLFlEQiT5pNLKKbrHISKk7OtE=; b=d+l+2xy24/CXDZNlRWsU/WnqrErb6oWBXI/4/Qo12vpAqMKPutM3VTmV0tupeK+67v xDG84wIqYon82WNAWt71Jd7mPO+wegL2uDY03ggbLz8W9zXraUt1E5IC5LrD5Ckltczt HfDPP7FwAvqUDDPwmalLRQpcxsOrlFTjInv5g+LR+lFxvGLxY09zzjhk6qaMVFPdlfBv 5CdIviutTPtUX5D+pZeuWZYYijlxsm4PdcVnHPG3AUpEk4N0hC6j+LYFxbIEHMODaZHZ 4KWFWGIh6XA7PfWGTcZ0EFB91q5jxXiPJMsO7OO4sliHC5RfnBUdkfQK8MED8+qOhmtD bfoQ== X-Forwarded-Encrypted: i=1; AJvYcCXXXRKZ41xAjHDyDV2PNvnF+freJfMH2r07/RpdQS81VfVjPU4t9IayCxxB8IdM4Ff+RFjDIae2tDPay++hjGgvmWiW7Z/O8gQaDs43 X-Gm-Message-State: AOJu0Yydroh85kZ0wXThxK5mzxC67+1UOQ0O7AscpQRXkixQVNDWvzkm ryMhKK3i3Smv+Sf+G9grxFk/gHd0j7E9Sp/Af3mP9uu8k7QWMXhB X-Received: by 2002:a05:6a20:1047:b0:1a3:c43c:9ccd with SMTP id gt7-20020a056a20104700b001a3c43c9ccdmr13905075pzc.42.1714464011272; Tue, 30 Apr 2024 01:00:11 -0700 (PDT) Received: from carrot.. (i223-218-155-26.s42.a014.ap.plala.or.jp. [223.218.155.26]) by smtp.gmail.com with ESMTPSA id i6-20020aa787c6000000b006e6b52eb59asm20461760pfo.126.2024.04.30.01.00.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 01:00:09 -0700 (PDT) From: Ryusuke Konishi To: Andrew Morton Cc: linux-nilfs@vger.kernel.org, linux-kernel@vger.kernel.org, Bart Van Assche , Jens Axboe Subject: [PATCH -mm 2/2] nilfs2: make superblock data array index computation sparse friendly Date: Tue, 30 Apr 2024 17:00:19 +0900 Message-Id: <20240430080019.4242-3-konishi.ryusuke@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240430080019.4242-1-konishi.ryusuke@gmail.com> References: <20240430080019.4242-1-konishi.ryusuke@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Upon running sparse, "warning: dubious: x & !y" is output at an array index calculation within nilfs_load_super_block(). The calculation is not wrong, but to eliminate the sparse warning, replace it with an equivalent calculation. Also, add a comment to make it easier to understand what the unintuitive array index calculation is doing and whether it's correct. Signed-off-by: Ryusuke Konishi Fixes: e339ad31f599 ("nilfs2: introduce secondary super block") --- fs/nilfs2/the_nilfs.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/fs/nilfs2/the_nilfs.c b/fs/nilfs2/the_nilfs.c index db322068678f..f41d7b6d432c 100644 --- a/fs/nilfs2/the_nilfs.c +++ b/fs/nilfs2/the_nilfs.c @@ -592,7 +592,7 @@ static int nilfs_load_super_block(struct the_nilfs *nilfs, struct nilfs_super_block **sbp = nilfs->ns_sbp; struct buffer_head **sbh = nilfs->ns_sbh; u64 sb2off, devsize = bdev_nr_bytes(nilfs->ns_bdev); - int valid[2], swp = 0; + int valid[2], swp = 0, older; if (devsize < NILFS_SEG_MIN_BLOCKS * NILFS_MIN_BLOCK_SIZE + 4096) { nilfs_err(sb, "device size too small"); @@ -648,9 +648,25 @@ static int nilfs_load_super_block(struct the_nilfs *nilfs, if (swp) nilfs_swap_super_block(nilfs); + /* + * Calculate the array index of the older superblock data. + * If one has been dropped, set index 0 pointing to the remaining one, + * otherwise set index 1 pointing to the old one (including if both + * are the same). + * + * Divided case valid[0] valid[1] swp -> older + * ------------------------------------------------------------- + * Both SBs are invalid 0 0 N/A (Error) + * SB1 is invalid 0 1 1 0 + * SB2 is invalid 1 0 0 0 + * SB2 is newer 1 1 1 0 + * SB2 is older or the same 1 1 0 1 + */ + older = valid[1] ^ swp; + nilfs->ns_sbwcount = 0; nilfs->ns_sbwtime = le64_to_cpu(sbp[0]->s_wtime); - nilfs->ns_prot_seq = le64_to_cpu(sbp[valid[1] & !swp]->s_last_seq); + nilfs->ns_prot_seq = le64_to_cpu(sbp[older]->s_last_seq); *sbpp = sbp[0]; return 0; } -- 2.34.1