Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3700188pxv; Mon, 26 Jul 2021 09:42:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzTDBIUNuDxdlj3jJWwoLelxTewdydTOD98wcBHjGhzzeHbkTY234zeAP99a0G7ilGaNqVl X-Received: by 2002:a05:6402:1396:: with SMTP id b22mr22525053edv.380.1627317760873; Mon, 26 Jul 2021 09:42:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627317760; cv=none; d=google.com; s=arc-20160816; b=QZg6PcLOklceAGpmaKxyRrseBUZmni4zYMtTWz46aMkvCMWfAIYCcjcjEOGLr4idHJ FyvLCSPt84lTEkkzNlINcGqQnuex2dYwhRqL0Ya7q0L+6VeIAF+qCox0+xjIuk3JfLqZ 2QuH2ExLypdWMQRk4yAKDfIY4aAXu/78asGBOpkElsNKMv4u7vaGc6u5tG/Aa720Z1zu SPsMa9c81kbUAbdLj5+EXE8dgL12ky2zJiQOr6OXP9674TH8+c463JQLlaiJuXGDquBM pRSMlp6nOajzv7SZucAzsHSVLTOh3XiQYUnVInBbAR7D81VzzYQUjjClZ59VkPpEelxs 1zew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=7fBk0xHsaKhVwGVDGQ/kuCEhnDs++Xdm8n1RPPeuY6c=; b=Wmlmd7dw6wPPVGRXf7GTWwAYY7PeoUqrNh8bsHKI/EvOty5oB1g1a86EGp+VKn+HLE V0ogwfq50+ae+XaTgTIbvKPrK1LwmFg2Bdb0PEzCadAqDS+rQZFKqozM/CG0i23FeeT9 02dihrTcF37Bv2sng06+uTtD9SNoIlQ/eWvz1NEY7xbd6nkO1srXh/kjU0glpikU7Pl9 N2hhQwcCIvRHQc1SspD4twjlhEOKcGg2yM24PM9Yq2OmtkkNIdM6hCITRrgUOFLZSWRC 01Jdr8CHosDm4aatozjWHQEFX6CVdZreRUE3kof/6KcE8vQ0d0+ao4ABLUb6pIFEscA4 ZX4g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z8si373838edb.213.2021.07.26.09.42.14; Mon, 26 Jul 2021 09:42:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234511AbhGZP55 (ORCPT + 99 others); Mon, 26 Jul 2021 11:57:57 -0400 Received: from mout.kundenserver.de ([212.227.126.135]:57273 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237511AbhGZPmA (ORCPT ); Mon, 26 Jul 2021 11:42:00 -0400 Received: from mail-wr1-f50.google.com ([209.85.221.50]) by mrelayeu.kundenserver.de (mreue009 [213.165.67.97]) with ESMTPSA (Nemesis) id 1N9MlI-1l2jt831jY-015EtT; Mon, 26 Jul 2021 18:22:18 +0200 Received: by mail-wr1-f50.google.com with SMTP id p5so6681919wro.7; Mon, 26 Jul 2021 09:22:18 -0700 (PDT) X-Gm-Message-State: AOAM533VQV99cc+dxxLIjJxZGXNngbz3hCJjNiuXNSOrkmHkz5bTC4gJ 4DCqCyJ5F6ho0TLxzQQUzh3DNN+3SGrtNWwSFK0= X-Received: by 2002:adf:e107:: with SMTP id t7mr20157064wrz.165.1627316538300; Mon, 26 Jul 2021 09:22:18 -0700 (PDT) MIME-Version: 1.0 References: <20210724162429.394792-1-sven@narfation.org> <3234493.RMHOAZ7QyG@ripper> In-Reply-To: <3234493.RMHOAZ7QyG@ripper> From: Arnd Bergmann Date: Mon, 26 Jul 2021 18:22:02 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] asm-generic: avoid sparse {get,put}_unaligned warning To: Sven Eckelmann Cc: Al Viro , Arnd Bergmann , b.a.t.m.a.n@lists.open-mesh.org, linux-arch , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" X-Provags-ID: V03:K1:VvZ46d4HcbQ9Yh9Wr5KJMJAA4QGmLQUzmw70t+kcPBYI7iDts0y JcuvTpoimJpWvw1X2jgnk/cJlJnK/oj8KBFj/fEohjsDbmt7BBFPFuK9K0D+3Hs47W4f9Ut 1goQ3FsZhIEbYaicnKjucgcLS/Z5yvmluJP6Yz44n+1pylkq151u36+7Wojy4ekcS+6ein2 N4hg6Maf5n3XQbkC6pqQg== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:UKpcsJUq4AU=:euwYip+Am0oMSvCjo6DqXU Igr9R25Zgk7EqGMu/+p7xf/Q29Ks7ZAthvrJhLt9uQ3Rt76Gt6IPRE/3YbptYeP5+vkaAYkVH nhAD6fKFUQ/vuxZZhXw2OHC3y2aQaEgTigXUzoPm5whAtNe57pMwT1BYF6DsPi/+82osTklkM oaLIg7fG2U70nv7c3cSWYi2pAKlkEWmGQp0x+/hv9tIkt7hqr0XL8lTgrGbrMJfkXPIhlk6sy C3OSMxx2QwohU7hEnTb+mfAXGoXDZ/cjrKplAg5JBf0m/UzAoaKg1QdwDITnNjcPnI9bhS4HY KP5i+uE3E0jL0mpFKZD/tT1FvfhMdb3RQ13mbqwU6NRtQ6R5ohotwnN8UWx/o/Zv3yNCU4QV4 s7CnjkO3b/P3SOCXczn1hV2/fgiXneN3JO1CRgroA+xKkQhQ31HsOcH1viqeS4y6j1jqdLdHy 1qJ0Z4Me+a4M97/t+wtRnGkCvMneeuIwABAz9l+/zPbLlyK3GpUdZMvGlL+Y1IuHWds9NpPnP oFDfJNdKxL40ew1O0AIV5/RkIgGY4ayjLoCfzL4Hn/Z/fGfhL7nKSgc2zFcwuOvwjBKsBsnk0 A08lCrlKWGemysbqWTPBSOt+CLFJgUIQXrlqAgHTrrRWTplTPoHKUsfo2xV5HfTMkvYKKTDEO Vm+boK7/E5jODDubIqGst1IpgUEiF3NZSjTGEciYo3kE8WV2WFYFzMvmmPeIIrKwvD9PlWAVp utyFjS5YSBGYWjYNppy3bdRfhDpNekJu7aF1MKZPyBtTx/Y2d76cnN5DsmAdI8G46cKU2D8f7 mWiFg3o92haUB+8oaiYYynAk6jqH834cjO3sldD0PmEd3jjM/OV/txfDCv0batLOejDIFZz Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jul 26, 2021 at 5:04 PM Sven Eckelmann wrote: > > On Monday, 26 July 2021 14:57:31 CEST Arnd Bergmann wrote: > > > > > > > The special attribute force must be used in such statements when the cast > > > > is known to be safe to avoid these warnings. > > > > I can see why this would warn, but I'm having trouble reproducing the > > warning on linux-next. > > I have sparse 0.6.3 on an Debian bullseye amd64 system. Sources are from > linux-next next-20210723 > > make allnoconfig > cat >> .config << "EOF" > CONFIG_NET=y > CONFIG_INET=y > CONFIG_BATMAN_ADV=y > CONFIG_BATMAN_ADV_DAT=y > EOF > make olddefconfig > make CHECK="sparse -Wbitwise-pointer" C=1 > > I should maybe have made this clearer in the last sentence of the first > paragraph: "This is also true for pointers to variables with this type when > -Wbitwise-pointer is activated." Ok, got it. I assumed this would be turned on by an 'allmodconfig' build. > > If both work equally well, I'd prefer Sven's patch since that only > > expands 'type' once, while container_of() expands it three more times Not sure what I was thinking here, as it's not 'type' that gets expanded here but 'ptr'. We could do Al's suggestion to avoid the __force without multiple expansions, using diff --git a/include/asm-generic/unaligned.h b/include/asm-generic/unaligned.h index 1c4242416c9f..d138dc5fd8e3 100644 --- a/include/asm-generic/unaligned.h +++ b/include/asm-generic/unaligned.h @@ -10,17 +10,25 @@ #include #define __get_unaligned_t(type, ptr) ({ \ - const struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr); \ + const struct { type x; } __packed *__pptr = \ + container_of(ptr, typeof(*__pptr), x); \ __pptr->x; \ }) #define __put_unaligned_t(type, val, ptr) do { \ - struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr); \ + struct { type x; } __packed *__pptr = \ + container_of(ptr, typeof(*__pptr), x); \ __pptr->x = (val); \ } while (0) -#define get_unaligned(ptr) __get_unaligned_t(typeof(*(ptr)), (ptr)) -#define put_unaligned(val, ptr) __put_unaligned_t(typeof(*(ptr)), (val), (ptr)) +#define get_unaligned(ptr) ({ \ + __auto_type _ptr = (ptr); \ + __get_unaligned_t(typeof(*(_ptr)), (_ptr)); \ +}) +#define put_unaligned(val, ptr) ({ \ + __auto_type _ptr = (ptr); \ + __put_unaligned_t(typeof(*(_ptr)), (val), (_ptr)); \ +}) static inline u16 get_unaligned_le16(const void *p) { Not sure if this is any better. Arnd