Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp978468imu; Thu, 22 Nov 2018 08:11:22 -0800 (PST) X-Google-Smtp-Source: AJdET5eNvtuNbSs4nA08lwThNKA+kFe5BOEpYIMoDN78BpeXMF4O83pcyELj0zzvrZ2UC3mhb/Sv X-Received: by 2002:a63:4e15:: with SMTP id c21mr10642260pgb.50.1542903082165; Thu, 22 Nov 2018 08:11:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542903082; cv=none; d=google.com; s=arc-20160816; b=FBqQBnyjmRc819ZOx3o6/y1TZHeNF7MROPSc5TgUk9yU1L3zlbVS3SGG5JgLquAieL SmKKHFQTBOJ0OsUkCruIchhZP/Z5ASMh07BlhF+JHCer/2HBwzPJP5/wTduhrdCGonpe FyB4+6Me1cpmuJP0tCHYDPtJowI2yx6Pdz7tjyH0uMoShAXGFbv/GBKoDdyT9YWBsh8S 5Z6c5t4jhYTVniz2pJ6OhkjiG/CVlXmT6zFlc4KkMcP/Dm5s+BeCreWAvswYfmvf0U3B 7zGOewPXu4pddbDH58ojjIAE/OETWVkvVnss52vwl51fZKC2XiYxcKhZIJg5umXwiV2G qiFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=9OSyc5/6h79up3LZctr0MsZesAr0KVm6SQ4LlSnW5bY=; b=nU1FHvPBQ966/U67vGKNfneTDJNqX8fQucpQ6OuwdFqv96NgbqxAXxoOO8B4eUFgt1 7YYKp8FXwqaWKKapMAwYRsDVh+n7FnFI8v282pN8nJBP7szYFiSrGEX24QQFzta0vigX jLrKljEc2GQIsj+X9NTX7LJqqXpQOV5moh58XuE3yilldVffM0X0lOcVqrElHabsEB5q bLj4Rn2KjsF1hL1mCS4fhvYPHa3odxA6iFZHZ8WQpnnq4iMoxTheTI64cr5QwQ1D+bL1 ME0JtcIBdc32m0zDpWco97nEoWTWu7scMg2QNjwGPmopeYZ9+5WH9rgzaoA3FQYOvxtj yw4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=Yafmn75o; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t19-v6si19268718plo.69.2018.11.22.08.11.06; Thu, 22 Nov 2018 08:11:22 -0800 (PST) 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=pass header.i=@nifty.com header.s=dec2015msa header.b=Yafmn75o; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391994AbeKVNxH (ORCPT + 99 others); Thu, 22 Nov 2018 08:53:07 -0500 Received: from conuserg-09.nifty.com ([210.131.2.76]:51398 "EHLO conuserg-09.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732521AbeKVNxH (ORCPT ); Thu, 22 Nov 2018 08:53:07 -0500 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-09.nifty.com with ESMTP id wAM3EZ3E004964; Thu, 22 Nov 2018 12:14:35 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-09.nifty.com wAM3EZ3E004964 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1542856476; bh=9OSyc5/6h79up3LZctr0MsZesAr0KVm6SQ4LlSnW5bY=; h=From:To:Cc:Subject:Date:From; b=Yafmn75oaOyr5NJXB53AXKyKEQ82YStVfgyWMUh75FHve14O2bMsA5BjYpzudQMbY zkeRiHteRqa3gn1Wjhu34jbQdOR2LsEjo1KY0ii3hZvpKa9F9MbX24ZDOfT6g93uRr ISZLKNlsMEbC3lCjGenOi875bafdv0twO7Ema2m0VabWiqc3G0E/INYb6737S++9bs dJnf3+9ZRoAuAM55XWUKbGPUYr981WISiRuMgXnl2U3xpbrcsQBBqg68GeRHn7vpdc hjiLt8NR7DW0uKc2ZJJ7PKGIalBNr9YOM9qUlU4FfreESbPi6S7OSdyXKYBrXjNUwK ZV236b42ZavRQ== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: Andrew Morton Cc: Luc Van Oostenryck , Nick Desaulniers , Kees Cook , Josh Triplett , Masahiro Yamada , Alexei Starovoitov , linux-kernel@vger.kernel.org, NeilBrown , Greg Kroah-Hartman , Ingo Molnar , Crt Mori , Dan Carpenter Subject: [PATCH v4 1/3] kernel.h: disable type-checks in container_of() for Sparse Date: Thu, 22 Nov 2018 12:14:20 +0900 Message-Id: <1542856462-18836-1-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When I tried to enable BUILD_BUG_ON for Sparse, the kbuild test robot reported lots of "unknown expression" warnings from container_of(), which seemed false positive. I addressed this in [1], but fixing Sparse is the right thing to do. The issue was fixed by Sparse commit 0eb8175d3e9c ("fix expansion of function designator"), but it will take time until the fixed version of Sparse is widely available. Disable the container_of() type checks for Sparse for now. [1] https://lore.kernel.org/lkml/1542623503-3755-1-git-send-email-yamada.masahiro@socionext.com/ Signed-off-by: Masahiro Yamada --- Changes in v4: - New patch Changes in v3: None Changes in v2: None include/linux/kernel.h | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/include/linux/kernel.h b/include/linux/kernel.h index d6aac75..d8c4adb 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h @@ -985,6 +985,21 @@ static inline void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) { } #define __CONCAT(a, b) a ## b #define CONCATENATE(a, b) __CONCAT(a, b) +/* + * TODO: + * Sparse emits "unknown expression" warnings. + * It was fixed by commit 0eb8175d3e9c0d20354763d07ce3d4c0e543d988 in Sparse. + * Remove the following workaround when the fixed Sparse is widely available. + */ +#ifdef __CHECKER__ +#define TYPE_CHECK_CONTAINER_OF(ptr, type, member) do {} while (0) +#else +#define TYPE_CHECK_CONTAINER_OF(ptr, type, member) \ + BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) && \ + !__same_type(*(ptr), void), \ + "pointer type mismatch in container_of()") +#endif + /** * container_of - cast a member of a structure out to the containing structure * @ptr: the pointer to the member. @@ -994,9 +1009,7 @@ static inline void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) { } */ #define container_of(ptr, type, member) ({ \ void *__mptr = (void *)(ptr); \ - BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) && \ - !__same_type(*(ptr), void), \ - "pointer type mismatch in container_of()"); \ + TYPE_CHECK_CONTAINER_OF(ptr, type, member); \ ((type *)(__mptr - offsetof(type, member))); }) /** @@ -1009,9 +1022,7 @@ static inline void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) { } */ #define container_of_safe(ptr, type, member) ({ \ void *__mptr = (void *)(ptr); \ - BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) && \ - !__same_type(*(ptr), void), \ - "pointer type mismatch in container_of()"); \ + TYPE_CHECK_CONTAINER_OF(ptr, type, member); \ IS_ERR_OR_NULL(__mptr) ? ERR_CAST(__mptr) : \ ((type *)(__mptr - offsetof(type, member))); }) -- 2.7.4