Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp1833704imc; Tue, 12 Mar 2019 01:21:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqyEIoHc7NykEDP5iwqohG62jtOIkObrWpIZu/Eqwp34XPVERhC7Toe8kyAUJe1hWSiFC1HG X-Received: by 2002:a17:902:f83:: with SMTP id 3mr39825786plz.125.1552378886886; Tue, 12 Mar 2019 01:21:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552378886; cv=none; d=google.com; s=arc-20160816; b=CE1UO5uuqdmEo4lsODzzMEwW0VH+amK2SR9gHMBgjSYb2XxcKoSI9qEZ2NbE1JZrey LQsRustJoLiQn2auNsyg2kmfThmALhW/de8CYlGYd6FHENL7Zi80hpxjB/DK3ljnSoaS gliEHSIxzLQPTOds+zEBRhF/vTXOQcoYbRinmhwfBOk71aCldhySQtQWC/8Nk15PawtX CGBeX2789m980llb4WF4r9Hi2w+cL/xi9iaiNCZlmAuaITP3awWIFJCYgwHM0eioSOW7 fpELZA/Z3CCCoRUEOl3vi9SnV6+ARFsbj1E1R7w+6ggF8Zz1eZtaoZjxnEu0fdIzow0L +a5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:from :dkim-signature; bh=754GpwZyrAesX+qcC0sVeTqfB37HoJTOe+dmtDS1DH8=; b=YWe4LfX+cEgxsrt8tjH5rSnAUOHstc4p9Vv52RwQlPqgyJ67C8qr8XVsMPpFhBt013 egADgDlxwtvGLWQhpv2TFizeWt7SN1xudwYivx/W9B3AiLhyNZrngLbLntVipawPxWCp xfwsx8J24mrYdwOwGqgBTZPhni5es1N+fpj18DzeVHxVmA8s4VJHx3D3Y1t+N8Z9VzhZ 3iHf7nGd8xlIJZt8s2XYIamQtd8NFXNuOEKY8osVu6XR+ei8rveVkJMeXSvjW9KBNKNT cJ58b+V5Qx6UhDumG+F/251O71Qot+zxnF2gYWvi7jkVIy4Og31PcrWI4l5R2Xlqgi9I a49Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@chromium.org header.s=google header.b=Q7S9ieTf; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id gn18si7368583plb.185.2019.03.12.01.21.11; Tue, 12 Mar 2019 01:21:26 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@chromium.org header.s=google header.b=Q7S9ieTf; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727568AbfCLITT (ORCPT + 99 others); Tue, 12 Mar 2019 04:19:19 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:43068 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726218AbfCLITT (ORCPT ); Tue, 12 Mar 2019 04:19:19 -0400 Received: by mail-pg1-f196.google.com with SMTP id l11so1222962pgq.10 for ; Tue, 12 Mar 2019 01:19:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=754GpwZyrAesX+qcC0sVeTqfB37HoJTOe+dmtDS1DH8=; b=Q7S9ieTfoklNlKizyON7nYle2kJoGMLc3cye3Opl17h66pt3TBo3hD6DrpGmb0x6Ml yuAsIuPsJ571B+0xk1wfu34u9zRfo4jppeQES+Tow0N6tXhiWwZehR+2lBHgxRjX80JH yWNLBJ5HbxvQRnjEgth7DAuQVNVUEI05vnwuo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=754GpwZyrAesX+qcC0sVeTqfB37HoJTOe+dmtDS1DH8=; b=AvmboKnLw5HvLy1ATAVal1DEzYT+yL5HTUhSA9TswYjNY4+UrlyZa8ntMSDv/2b7II xQBsmNKWJpECwZmNz7hRNItlHAnItnQPkNn4E9f/xNAH+ZwChLgc1s8uOt4iaGAUrZTX bwAGKG+t1ymf3+PS84iQ+6LbJSHzDamMkyo1tPWSGb9La0SlwxCZMySdF+bGwEiOn6/A d/mdbo4BexvhXinls4xqPrqGdW160PBgAmhHEa4B/ZQkzlU1yaQVlMVsFicbFlI/h4xW oJoDYC3FX3Ugg+1wGRRw7fKDLjsWVV5LPYVJp8hd70Rzbb5/n5tetmN7wFDBPl6gh05I HV0g== X-Gm-Message-State: APjAAAVRbIwKqJZ+eeM8kUVX+R1hrxhLWM3nollJQffmUL+n5ILbkCRB fn6C7++B5dA3IRhIHkzhbcfWYQ== X-Received: by 2002:a63:e416:: with SMTP id a22mr20187231pgi.338.1552378758415; Tue, 12 Mar 2019 01:19:18 -0700 (PDT) Received: from pihsun-z840.tpe.corp.google.com ([2401:fa00:1:10:7889:7a43:f899:134c]) by smtp.googlemail.com with ESMTPSA id u11sm10842564pfh.23.2019.03.12.01.19.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Mar 2019 01:19:17 -0700 (PDT) From: Pi-Hsun Shih Cc: Pi-Hsun Shih , Andrew Morton , Michal Hocko , Matthew Wilcox , Johannes Weiner , Stephen Rothwell , Minchan Kim , Huang Ying , Wei Yang , Yang Shi , Aaron Lu , Tejun Heo , Omar Sandoval , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v2] mm/swap: Use offsetof instead of custom __swapoffset macro. Date: Tue, 12 Mar 2019 16:18:59 +0800 Message-Id: <20190312081902.223764-1-pihsun@chromium.org> X-Mailer: git-send-email 2.21.0.360.g471c308f928-goog In-Reply-To: <20190307094653.119425-1-pihsun@chromium.org> References: <20190307094653.119425-1-pihsun@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit To: unlisted-recipients:; (no To-header on input) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use offsetof to calculate offset of a field to take advantage of compiler built-in version when possible, and avoid UBSAN warning when compiling with Clang: UBSAN: Undefined behaviour in mm/swapfile.c:3010:38 member access within null pointer of type 'union swap_header' CPU: 6 PID: 1833 Comm: swapon Tainted: G S 4.19.23 #43 Call trace: dump_backtrace+0x0/0x194 show_stack+0x20/0x2c __dump_stack+0x20/0x28 dump_stack+0x70/0x94 ubsan_epilogue+0x14/0x44 ubsan_type_mismatch_common+0xf4/0xfc __ubsan_handle_type_mismatch_v1+0x34/0x54 __se_sys_swapon+0x654/0x1084 __arm64_sys_swapon+0x1c/0x24 el0_svc_common+0xa8/0x150 el0_svc_compat_handler+0x2c/0x38 el0_svc_compat+0x8/0x18 Signed-off-by: Pi-Hsun Shih --- include/linux/swap.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/linux/swap.h b/include/linux/swap.h index fc50e21b3b88..4bfb5c4ac108 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -157,9 +157,9 @@ struct swap_extent { /* * Max bad pages in the new format.. */ -#define __swapoffset(x) ((unsigned long)&((union swap_header *)0)->x) #define MAX_SWAP_BADPAGES \ - ((__swapoffset(magic.magic) - __swapoffset(info.badpages)) / sizeof(int)) + ((offsetof(union swap_header, magic.magic) - \ + offsetof(union swap_header, info.badpages)) / sizeof(int)) enum { SWP_USED = (1 << 0), /* is slot in swap_info[] used? */ -- 2.21.0.360.g471c308f928-goog