Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp279591yba; Thu, 18 Apr 2019 00:51:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqzncTftx4XwNtMA4OZld7W2/4zTzsujX8GHofY5TMtc7Ds9wk3449NIniM3OmTdPlRie7VE X-Received: by 2002:a65:6546:: with SMTP id a6mr87550044pgw.5.1555573907609; Thu, 18 Apr 2019 00:51:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555573907; cv=none; d=google.com; s=arc-20160816; b=yWkJMRn7KLUCRzAaI3E5lwZDFsjKNsB40mH+ZRT1oYabT8tDm4GoghONY9Mgub7j94 n22qONJgnN7ekLi8RDz0+SQfNR9s4UMHiY2YaYTNPOZbi+K6mzvHVXDmwbENmYFs4SpQ k0XTFF0imyOo2DAhXOP0O9BVzm2tQdo9XGvT1W9bHZFuaWLA66zmpWaGtpeQd1XFkLzR 4vrR3+Tqph7cI4J3+lixoW10vNZAmhISKXU2qlmCKTRp4PZydhwqhVprD0FNSl8y67y3 u+vc53vuGkp63iK8xxcVr07LVoCDHqcGqz8ZWJZEXDPIVHhTLXCHMcOwHAN6jIbLzPsT NR5g== 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 :message-id:date:subject:cc:from:dkim-signature; bh=1+u7DKJJDYH4Nv31VWy+05JzeHtfYaxqUK6Ky58Kb+o=; b=HFXfrB8p5n3M2iuKXFdorQSvdhxEEG1zHowWS0GbLStfajD7H3mi1tYxhPNYbhUJt4 9sP/+fGYlsQcNH0Ea2nFPlRhuysh0ysIJE/vfX+vklI9u53e+O22vQt7oXfpVbkZtzq2 8YL2XeKFDg3CtIMzc9WtR8N+npY/XkelDEaqrjieSsDzXTuqQ4WOI8MsslNUbnimKVfV PbDf4GG54r3PTe4uRIGEv8cbMIS26MnhktRXhMwCdvZhvdCHcsqPalT1xjdMTAZwm/kr 56MrInDq8soZHjv/6vCzQRBDufaJ5husRY7iIgDqE/OtWeayW9P9K50EErwnN+K9iHs6 rHKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@chromium.org header.s=google header.b=JlMxKBLM; 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 n12si1369256plp.223.2019.04.18.00.51.32; Thu, 18 Apr 2019 00:51:47 -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=JlMxKBLM; 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 S2388060AbfDRHuh (ORCPT + 99 others); Thu, 18 Apr 2019 03:50:37 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:43503 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725747AbfDRHuh (ORCPT ); Thu, 18 Apr 2019 03:50:37 -0400 Received: by mail-pg1-f196.google.com with SMTP id z9so798029pgu.10 for ; Thu, 18 Apr 2019 00:50:37 -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:mime-version :content-transfer-encoding; bh=1+u7DKJJDYH4Nv31VWy+05JzeHtfYaxqUK6Ky58Kb+o=; b=JlMxKBLMdN5Q35ZfymHUS0hQqCDXg8FEI2v7sxeO4UB8u8fM5lDI8S3GTnGBLL2rZt YAWfUUzHkp5Qb4D52ytlW6ByOSshgU5uPnRAJVZdVaPIlkF6AaahpVz3f8yeMogLwjZN OBRG17mhEdCIoTOAaq1IoSCWFTZwoZvfDul6c= 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:mime-version :content-transfer-encoding; bh=1+u7DKJJDYH4Nv31VWy+05JzeHtfYaxqUK6Ky58Kb+o=; b=MNsrPSnywrxJRpHB0ZQeidY6lGs132rYAttqHbOEnYvqAU0rrQ0CppgblN9SxJOGbx 38+S+gA8ZxEB9SWuhkbQ/xZXSnyDOMNeDi7VwEeeYzxsOdV9c+S+MwOVHcgvwSUV11Sb tM6KrJvBzGNl2hQRgVXBbYtXZbgzbdLFcOztL0udVAyl6Os/NjGNIqswEjDjNfHwGvSO khPBe63YdRsIkj2DQg4kwKOGXAGYJJeYz9NSstochUD8zEgXcX/H8gmZeaE8ZnDFglLv IviG+mdwh14BvCFOhVaUUI8Mvgy3Ma2UTTS7eyuQFePxNli23XzHR1UV3biVbyVqtQIl rTzA== X-Gm-Message-State: APjAAAV1Xba3dz+vOS2AYXRZEmIXhH+j4w9XNW6XFGr/i04ne3//8h3x zvdZuSQy3zIJYB91JBphrZ/HmA== X-Received: by 2002:a63:2157:: with SMTP id s23mr4221987pgm.436.1555573836094; Thu, 18 Apr 2019 00:50:36 -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 i24sm1870830pfo.85.2019.04.18.00.50.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Apr 2019 00:50:35 -0700 (PDT) From: Pi-Hsun Shih Cc: Pi-Hsun Shih , linux-kernel@vger.kernel.org (open list) Subject: [PATCH] wireless: Use offsetof instead of custom macro. Date: Thu, 18 Apr 2019 15:50:14 +0800 Message-Id: <20190418075016.252988-1-pihsun@chromium.org> X-Mailer: git-send-email 2.21.0.392.gf8f6787159e-goog 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 net/wireless/wext-core.c:525:14 member access within null pointer of type 'struct iw_point' CPU: 3 PID: 165 Comm: kworker/u16:3 Tainted: G S W 4.19.23 #43 Workqueue: cfg80211 __cfg80211_scan_done [cfg80211] 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 wireless_send_event+0x3cc/0x470 ___cfg80211_scan_done+0x13c/0x220 [cfg80211] __cfg80211_scan_done+0x28/0x34 [cfg80211] process_one_work+0x170/0x35c worker_thread+0x254/0x380 kthread+0x13c/0x158 ret_from_fork+0x10/0x18 =================================================================== Signed-off-by: Pi-Hsun Shih --- include/uapi/linux/wireless.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/uapi/linux/wireless.h b/include/uapi/linux/wireless.h index 86eca3208b6b..f259cca5cc2b 100644 --- a/include/uapi/linux/wireless.h +++ b/include/uapi/linux/wireless.h @@ -1090,8 +1090,7 @@ struct iw_event { /* iw_point events are special. First, the payload (extra data) come at * the end of the event, so they are bigger than IW_EV_POINT_LEN. Second, * we omit the pointer, so start at an offset. */ -#define IW_EV_POINT_OFF (((char *) &(((struct iw_point *) NULL)->length)) - \ - (char *) NULL) +#define IW_EV_POINT_OFF offsetof(struct iw_point, length) #define IW_EV_POINT_LEN (IW_EV_LCP_LEN + sizeof(struct iw_point) - \ IW_EV_POINT_OFF) -- 2.21.0.392.gf8f6787159e-goog