Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4989358yba; Tue, 30 Apr 2019 07:29:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqzd0kDVTH6vwzblJOPgXUfXvpXX8EMyr2JSqSRSZGbWkcvogPPexpJrFMC4Ae1Om3zY0397 X-Received: by 2002:a63:171c:: with SMTP id x28mr17407075pgl.12.1556634550588; Tue, 30 Apr 2019 07:29:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556634550; cv=none; d=google.com; s=arc-20160816; b=ldVgDL9ciII0nrszCOvV42VNkkbEnwyaujkyhYoFsu0yXMqhD0cVcOeBijfn6JyBYV iaDkFxbUy8BtlbWkYHz3c1ecF6FI+qdEOOvkaRxfV3ojKyFpfori92Ot4MJ2X1pnl0BL /mfcvYhagKMOBGWLcaQuGvFK5nEDlBnCGX8QF0vjBHPkrl9fN49khz0EH6DIKNql2+Oj IHK021Ku0tVX7dtkYPJuqbyZQaxkYjy3q9wjU5JTbY0b2Xh8qtotzSOKUTG9IVctVWx3 KckdXdg5KKlyZuESH7ya3p+j/2dDnrBHEYukTkBzlFxxiQfCrtLCjFZdXA0RE1R52Gp1 6xMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=SbIc79iCcGDp7Aa+luyFT47UZxxoXWn5ib5Q4L4Kd/g=; b=qb2znKgeTiLcz/0s4afmvsTIjfbQT2e4uOxCpNac1Yqu2K8d6NJ8wud6yzEvat9lSO mFsv2mLre9+CspG+yxUER/AIqs5cuxS5IIcwXl2kf532XGxkDhXOs2U51Jyn9+1irOM5 TSzKQNnAm+j+PXWjrDEBvkIsLwvnFs/STOGFR87yH++XqGE1K1U+3O3zwYrngciGNKa4 1odwueIAZSOCffB9mbWPMhs6QqrmvnkwyK2/HIFVv8+uqFYtA7l2g56GqIDvelh3zmcC tFQG5oyhxiC2TodbJ+0eyw4E1TVJXHH3R0cExwSxVh2phzSHjqRlSEaT99G3sKb1FDzL f+Qg== ARC-Authentication-Results: i=1; mx.google.com; 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 k6si38893677pfc.122.2019.04.30.07.28.49; Tue, 30 Apr 2019 07:29:10 -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; 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 S1727817AbfD3O1q (ORCPT + 99 others); Tue, 30 Apr 2019 10:27:46 -0400 Received: from zeniv.linux.org.uk ([195.92.253.2]:45800 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725942AbfD3O1q (ORCPT ); Tue, 30 Apr 2019 10:27:46 -0400 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.92 #3 (Red Hat Linux)) id 1hLTjJ-0003ij-4f; Tue, 30 Apr 2019 14:27:33 +0000 Date: Tue, 30 Apr 2019 15:27:33 +0100 From: Al Viro To: Sven Van Asbroeck Cc: Nicholas Mc Guire , Nicholas Mc Guire , Greg Kroah-Hartman , devel@driverdev.osuosl.org, Linux Kernel Mailing List Subject: Re: [PATCH V2] staging: fieldbus: anybus-s: force endiannes annotation Message-ID: <20190430142733.GL23075@ZenIV.linux.org.uk> References: <1556517940-13725-1-git-send-email-hofrat@osadl.org> <20190430022238.GA22593@osadl.at> <20190430030223.GE23075@ZenIV.linux.org.uk> <20190430033310.GB23144@osadl.at> <20190430041934.GI23075@ZenIV.linux.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.11.3 (2019-02-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 30, 2019 at 09:32:20AM -0400, Sven Van Asbroeck wrote: > On Tue, Apr 30, 2019 at 12:19 AM Al Viro wrote: > > > > ... not that there's much sense keeping ->fieldbus_type in host-endian, > > while we are at it. > > Interesting! Suppose we make device->fieldbus_type bus-endian. > Then the endinan-ness conversion either needs to happen in > bus_match() (and we'd have to convert endianness each time > this function is called). > Or, we make driver->fieldbus_type bus-endian also, then there > is no need for conversion... but the driver writer has to remember > to specify this in bus endianness: > > static struct anybuss_client_driver profinet_driver = { > .probe = ..., > .fieldbus_type = endian convert?? (0x0089), > }; > > Which pushes bus implementation details onto the > client driver writer? Also, how to convert a constant > to a specific endianness in a static initializer? cpu_to_be16() or htons() - either will be fine there. On little-endian you'll get htons(0x0089) => ___htons(0x0089) => __cpu_to_be16(0x0089) => ((__force __be16)__swab16((0x0089))) => ((__be16)(__builtin_constant_p((__u16)((0x0089))) ? ___constant_swab16((0x0089)) : __fswab16((0x0089))) => ((__be16)(__builtin_constant_p((__u16)((0x0089))) ? ((__u16)((((__u16)((0x0089)) & (__u16)0x00ffU) << 8) | (((__u16)((0x0089)) & (__u16)0xff00U) >> 8))) : __fswab16((0x0089))) and once the preprocessor has produced that, from compiler POV we have a constant expression as argument of __builtin_constant_p(), so it evaluates as true, reducing the whole thing to ((__be16)(((__u16)((((__u16)((0x0089)) & (__u16)0x00ffU) << 8) | (((__u16)((0x0089)) & (__u16)0xff00U) >> 8))) ) i.e. (__be16)0x8900. On big-endian expansion will be different, resulting in (__be16)0x0089... IOW, you can use endianness convertors in static initializers; things like struct sockaddr_in addr = {.sin_addr.s_addr = htonl(0x7f000001), .sin_port = htons(25), .sin_family = AF_INET}; are fine kernel-side (from the compiler POV, that is - something trying to speak SMTP in the kernel code would obviously be a bad sign). As for having to remember - sparse will complain about endianness mismatches in initializer...