Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3863855pxj; Tue, 15 Jun 2021 10:14:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyzEGCJPIWKW0OTYSV7y84r66UtB3bIJ1/4Gyg3Vidg1c3n//PcrDvEZcjLLEtTfmtj3QGI X-Received: by 2002:a05:6402:101a:: with SMTP id c26mr601831edu.317.1623777254365; Tue, 15 Jun 2021 10:14:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623777254; cv=none; d=google.com; s=arc-20160816; b=QlgKbjmVnvkNqUzAfh+i7PNKndogoSdqETZUw2qBCUHjBDm2JrhFPKb/rPVHxhzHlc SwbSCk8yyQTsthDSTZxlyClWMOO+x6Sd1R2FiwhSQ+ZBd6tSwYPgLS+KXh7kDc/q9CjK x+ivxUqXHt3XDC/PaeD2MTCmL/JMDXcokmfKt2RgWbTV7rhRu6QOv3sOKsnWHQqoRS+G vxhksRmM53K6rhOobCggJ0Ztw7w2jPUja1B/l0LNtrtaBU2I4M4qm16OVTW5t8I7m+WS D83uKFy57jMt6CVAFWFe2om0+xZIpp7XAa8KrBkUnDt3PmEJP8b03L0AoHW9doiRSbDb YaIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:message-id:in-reply-to:subject:cc:to:from :date; bh=8EZySQUXFWaq9AvImgQkdkdbv0GNnLgIy6sx6xG2Sio=; b=EuFTwYcL2xaJOxtov40QqlT8NNs7ioCOJ676c924BAUyu8rjURAWE18h8zClprtV97 O7LH2wCWnUZvIB5YaWzM35mS9bq6UaPv+E9PXpyX9HiLrs+MJlCcVVRiJEDIji0HkVss nTcursEZAwL3N1SWGCgYN1LjaN2KcBF8p6byfaSDgTs2wk2i3CsSxygUNzkBzPWf1UTW 6Gk6n+v6Z9shebQkLOOo60DDwoVusf/LRReAJY6T8G14Zk8v8pYvQwSH9fYZaNea0h7y UgNixBAE3rMFEOuMEdeItHjpJLkrW3E5jIY0wloXWtN0iPXxlHp4quGTIWajpsPR5D8R rxoQ== 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 i19si3626248edc.598.2021.06.15.10.13.51; Tue, 15 Jun 2021 10:14:14 -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 S229613AbhFOROv (ORCPT + 99 others); Tue, 15 Jun 2021 13:14:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49276 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229492AbhFOROu (ORCPT ); Tue, 15 Jun 2021 13:14:50 -0400 Received: from angie.orcam.me.uk (angie.orcam.me.uk [IPv6:2001:4190:8020::4]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 559ECC061574; Tue, 15 Jun 2021 10:12:46 -0700 (PDT) Received: by angie.orcam.me.uk (Postfix, from userid 500) id 0891C92009C; Tue, 15 Jun 2021 19:12:45 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by angie.orcam.me.uk (Postfix) with ESMTP id 01F2592009B; Tue, 15 Jun 2021 19:12:44 +0200 (CEST) Date: Tue, 15 Jun 2021 19:12:44 +0200 (CEST) From: "Maciej W. Rozycki" To: Greg Kroah-Hartman cc: Jiri Slaby , linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 0/4] serial: 8250: Fixes for Oxford Semiconductor 950 UARTs In-Reply-To: Message-ID: References: User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 15 Jun 2021, Greg Kroah-Hartman wrote: > > > This patch series causes the following build warning to be added: > > > > > > drivers/tty/serial/8250/8250_pci.c: In function ‘pci_oxsemi_tornado_setup’: > > > drivers/tty/serial/8250/8250_pci.c:1258:32: warning: unsigned conversion from ‘int’ to ‘unsigned char’ changes value from ‘-129’ to ‘127’ [-Woverflow] > > > 1258 | up->mcr_mask = ~UART_MCR_CLKSEL; > > > | ^ > > > > > > > > > Can you fix this up and resend? > > > > I've seen that, but that's not a problem with my change, but rather with > > making this macro (and the remaining ones from this > > group) expand to a signed constant (0x80 rather than 0x80u). > > As your change causes it to show up, it must have something to do with > it :) Of course it does, but the problem comes from the data type signedness difference between the `mcr_mask' member of `struct uart_8250_port', the type of which is (rightfully IMO) `unsigned char' (rather than `char' or `signed char') and the UART_MCR_CLKSEL macro, which expands to a signed int. My change does not introduce this data type difference, hence it's not responsible for the problem, though it does expose it. > > I can fix the header, but that would be a separate change, and mind too > > that this is a user header, so it's not clear to me what the impact might > > be on user apps making use of it. > > You can not change the uapi header, why would you want to? To make the data type of the constants it defines such that they can be assigned to program entities they are supposed to be used with without changing the sign at truncation time? > > We could use a GCC pragma to suppress the warning temporarily across this > > piece of code, but it's not clear to me either what our policy has been on > > such approach. > > What pragma? #pragma GCC diagnostic ignored "-Woverflow" > > Thoughts? > > Why does your change cause this to show up? As I have noted above there is a data type signedness difference between `mcr_mask' and UART_MCR_CLKSEL. So we have the value of 0x80 (128). Once bitwise-complemented it becomes 0xffffff7f (-129). Once assigned to `mcr_mask' however it becomes 0x7f (127), which is considered an unsafe conversion between signed and unsigned integers by GCC, which is why the compiler complains about it. The same difference exists with say UART_MCR_OUT2 used in a similar manner for ALPHA_KLUDGE_MCR, but GCC does not get noisy about it because the constant UART_MCR_OUT2 expands to is 0x08 and therefore the position of the bit set there does not coincide with the sign bit once truncated to 8 bits, so the truncation does not cause a sign change. The same warning would trigger however if the constant were left-shifted by 4 before the bitwise complement operation, so all these constants should be unsigned. It does not make sense IMO to operate on signed values in the context of bit patterns for peripheral hardware registers. I'll find a way to paper it over if this is what is desired here, e.g. I guess this piece: up->mcr_mask = ~0; up->mcr_mask ^= UART_MCR_CLKSEL; will do, although I find it obscurer than my original proposal, and surely asking for a comment (which I think is a sign of a problem). Maciej